Git:向前移动一个提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21105315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: Move head one commit ahead
提问by SeekingAlpha
I did a git reset HEAD~1
to go back one commit. I did this a number of times.
我做了一个git reset HEAD~1
返回一个提交。我这样做了很多次。
I now want to go back to where HEAD
was originally but am not sure how to move my HEAD
forward.
我现在想回到HEAD
原来的地方,但不知道如何HEAD
前进。
Does anyone know what command I need to use?
有谁知道我需要使用什么命令?
1-2-3-4-5-6
1-2-3-4-5-6
Originally I was at 6 and I reset back to 3. I now want to go back to 5. My understanding is that since I did not do git reset --hard
my original files from commit 6 is still available. Theoretically I should be able to un-reset and move back up correct?
最初我在 6 并且我重置回 3。我现在想回到 5。我的理解是,因为我没有做git reset --hard
我从提交 6 开始的原始文件仍然可用。从理论上讲,我应该能够取消重置并正确地向上移动吗?
回答by user3159253
use git reflog
to see SHA-1 of last operations and then do git reset --hard <sha1>
.
用于git reflog
查看上次操作的 SHA-1,然后执行git reset --hard <sha1>
.
Git keeps objects (and their SHA-1 respectively) even they go "out of scope" until next git gc
invocation. So if you think, you've lost something in the project history, use git reflog
to see if that smth is there.
Git 会保留对象(以及它们的 SHA-1),即使它们“超出范围”直到下一次git gc
调用。因此,如果您认为您在项目历史中丢失了某些东西,请使用它git reflog
来查看是否存在。