Say I\'m in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I find I need to restore that file.
I know
In many cases, it can be useful to use coreutils (grep, sed, etc.) in conjunction with Git. I already know these tools quite well, but Git less so. If I wanted to do a search for a deleted file, I would do the following:
git log --raw | grep -B 30 $'D\t.*deleted_file.c'
When I find the revision/commit:
git checkout ^ -- path/to/refound/deleted_file.c
Just like others have stated before me.
The file will now be restored to the state it had before removal. Remember to re-commit it to the working tree if you want to keep it around.