Retrieve a deleted file in a git repository

So… you deleted a file last week in your git repo and now you want it back? No problem:

1. Use git log –diff-filter=D –summary to get all the commits which have deleted files and the files deleted.
2. Use git checkout $commit~1 path/to/file.ext to restore the deleted file.

* Where $commit is the value of the commit you’ve found at step 1, e.g. e4cf4996

Thats it 🙂

Posted in Git