Introduction: Recovering Deleted Files in Git
It was late, the weather was foul, and my Wi-Fi decided to have an opinion. Something went wrong during a sync between two machines, and the next morning I discovered that an entire folder of images had quietly vanished from my Git repository. Not overwritten — deleted. Gone from the working tree and staged as deletions in the last commit.
If this has happened to you, take a breath. Git keeps the entire history of your project, including every file that was ever committed. Nothing is truly lost as long as the deletion was committed (and not just a git rm you haven’t committed yet — that is even easier to undo). Let me walk you through exactly what I did.
How to Restore Deleted Files in Git
Step 1 — Find the commit that deleted your files
Git’s --diff-filter option lets you filter the log to show only commits that match a specific kind of change. The flag D means “deleted”:
git log --diff-filter=D --summary
The --summary flag prints a brief list of files added, deleted, or renamed in each commit — which is exactly what we need. You will see output like this:
commit 45a2d299ef3d....
Author: Elena Daehnhardt <email@gmail.com>
Date: Wed Nov 29 12:05:06 2023 +0100
create_references
delete mode 100644 images/ai_art/dalle/elena/dall.e.22.18.39.png
delete mode 100644 images/ai_art/dalle/elena/dall.e.22.18.45.png
delete mode 100644 images/ai_art/dalle/elena/dall.e.22.18.50.png
There it is. Copy the commit hash — you will need it in the next step.
Inspecting what changed at a commit
🔒 Subscribe to keep reading.
Conclusion: Git History as a Time Machine
🔒 Subscribe to keep reading.
References
🔒 Subscribe to keep reading.
You've hit a Deep Dive tutorial.
I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):
Full content temporarily unavailable — refresh in a moment
Already a subscriber? Use the magic link from your last newsletter, or reset your password.
Log in to unlock
New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in — use the same email afterwards.