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

后端 未结 18 3357
逝去的感伤
逝去的感伤 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:50

    This has saved my life: https://medium.com/@CarrieGuss/how-to-recover-from-a-git-hard-reset-b830b5e3f60c

    Basically you need to run:

    for blob in $(git fsck --lost-found | awk ‘$2 == “blob” { print $3 }’); do git cat-file -p $blob > $blob.txt; done
    

    Then manually going through the pain to re-organise your files to the correct structure.

    Takeaway: Never use git reset --hard if you dont completely 100% understand how it works, best not to use it.

提交回复
热议问题