0

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?

Yusef Maali
  • 2,201
  • 2
  • 23
  • 29
doctopus
  • 5,349
  • 8
  • 53
  • 105
  • 1
    You should look at git reflog, previous states should be there. I would also push your branches just in case you screw up again. It's unclear what the correct bit of work to go to is, but maybe reflog will show some options... Lesson is to commit more frequently!! – Andy Hayden Oct 24 '17 at 00:45
  • You **should** be able to call `git checkout fix-error-msg` -check reflog first, as recommended above. – S. Walker Oct 24 '17 at 00:46
  • sorry guys, i forgot to add that i deleted the branch by calling `git checkout -D fix-error-msg` : / – doctopus Oct 24 '17 at 00:54
  • `git checkout @{1}` – jthill Oct 24 '17 at 01:14
  • *git reflog* is the way to go. Your commit (the pointed to by the branch you deleted) should still be there. – eftshift0 Oct 24 '17 at 01:41

1 Answers1

0

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?

Yusef Maali
  • 2,201
  • 2
  • 23
  • 29