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

LuisPa @luispa

About: software gardener | everybody so judgemental.

Location:
internet
Joined:
Mar 25, 2017

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

Publish Date: Jan 5 '23
10 0

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

Comments 0 total

    Add comment