Git: move commit before merge

In my story tree now it looks like this: enter image description here

I want to apply commit b3 to the master branch. Of course, I could merge the feature branch into master again, but the story would look messy with two merge commits ( a6 and a4 , which are now useless): enter image description here


So what would I like to know how to make a4 now point to b3 instead of b2 ? enter image description here I acknowledge that SHA1 will be different, and thus the commit will be renamed a4' and a5'

+5
source share
1 answer

From the main branch, you can simply reinstall the new b3 , saving the merge using the --preserve-merges (or -p short) option:

 git rebase -p feature 

That way, when Git rebases, it will not try to smooth out the merge, but instead recreates it on top of the new base commit. So your story will look like this:

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

Compared to the following when the --preserve-merges flag is not used:

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

Source: https://habr.com/ru/post/1262188/


All Articles