tags:

views:

39

answers:

1

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.

+1  A: 

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.

Novelocrat
Not necessarily - HEAD can get updated a lot of times during an interactive rebase. `git reset --hard <branch>@{3}` would work, though - assuming all of the rebases actually did something. If they didn't, that'd be too far back in the history. I'd recommend looking at `git reflog show <branch>` to make sure you get what you want.
Jefromi
Will git checkout <file> accomplish the same thing, or will that have only worked prior to doing the rebases?
ConnorG
`git checkout <file>` grabs the version of `<file>` from the index and places it in the work tree. It only affects that file in the work tree. It has nothing to do with moving `HEAD` around.
Jefromi
Ahhh, gotcha. I had originally thought the OP wanted to do something different, but it makes much more sense now. Thanks!
ConnorG