Recover deleted file from Git

To recover an old file from git where you don’t know the commit, you can do:

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"

Finds the last commit that affected the given path and checks out the file from there. Works on any file still in the history. If the file has not been staged or committed, simply use git checkout $file.

From: SO

Leave a Reply