In git, how do you revert a file back to 3 commits ago?

Patoshi パトシ picture Patoshi パトシ · Jan 8, 2014 · Viewed 8.2k times · Source

I changed an image file in git and it was 2 commits ago. How do I go back to 2 previous commits ago?

What is the easiest method of doing this file revert via the command line with the least amount of commands required?

Answer

poke picture poke · Jan 8, 2014

Just check out the old version of that file:

git checkout HEAD~2 -- path/to/file

Or more explicit:

git checkout commit-id -- path/to/file