Search code examples
gitversion-controlrevision

git get back sha-1 after checking out an old revision


I have a git repo like this:

rev3
rev2
rev1
Init repo

and I checkout rev1,

then my git log looks like:

rev1
Init repo

so how can I go back to rev3? should I always have to copy-paste the git log before I do the checkout? that seems unacceptable for me. I read through Go to particular revision but that wasn't the answer I want, and I believe there must be some way I can do this without a copy-paste, just like tortoiseHg done.


Solution

  • If you just did a checkout to go back to rev1, then your branch, which you were on when you committed, should still point to rev3, so just checkout that branch and you should be good. However, if you did a hard reset, then you have to check the reflog (git reflog) to get the SHA of rev3.