Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

see all history of git

Tags:

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

like image 848
Fred Yang Avatar asked Jan 22 '11 14:01

Fred Yang


2 Answers

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.

like image 62
bdonlan Avatar answered Nov 10 '22 01:11

bdonlan


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.

like image 43
Theo Avatar answered Nov 09 '22 23:11

Theo