If you know the commit you want to return to is the head of some branch, or is tagged, then you can just
git checkout branchname
You can also use git reflog
to see what other commits your HEAD (or any other ref) has pointed to in the past.
Edited to add:
In newer versions of Git, if you only ran git checkout
or something else to move your HEAD
once, you can also do
git checkout -
to switch back to wherever it was before the last checkout. This was motivated by the analogy to the shell idiom cd -
to go back to whatever working directory one was previously in.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…