Find when a file was deleted in Git
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Git tracks every change to your repository, including file deletions. If a file was deleted in a past commit, you can find exactly when it was removed, who deleted it, and even recover its contents. The key tools are git log with --diff-filter=D and --all flags.
Find When a Specific File Was Deleted
This shows the full commit history for that file, including the commit where it was deleted. The last commit in the output is the deletion commit.
Add --oneline for a compact view:
Find All Deleted Files
List every file deletion across the entire repository history:
This shows all commits that deleted files, with delete mode lines indicating which files were removed:
For a more concise output showing only filenames:
Find Who Deleted a File
The format placeholders:
%h— short commit hash%an— author name%ad— author date%s— commit subject
Recover a Deleted File
Once you know the deletion commit, recover the file from the commit before it:
The ~1 suffix means "the parent commit." This retrieves the file as it existed just before deletion.
Search for a Deleted File by Name
If you do not remember the full path:
View the Contents of a Deleted File
View the Deletion Diff
See exactly what was in the file when it was deleted:
This shows the diff for that commit, including all the removed lines (prefixed with -).
Using git bisect to Find When a File Disappeared
For complex histories, git bisect can pinpoint the exact commit:
Diff Filter Options Reference
| Filter | Meaning |
--diff-filter=D | Deleted files only |
--diff-filter=A | Added files only |
--diff-filter=M | Modified files only |
--diff-filter=R | Renamed files only |
--diff-filter=C | Copied files only |
Combine filters: --diff-filter=DR shows deleted and renamed files.
Common Pitfalls
- File moved, not deleted: If a file was renamed or moved,
git log -- old/pathshows it as deleted. Usegit log --follow -- new/pathto track a file across renames, or--diff-filter=Rto find renames. - Shallow clones:
git clone --depth=1does not include full history. The deletion commit may not exist in a shallow clone. Usegit fetch --unshallowto get the full history. - The
--allflag: Without--all,git logonly searches the current branch. The file might have been deleted on a different branch. Always use--allwhen searching across the entire repository. - Case sensitivity: On case-insensitive filesystems (macOS, Windows),
path/to/File.txtandpath/to/file.txtmay refer to the same file. Git tracks the exact case used at commit time. - Recovering to working directory:
git checkout <commit> -- filestages the recovered file and adds it to the working directory. You still need to commit it to make the recovery permanent.
Summary
- Use
git log --all -- path/to/fileto find when a specific file was deleted - Use
git log --diff-filter=D --summaryto list all file deletions across history - Recover deleted files with
git checkout <commit>~1 -- path/to/file - Use
git show <commit>~1:path/to/fileto view deleted file contents without recovering - Always include
--allto search across all branches

