My history tree currently looks like this:

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):

Thus, what I'd like to know, is how to make a4 now point on b3 instead of b2?
I acknowledge SHA1s will be different, and thus commits will be renamed a4' and a5'
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With