简体   繁体   中英

see all history of git

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.

There are two ways :-

Classic : git reflog

Big Picture :) git log --graph --decorate --oneline

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM