How to revert only one file back to a revision or commit

I messed up with one file in one repository and want to check out only that file back to a commit. How to achieve this?

To check the file with at git commit commit_sha1:

$ git checkout commit_sha1

You can also use the relative commit instead of commit_sha1 such as master~4, HEAD~4, HEAD^, master^ and etc.

To check back (the master) of

$ git checkout master

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *