How to convert a git merger into a rebase

1.7k views Asked by At

I have merged two branches. Now it seems that I had to rebase the two branches. What should I do? Here is what I am looking for

enter image description here

2

There are 2 answers

2
Ivan Mushketyk On BEST ANSWER

If you are on the develop branch:

Revert the merge:

git reset --hard [last-commit-before-merge]

Go to experiment branch:

git checkout experiment

Perform the rebase:

git rebase -i develop

2
poke On

You can just reset your branch to the point before the merge and then perform a rebase instead. So if this is your situation:

                       experiment
                          ↓
  A --- B --- C --- D --- E
 /                         \
* --- * --- * ----- X ----- M
                            ↑
                          master

Then reset master to commit X, and then perform the rebase on experiment:

git checkout master
git reset --hard X
git checkout experiment
git rebase master

Then you will end up with this:

* -- * -- * -- X -- A' -- B' -- C' -- D' -- E'
               ↑                            ↑
             master                     experiment

So the merge commit M is gone and your experiment branch is rebased onto master. You can then fast-forward master and get rid of the experiement branch.