Once upon a time there was a file in my project which i'd like to get now

The problem is i don't know when i deleted it and what path it took

How do you find the commit of a file?

Best Answer

If you do not know the exact path you may use

git log --all --full-history -- "**/thefile.*"

If you know where the file was located you can do it

git log --all --full-history -- <path-to-file>

This should show a list of commits in all branches that touched this file Then, you can find the version of the file you want, and display it with...

git show <SHA> -- <path-to-file>

Or you can restore it with a working copy

git checkout <SHA>^ -- <path-to-file>

Note the caret symbol ( ^ ), which gets the checkout prior to the one identified, because at the moment of <SHA> commit the file is deleted, we need to look at the previous commit to get the deleted file's contents