回滚到以前的版本后获取完整的git日志

问题描述:

我是git的新手,可能没有使用正确的术语,所以请忍受:)

I'm new to git, and probably not using correct terminology, so bear with me :)

假设我有一个包含5个更改的存储库,例如

Let's say I have a repository with 5 changes, e.g.

D:\test\gitrepo2>git log --oneline
3a5fd33 555
3cfbfae 444
e9a78c8 333
a618586 222
b80d5e1 111

我了解到可以通过执行以下操作来同步回早期版本:

I learned that I can sync back to an earlier revision by doing:

D:\test\gitrepo2>git reset e9a78c8 --hard
HEAD is now at e9a78c8 333

我的问题是:这样做之后,如何获取完整的日志,以便可以返回到最新版本?

运行日志不再显示这些修订版本:

Running log no longer shows those revisions:

D:\test\gitrepo2>git log --oneline
e9a78c8 333
a618586 222
b80d5e1 111

我也尝试添加--all开关,这没有什么不同.在Mercurial中,在相同的情况下,即使我更新到较早的修订版,运行'hg log'也会提供完整的日志.

I also tried add the --all switch, which didn't make a difference. In Mercurial, under the same scenario, running 'hg log' gives the complete log even after I update to an earlier revision.

我认为通过同步回",您的意思是您实际上只是希望工作副本看起来像以前的某个时间点.为此,您需要的是checkout,而不是reset:

I assume by "sync back" you really mean you just want your working copy to look like a previous point in time. To do that, you want checkout, not reset:

> git checkout e9a78c8

此时,您的存储库如下所示:

At that point, your repository looks like this:

> git log master --oneline
3a5fd33 555   <--- master is still here
3cfbfae 444
e9a78c8 333   <--- HEAD (working copy) is here
a618586 222
b80d5e1 111

现在返回到master上的最新提交,只需再次git checkout master.

Now to get back to the latest commit on master, just git checkout master again.

通过使用reset,您得到的是:

By using reset, you got this instead:

> git log master --oneline
e9a78c8 333   <--- HEAD (working copy) and master are here
a618586 222
b80d5e1 111