How can I undo git reset --hard HEAD~1?

后端 未结 18 3111
逝去的感伤
逝去的感伤 2020-11-22 00:21

Is it possible to undo the changes caused by the following command? If so, how?

git reset --hard HEAD~1
18条回答
  •  无人及你
    2020-11-22 00:30

    as far as i know, --hard will discards uncommitted changes. Since these aren't tracked by git. but you can undo the discarded commit.

    $ git reflog
    

    will lists:

    b0d059c HEAD@{0}: reset: moving to HEAD~1
    4bac331 HEAD@{1}: commit: added level introduction....
    ....
    

    where 4bac331 is the discarded commit.

    Now just move the head to that commit::

    $ git reset --hard 4bac331
    

提交回复
热议问题