Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming the hash of the commit you want is
c5f567:The git checkout man page gives more information.
If you want to revert to the commit before
c5f567, append~1(where 1 is the number of commits you want to go back, it can be anything):As a side note, I’ve always been uncomfortable with this command because it’s used for both ordinary things (changing between branches) and unusual, destructive things (discarding changes in the working directory).
For the meaning of
--in the command, refer to In Git, what does--(dash dash) mean?There is also a new
git restorecommand that is specifically designed for restoring working copy files that have been modified. If your git is new enough you can use this command, but the documentation comes with a warning:Because
git restoreis experimental, it should not yet be promoted as the primary answer to this question. When the command is no longer marked as "experimental", then this answer can be amended to promote the use ofgit restore. [At the time of writing, thegit restorecommand has been marked as "experimental" for at least four years.]