Question

I have a local ref that contains a few branches that I recently performed git rebase on:

A---B---C---D master
     \
      E---F---G topic1
               \
                H---I---J topic2

Which turned it into:

A---B---C---D master
             \
              E'---F'---G' topic1
                         \
                          H'---I'---J' topic2

by using the following set of commands:

git checkout topic1
git rebase master
git checkout topic2
git rebase topic1

The problem?

I accidentally forgot to do git rebase --no-ff in order to keep track of all of my previously merged branches. Now, I have no way of easily telling (by using gitk --all) where my merges occurred. I know that they happened somewhere between HEAD@{E} and HEAD@{J}, but without going through each commit individually, I'm lost.

What I have decided to do:

So, I figured that I would use git reflog as suggested here, along with git reset --hard HEAD@{#} to revert back to the original state before the two rebases occurred and then attempt to git rebase branchname --no-ff as I suggested.

My ultimate question is this (with a few additional):

Can I simply go all the way back to the last commit before the first rebase or do I need to rollback each of the rebases individually? Will each of the top branches be exactly as I used to have them (showing the non-fast forwarded merges that I'm looking for)? Am I making this too difficult/is there a simpler way to do this? Anything I'm neglecting to think about?

Thanks.

Was it helpful?

Solution

If you reset each branch to the commit it was on before the rebase of that branch occurred, it will be like the rebase never happened. Each branch has its own history independent of any other branch, so you will need to reset each branch individually.

OTHER TIPS

Please take a look at git reflog. It has the previous references. You can reset to a commit from the reflog by doing git reset --hard HEAD@{2} to get the 2nd most recent commit being pointed to by HEAD. Same applies for branches.

You can even do that without checking them out like so:

git push . +topic1@{1}:topic1
git push . +topic2@{1}:topic2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top