restore - git reset --hard HEAD^

后端 未结 2 2074
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 00:03

Unfortunately I did several times git reset --hard HEAD^ losing a quite big chunk of code in several files. Is there a way to restore those commits or in this case

2条回答
  •  隐瞒了意图╮
    2021-02-14 00:46

    Use the reflog to recover the sha1 of the previous HEAD. In particular, the article reflog, your safety net will be particularly relevant to you. From that article:

    The most common usage of this command is that you’ve just done a git reset and moved your HEAD back a few commits. But oops, you need that bit of code you left in the second commit. Crap. Now what?

    Once you have found the sha1 of the commit you want to go back to, use something like:

    git reset --hard 0a1b2c
    

提交回复
热议问题