Recover from git reset --hard?

后端 未结 22 2825
盖世英雄少女心
盖世英雄少女心 2020-11-22 00:52

Is there any way to recover uncommitted changes to the working directory from a git reset --hard HEAD?

22条回答
  •  执笔经年
    2020-11-22 01:33

    I ran into same issue and I was almost going insane....initially i committed the project and merged.. later when i try running git push --set-upstream origin master i was getting this error

      fatal: refusing to merge unrelated histories
    

    so i ran git reset --hard HEAD and it deleted a 3 weeks project but these few commands below save the day:

    git reset HEAD@{1}         //this command unstage changes after reset
    git fsck --lost-found      //I got the dangling commit fc3b6bee2bca5d8a7e16b6adaca6a76e620eca4b
    git show  fc3b6bee2bca5d8a7e16b6adaca6a76e620eca4b>
    git rebase fc3b6bee2bca5d8a7e16b6adaca6a76e620eca4b
    

    hope this helps

提交回复
热议问题