Let's say, my current git log is
commit3
commit2
commit1
I reset the head to commit2.
Now I want to go back to commit3, but I forget the sha-1 of commit3, so I want to look at the log , but "git log" will only show commit2, commit1, my question is how to reset to commit3 or let the log show also commit3 now?
Thanks
Use git reflog
to find the old reference and pass it to git log
directly. Note that the reflog is purged periodically, and old commits will be eventually deleted unless they're part of a branch - if you want to undo a commit but leave it in history, use git revert
to undo them without removing them from history.
The command
git reflog
will show you a list of SHAs that have been the HEAD. In other words, it shows a list of commits in the order that they have been checked out. In that list you will also see the syntax HEAD@{1}
, HEAD@{2}
etc. That is a way to address the previous HEADs.
I your case git checkout HEAD@{1}
should check out commit3, because it was the HEAD before the current HEAD.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With