开发者

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开发者_Go百科, 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜