Recover a deleted file in git history
Firstly, get all deleted files:
git log --diff-filter=D --summary
Then, find the desired file:
grep "/filename$"
Keep only the filepath:
sed "s/ [^0-9]\+ [0-9]\+ \(.*\)$/\1/"
All together:
git log --diff-filter=D --summary | grep "/filename$" | sed "s/ [^0-9]\+ [0-9]\+ \(.*\)$/\1/"
Choose the correct filepath and finally restore it:
git checkout your_branch -- filepath
Only the commands:
git log --diff-filter=D --summary | grep "/filename$" | sed "s/ [^0-9]\+ [0-9]\+ \(.*\)$/\1/"
git checkout your_branch -- filepath
Written by Matheus de Souza
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Related Tags
#git
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#