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

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?


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看到提交的提交ID。


Even easier (if you haven't done any other operations):

git reset ORIG_HEAD

ORIG_HEAD is the previous state of HEAD .

More details about HEAD vs. ORIG_HEAD are in the answer to this SO question.

链接地址: http://www.djcxy.com/p/36248.html

上一篇: 忽视git忽略与假设

下一篇: 如何恢复一个不必要的“git reset HEAD〜1”