How can I list all the deleted files in a Git repository?
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?
Solution 1:
git log --diff-filter=D --summary
See Find and restore a deleted file in a Git repository
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:
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:
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:
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