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

Git

Git Problem Overview


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 Solutions


Solution 1 - Git

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

See https://stackoverflow.com/questions/953481/restore-a-deleted-file-in-a-git-repo

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

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

Solution 2 - Git

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.

Solution 3 - Git

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 ls-files --deleted | xargs git rm

Solution 4 - Git

Citing this Stack Overflow answer.

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

git diff --name-status HEAD~1000

Solution 5 - Git

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 \(.*\)/ \1/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)

Solution 6 - Git

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

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

Solution 7 - Git

Show all deleted files in 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 

Solution 8 - Git

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.

Solution 9 - Git

If you want the names purely separated by a newline character, you can use the --name-only flag like this:

git diff --diff-filter=D --name-only <old-commit-hash> <new-commit-hash>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTobyView Question on Stackoverflow
Solution 1 - GitI82MuchView Answer on Stackoverflow
Solution 2 - GitMark LongairView Answer on Stackoverflow
Solution 3 - GitJim ClouseView Answer on Stackoverflow
Solution 4 - Gituser3275211View Answer on Stackoverflow
Solution 5 - GitestaniView Answer on Stackoverflow
Solution 6 - GitJames SkempView Answer on Stackoverflow
Solution 7 - Gitvix2View Answer on Stackoverflow
Solution 8 - GitMr_and_Mrs_DView Answer on Stackoverflow
Solution 9 - GitAman KumarView Answer on Stackoverflow