Leos313
Leos313

Reputation: 5647

git rebase with the fast forward option enabled

Let's say I have a situation like this:

a -- b -----------------c -- d -- e   <-- Master
      \
       f ------------l                <-- Branch1
        \           /
         g -- h -- i                  <-- Branch2

Where i was merged with f by using:

git merge --no-ff

Well, now I want to rebase the Branch1 to the master.

If I use git rebase master Branch1 the result is:

a -- b -- c -- d -- e                     <-- Master
                     \
                       f -- g -- h -- i   <-- Branch1

It has just merged ignoring my previous --no-ff.

Question:

Is there an instruction like git rebase --no_ff ...?

What I would like to achieve is:

a -- b -- c -- d -- e                   <-- Master
                     \
                      f ------------l   <-- Branch1
                       \           /
                        g -- h -- i     <-- Branch2

Looking on the web (included stackoverflow) I was not able to find any useful information.

Upvotes: 1

Views: 686

Answers (1)

joanis
joanis

Reputation: 12280

Solution

The -p option to git rebase is intended to solve this problem.

This should work:

git rebase -p master Branch1

From git rebase -h:

-p, --preserve-merges
                      try to recreate merges instead of ignoring them

Caveats

Thanks @andreee for pointing these issues out, documented in git rebase --help:

  • Merge conflict resolutions or manual amendments to merge commits are not preserved.
  • combining --preserve-merges with --interactive is generally not a good idea

Upvotes: 1

Related Questions