How to revert an unnecessary “git reset HEAD~1”

前端 未结 3 1021
天涯浪人
天涯浪人 2021-01-31 15:13

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?

相关标签:
3条回答
  • 2021-01-31 15:38

    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.

    0 讨论(0)
  • 2021-01-31 15:40

    You could see the commit id of that commit with git reflog.

    0 讨论(0)
  • 2021-01-31 15:51

    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.

    0 讨论(0)
提交回复
热议问题