odbhut.shei.chhele
odbhut.shei.chhele

Reputation: 6264

How to convert a git merger into a rebase

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

Upvotes: 5

Views: 1976

Answers (2)

poke
poke

Reputation: 388463

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.

Upvotes: 2

Ivan Mushketyk
Ivan Mushketyk

Reputation: 8305

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

Upvotes: 5

Related Questions