393

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Toby
  • 8,483
  • 13
  • 45
  • 68
  • 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`. – Gabriel Staples Mar 30 '20 at 23:09

9 Answers9

518
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
Community
  • 1
  • 1
I82Much
  • 26,901
  • 13
  • 88
  • 119
  • 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. – T.J. Crowder Aug 09 '14 at 08:43
  • 34
    You should also look at the **git whatchanged** command. It's pretty cool. – Mr.Black Mar 19 '15 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` – Slaven Rezic Jul 21 '15 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`` – Michael Große Jun 30 '16 at 10:53
  • If you know the name of the file then this will give a bit more context (15 lines +/-) around the results: `git log --diff-filter=D --summary | grep -15 ` – gArn Jun 22 '18 at 11:09
  • 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. – Vadim Jan 10 '19 at 19:11
  • This does not list files, only the commits that contains changes of those files. The answer by Mark Longair does the right thing. – Jaap Eldering Apr 02 '20 at 16:11
  • it worked! How to show the log from a specific folder? I tried '-- folder' and doen't seems to work – Taison Morris Apr 30 '20 at 19:01
  • 1
    @Mr.Black `man git whatchanged` recommends `git log` instead for general use: “New users are encouraged to use git-log(1) instead. … The command is kept primarily for historical reasons”. I would use `git log --patch` instead. – Guildenstern Oct 16 '20 at 13:21
107

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
...
the Hutt
  • 16,980
  • 2
  • 14
  • 44
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
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
Jim Clouse
  • 8,774
  • 6
  • 32
  • 25
  • 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 '12 at 20:58
  • 1
    or `git rm $(git ls-files --deleted)` – yunzen Jul 08 '15 at 12:42
  • 4
    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 – solstice333 Aug 08 '19 at 00:17
21

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
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
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)

estani
  • 24,254
  • 2
  • 93
  • 76
  • 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 '15 at 07:07
  • The case I had was that the directory was also removed and I just new part of the name. – estani Sep 23 '15 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
James Skemp
  • 8,018
  • 9
  • 64
  • 107
  • What is `Select-String`? – MarcusJ Dec 15 '17 at 12:03
  • 4
    It's a PowerShell cmdlet. See https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?view=powershell-5.1 – James Skemp Dec 15 '17 at 17:03
  • Windows has [FIND](https://ss64.com/nt/find.html) and [FINDSTR](https://ss64.com/nt/findstr.html), though I must admit I have never used them. Installing [Git Bash](https://superuser.com/questions/1053633/what-is-git-bash-for-windows-anyway) is the easiest way. An alternative is the bloated [Cygwin](https://en.wikipedia.org/wiki/Cygwin). – Peter Mortensen May 13 '20 at 22:56
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 
pfrenssen
  • 5,498
  • 1
  • 22
  • 16
vix2
  • 51
  • 1
  • 2
  • 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` – nathaneastwood Jul 05 '19 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.

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
0

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>
Aman Kumar
  • 41
  • 4