如何恢复不必要的“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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:20:09  来源:igfitidea点击:

How to revert an unnecessary "git reset HEAD~1"

git

提问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 reflogif 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_HEADis the previous state of HEAD.

ORIG_HEAD是之前的状态HEAD

More details about HEADvs. ORIG_HEADare in the answer to this SO question.

关于HEADvs. 的更多细节ORIG_HEAD这个 SO question答案中