如何恢复不必要的“git reset HEAD~1”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16944826/
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
How to revert an unnecessary "git reset HEAD~1"
提问by cahen
After running git reset HEAD~1
, I noticed that actually there was nothing else to do and the commit was fine. Is there a way to revert this command?
运行后git reset HEAD~1
,我注意到实际上没有其他事情可做,并且提交很好。有没有办法恢复这个命令?
回答by michas
You can use:
您可以使用:
git reset HEAD@{1}
This uses the last entry in the reflog. See git reflog
if you did other things in between.
这将使用引用日志中的最后一个条目。看看git reflog
你是否在这之间做了其他事情。
回答by Adrian Panasiuk
You could see the commit id of that commit with git reflog
.
您可以使用git reflog
.
回答by Andrejs
Even easier (if you haven't done any other operations):
更简单(如果您还没有进行任何其他操作):
git reset ORIG_HEAD
ORIG_HEAD
is the previous state of HEAD
.
ORIG_HEAD
是之前的状态HEAD
。
More details about HEAD
vs. ORIG_HEAD
are in the answer to this SO question.
关于HEAD
vs. 的更多细节ORIG_HEAD
在这个 SO question的答案中。