列出Git存储库中的所有文件

你有一个干净的方式列出所有在指定的分支存在的文件?

这是Strager 解决scheme的简化版本:

git log --pretty=format: --name-status | cut -f2- | sort -u 

编辑:感谢Jakub在教学中多了一点点意见,这个版本有一个更短的pipe道,让git更有机会把事情做好。

 git log --pretty=format: --name-only --diff-filter=A | sort -u 

这样做是正确的,用来检查文件名是否存在于回购站中,而不仅仅存在于当前分支上。

 git log --all --pretty=format: --name-only --diff-filter=A | sort - | grep fubar 

你可以运行git-log --name-status ,这个回应类似于:

 commit afdbbaf52ab24ef7ce1daaf75f3aaf18c4d2fee0 Author: Your Name <your@email.com> Date: Tue Aug 12 13:28:34 2008 -0700 Added test file. A test 

然后提取文件添加:

 git-log --name-status | sed -ne 's/^A[^u]//p' | sort -u 

这里有两个有用的别名:FindFile ff和FindFilewithCopies ffc

 # Find if one file ever had into repository ff = "!git log --pretty=format: --name-status --all -M -B | sort -u | grep $1 #" # The same as above but showing copied files ffc = "!git log --pretty=format: --name-status --all -C -M -B | sort -u | grep $1 #" 

您可以获得有关文件名和操作的信息。

样品使用:

 $ git ff create A database/migrations/2014_10_12_000000_create_users_table.php A database/migrations/2014_10_12_100000_create_password_resets_table.php A database/migrations/2015_05_11_200932_create_boletin_table.php A database/migrations/2015_05_15_133500_create_usuarios_table.php D database/migrations/2015_05_12_000000_create_users_table.php M database/migrations/2015_05_11_200932_create_boletin_table.php R051 database/migrations/2014_10_12_000000_create_users_table.php database/migrations/2015_05_12_000000_create_users_table.php $ git ffc create A database/migrations/2014_10_12_000000_create_users_table.php A database/migrations/2014_10_12_100000_create_password_resets_table.php A database/migrations/2015_05_11_200932_create_boletin_table.php A database/migrations/2015_05_15_133500_create_usuarios_table.php C052 database/migrations/2014_10_12_000000_create_users_table.php database/migrations/2015_05_11_210246_create_boletin_nosend_table.php D database/migrations/2015_05_12_000000_create_users_table.php M database/migrations/2015_05_11_200932_create_boletin_table.php R051 database/migrations/2014_10_12_000000_create_users_table.php database/migrations/2015_05_12_000000_create_users_table.php