Restoring Removed Files With Git
By Andrew Price, 2009-01-11 04:01:49 in General.
So you've accidentally rm'd a file in a git tree and you want it back. What to do?
$ git checkout HEAD -- path/to/removed/file
This tip was brought to you by Andy's determination to remember how to do it next time, in cooperation with wasted moments spent reading the wrong man page (git reset). Sigh.
That's why I love bzr :P.
HEAD is the default, you can just do it like this:
git checkout path/to/removed/file
At first I was annoyed that the command is not "git revert" as with Subversion. But now that I'm used to Git, I think that "git checkout" is right because it is consistent with how Git works (you can checkout out all files of a branch, or single files of a branch, and it defaults to the current branch).