简体   繁体   English

看看git的所有历史

[英]see all history of git

Let's say, my current git log is 比方说,我目前的git日志是

commit3 commit3

commit2 commit2

commit1 commit1

I reset the head to commit2. 我将头重置为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? 现在我想回到commit3,但是我忘记了commit3的sha-1,所以我想查看日志,但是“git log”只会显示commit2,commit1,我的问题是如何重置为commit3或者让日志显示现在也是commit3?

Thanks 谢谢

Use git reflog to find the old reference and pass it to git log directly. 使用git reflog查找旧引用并直接将其传递给git log 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. 请注意,定期清除reflog,并且最终将删除旧提交,除非它们是分支的一部分 - 如果要撤消提交但将其保留在历史记录中,请使用git revert撤消它们而不从历史记录中删除它们。

The command 命令

git reflog

will show you a list of SHAs that have been the HEAD. 将向您显示已成为HEAD的SHA列表。 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. 在该列表中,您还将看到语法HEAD@{1}HEAD@{2}等。这是解决先前HEAD的方法。

I your case git checkout HEAD@{1} should check out commit3, because it was the HEAD before the current HEAD. 我的情况git checkout HEAD@{1}应该检查commit3,因为它是当前HEAD之前的HEAD。

There are two ways :- 有两种方法: -

Classic : git reflog 经典:git reflog

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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