7

My history tree currently looks like this: enter image description here

I'd like to apply commit b3 to branch master. Of course I could merge again branch feature into master but history will look messy with two merge commits (a6, and a4 that is just useless now): enter image description here


Thus, what I'd like to know, is how to make a4 now point on b3 instead of b2? enter image description here I acknowledge SHA1s will be different, and thus commits will be renamed a4' and a5'

ebosi
  • 1,285
  • 5
  • 17
  • 37

1 Answers1

3

From the master branch, you can simply rebase onto the new b3 while preserving merges using the --preserve-merges option (or -p in short):

git rebase -p feature

That way, when Git rebases, it will not attempt to flatten the merge, but instead recreate it on top of the new base commit. So your history will look like this:

                               master
                                 ↓
a1 -- a2 -- a3 --------- a4' -- a5'
        \                /
         \              /
          b1 -- b2 -- b3
                      ↑
                   feature

Compared to the following when not using the --preserve-merges flag:

                                      master
                                        ↓
a1 -- a2                 a3' -- a4' -- a5'
        \                /
         \              /
          b1 -- b2 -- b3
                      ↑
                   feature
poke
  • 369,085
  • 72
  • 557
  • 602
  • OP should (and, I see, did) note that the result is a new (different) merge, with different hash and different tree. As you say, rebase re-*creates* (i.e., make a *new*) merge that supplants the old one. Anyway, upvoted. :-) – torek Jan 03 '17 at 03:48
  • 1
    @torek Yeah, I use the `x'` notion to denote that it’s a recreated commit based on the original `x` :) – poke Jan 03 '17 at 07:14