How do I restore files to previous states in git?

Git

Git Problem Overview


Given the following interaction:

$ git add foo 
$ git commit -m "Initial import of 'foo'"
$ rm foo # This could be any destructive action on foo, like editing it.

How do I restore 'foo' in my working copy? I'm looking for something like:

$ git <magic> foo
Restored foo to revision <blah>.

Git Solutions


Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAaron MaenpaaView Question on Stackoverflow