DEV Community

LuisPa
LuisPa

Posted on

How do I find the last version of a deleted file in Git

A few months ago, I deleted a file.

Today, I realized that actually, I need it! I picked a random commit 6 months ago and found the file… but hm, what if it changed after that point?

How do I find the final version of that file?

Here's the Git command I used:

$ git log --full-history -- src/path/to/file.js
Enter fullscreen mode Exit fullscreen mode

This finds the commit that deleted the file. So, I checked out that commit, and then backed up one more:

$ git checkout HEAD~1
Enter fullscreen mode Exit fullscreen mode

This loads the file right before it was deleted! 🎉

Git is such a powerful tool.

Happy hacking!

Originally posted here: https://blog.luispa.dev/posts/how-do-i-find-the-last-version-of-a-deleted-file-in-git

Oldest comments (0)