Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get back to where I was... (roll back to previous commit) Git beginner

Tags:

git

My last commands were:

git rebase -i HEAD^^

git rebase -i HEAD^^

git rebase -i HEAD^^^

How do I get the repository back to the state it was in before the first of the listed commands?

NOTE: all I have been doing thus far is git commit -am "my commit message". I don't understand branching and merging yet so I haven't used them. I was trying to roll back the code to the previous commit, but this didn't seem to do anything.

like image 338
66tree Avatar asked Feb 26 '23 09:02

66tree


1 Answers

If those are the exact commands you've run, then git reset --hard HEAD@{3} will get you back to your HEAD as of 3 commands ago. More generally, look at the output of git reflog to come up with the ref you want to recover, and then git reset to that.

like image 73
Phil Miller Avatar answered Mar 01 '23 08:03

Phil Miller