列出 Git 存储库中曾经存在的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/543346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List all the files that ever existed in a Git repository
提问by elmarco
Do you have a clean way to list all the files that ever existed in specified branch?
您是否有一种干净的方法来列出指定分支中曾经存在的所有文件?
回答by Dustin
This is a simplified variation of Strager's solution:
git log --pretty=format: --name-status | cut -f2- | sort -u
Edit:Thanks to Jakub for teaching me a bit more in the comments, this version has a shorter pipeline and gives git more opportunity to get things right.
编辑:感谢 Jakub 在评论中教我更多,这个版本的管道更短,让 git 有更多机会把事情做好。
git log --pretty=format: --name-only --diff-filter=A | sort -u
回答by dch
This does the right thing for checking if a filename was ever present in the reponot just on the current branch.
这对于检查文件名是否存在于repo 中而不仅仅是在当前分支上是正确的。
git log --all --pretty=format: --name-only --diff-filter=A | sort - | grep fubar
回答by strager
You can run git-log --name-status
, which echoes something like:
您可以运行git-log --name-status
,它会回显如下内容:
commit afdbbaf52ab24ef7ce1daaf75f3aaf18c4d2fee0
Author: Your Name <[email protected]>
Date: Tue Aug 12 13:28:34 2008 -0700
Added test file.
A test
Then extract files added:
然后提取文件添加:
git-log --name-status | sed -ne 's/^A[^u]//p' | sort -u
回答by Juan Antonio Tubío
Here is two useful alias: FindFile ff
and FindFilewithCopies ffc
:
这是两个有用的别名: FindFileff
和 FindFilewithCopies ffc
:
# Find if one file ever had into repository
ff = "!git log --pretty=format: --name-status --all -M -B | sort -u | grep #"
# The same as above but showing copied files
ffc = "!git log --pretty=format: --name-status --all -C -M -B | sort -u | grep #"
You get information about file names and operations with them.
您可以获得有关文件名和操作的信息。
Sample use:
样品用途:
$ 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