Deleted a git branch, how to recover the commits?

I have a git repo that I hadn't commit in almost a week.

I was working on fixing how to display error messages in my react app.

So i decided to make a new branch by calling git checkout -b fix-error-msg

(note: I did NOT commit to master before creating new branch)

I made some changes in my code, but realised they were incorrect, so I decided I could be clever and go back to my original status by calling git commit -am 'oops' followed by git checkout master and followed by git branch -D fix-error-msg

I was hoping it would revert the code to what it was before I created the fix-error-msg branch.

Nope - it's reverted the code to what it was a week ago since my last commit on master .

I decided to be clever and paid for it.

Is there any way to revert this mistake?


git reflog is the only way you have to save your committed (even not pushed) works.

Check this: How can I recover a lost commit in Git?

链接地址: http://www.djcxy.com/p/3972.html

上一篇: 将存储库恢复为SHA提交

下一篇: 删除了一个git分支,如何恢复提交?