如何列出 Git 存储库中所有已删除的文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6017987/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:56:31  来源:igfitidea点击:

How can I list all the deleted files in a Git repository?

git

提问by Toby

I know Git stores information of when files get deleted and I am able to check individual commits to see which files have been removed, but is there a command that would generate a list of every deleted file across a repository's lifespan?

我知道 Git 存储文件何时被删除的信息,我能够检查单个提交以查看哪些文件已被删除,但是是否有一个命令可以生成存储库生命周期中每个已删除文件的列表?

回答by I82Much

git log --diff-filter=D --summary

See Find and restore a deleted file in a Git repository

请参阅在 Git 存储库中查找和恢复已删除的文件

If you don't want all the information about which commit they were removed in, you can just add a grep deletein there.

如果你不想要关于它们被删除的提交的所有信息,你可以grep delete在那里添加一个。

git log --diff-filter=D --summary | grep delete

回答by Mark Longair

This does what you want, I think:

这就是你想要的,我认为:

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

... which I've just taken more-or-less directly from this other answer.

...我刚刚或多或少地直接从另一个答案中获取了它

回答by Jim Clouse

If you're only interested in seeing the currently deleted files, you can use this:

如果您只想查看当前已删除的文件,可以使用以下命令:

git ls-files --deleted

if you then want to remove them (in case you deleted them not using "git rm") pipe that result to xargs git rm

如果你想删除它们(如果你不使用“git rm”删除它们)导致 xargs git rm 的管道

git ls-files --deleted | xargs git rm

回答by akshay

Citing thisStack Overflow answer.

引用这个Stack Overflow 的答案。

It is a pretty neat way to get type-of-change (A:Added, M:Modified, D:Deleted)for each file that got changed.

这是为每个更改的文件获取更改类型(A:添加,M:修改,D:删除)的非常巧妙的方法。

git diff --name-status

回答by James Skemp

Since Windows doesn't have a grepcommand, this worked for me in PowerShell:

由于 Windows 没有grep命令,这在 PowerShell 中对我有用:

git log --find-renames --diff-filter=D --summary | Select-String -Pattern "delete mode" | sort -u > deletions.txt

回答by vix2

Show all deleted files in some_branch

显示some_branch 中所有已删除的文件

git diff origin/master...origin/some_branch --name-status | grep ^D

or

或者

git diff origin/master...origin/some_branch --name-status --diff-filter=D 

回答by estani

And if you want to somehow constrain the results here's a nice one:

如果你想以某种方式限制结果,这是一个很好的结果:

$ git log --diff-filter=D --summary | sed -n '/^commit/h;/\/some_dir\//{G;s/\ncommit \(.*\)/ /gp}'
delete mode 100644 blah/some_dir/file1 d3bfbbeba5b5c1da73c432cb3fb61990bdcf6f64
delete mode 100644 blah/some_dir/file2 d3bfbbeba5b5c1da73c432cb3fb61990bdcf6f64
delete mode 100644 blah/some_dir/file3 9c89b91d8df7c95c6043184154c476623414fcb7

You'll get all files deleted from some_dir(see the sed command) together with the commit number in which it happen. Any sed regex will do (I use this to find deleted file types, etc)

您将从some_dir(请参阅 sed 命令)中删除所有文件以及它发生的提交编号。任何 sed 正则表达式都可以(我用它来查找已删除的文件类型等)

回答by Mr_and_Mrs_D

This will get you a list of all files that were deleted in all branches, sorted by their path:

这将为您提供在所有分支中删除的所有文件的列表,按其路径排序:

git log --diff-filter=D --summary | grep "delete mode 100" | cut -c 21- | sort > deleted.txt

Works in msysgit (2.6.1.windows.1). Note we need "delete mode 100" as git files may have been commited as mode 100644 or 100755.

在 msysgit (2.6.1.windows.1) 中工作。请注意,我们需要“删除模式 100”,因为 git 文件可能已作为模式 100644 或 100755 提交。