Recover from git reset --hard?

后端 未结 22 2516
盖世英雄少女心
盖世英雄少女心 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:45

    While I was working on a local project, I wanted to move it to GitHub and then created a new repository. While I was trying to add all these files to the new repository with .gitignore, I accidentally added a wrong file and then tried to clear it.

    I ran git reset --hard origin/master :P

    Then all of my local files deleted because the repo was empty. I thought everything was gone.

    This saved my life:

    git reflog show
    git reset HEAD@{1} 
    git push 
    

    Hope it saves another life.

提交回复
热议问题