400

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?

1
  • For anyone stumbling upon this answer but just looking to see a list of files added, renamed, deleted, modified, etc, from one commit hash or branch to another, do this: git diff --name-status commit_hash. Mar 30, 2020 at 23:09

9 Answers 9

523
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
9
  • 18
    Warning: This lists any files you've deleted. If you've deleted a file, then created a new file with the same name, it will show up on this list, even though there's an extant file there. Aug 9, 2014 at 8:43
  • 35
    You should also look at the git whatchanged command. It's pretty cool.
    – Mr.Black
    Mar 19, 2015 at 19:30
  • 8
    This would list also the renames as deletes. To skip these use git log --find-renames --diff-filter=D --summary | grep delete Jul 21, 2015 at 13:00
  • 3
    With git 2.9 detection of renames is activated by default. To see these again as deletes use git log --no-renames --diff-filter=D --summary | grep delete Jun 30, 2016 at 10:53
  • 2
    Beware using grep delete because if the commit message has the word delete, it'll be picked up as well. Use grep 'delete mode' instead. Jan 10, 2019 at 19:11
109

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.

This prints only file paths without other info:

BETA.md
CONTRIBUTING.md
files/en-us/api/file_api/index.html
files/en-us/games/index/index.md
files/en-us/games/visual-js_game_engine/index.html
files/en-us/games/visual_js_ge/index.html
files/en-us/games/visual_typescript_game_engine/index.html
...
0
50

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
3
  • 11
    This shows only files in the index that have been deleted in the working copy. The OP wants all files that have ever been deleted.
    – Max Nanasy
    Sep 25, 2012 at 20:58
  • 1
    or git rm $(git ls-files --deleted)
    – yunzen
    Jul 8, 2015 at 12:42
  • 5
    even though it's not what the OP wanted, this was still useful for at least myself, since I had trouble phrasing my query properly in a search Aug 8, 2019 at 0:17
22

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
0
5

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)

2
  • 2
    I believe that's way to complicated to be useful in daily developer life. Instead, if you want to list files deleted from current directory, just do: git log --diff-filter=D .
    – Sebi
    Sep 23, 2015 at 7:07
  • The case I had was that the directory was also removed and I just new part of the name.
    – estani
    Sep 23, 2015 at 10:13
5

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
3
5

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 
1
  • 3
    This wouldn't work because it would contain all files with a D in them. You need something like git diff origin/master...origin/some_branch --name-status | grep ^D or git diff origin/master...origin/some_branch --name-status --diff-filter=D Jul 5, 2019 at 14:16
2

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.

1

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.