Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a complex octopus merge?

Tags:

git

merge

I just make 8 different suggestions off of the tip of master, and I want to make a commit that merges all of them together. I've done the merges by manually resolving merge conflicts one-by-one (and then squashed them together with git merge --squash), but now, when I try to make an octopus merge commit with git merge -s ours branch1 branch2 branch3 etc, it replies Merge with strategy ours failed. If I commit the squashed merges and then a multi-parent commit, the commit works, but I have a commit that does something, followed by an empty commit, and I don't want that. How do I combine the merge content commit with the merge parent commit?

like image 591
Stuart P. Bentley Avatar asked Mar 23 '15 11:03

Stuart P. Bentley


People also ask

How do I merge multiple branches?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.


1 Answers

It sounds like you have a tree with the right content, and now you want to create a commit with that content and the right parents. I'm not entirely sure how you'd use git porcelains to make the commits you want, but as you've got the plumbing accessible to you, you may use that directly if you'd like.

If you've got all your files correctly merged and in your index, you can find out the hash of the tree using git write-tree:

$ git write-tree
4d5fcadc293a348e88f777dc0920f11e7d71441c

You can then create a commit with the right parents:

$ git commit-tree 4d5fcadc293a348e88f777dc0920f11e7d71441c -p branch1 -p branch2 ... -m "Dummy Message"
85e2a8f2f71816d17887caaf39e46225e47165a9

And update your branch to point at that new commit

$ git reset --hard 85e2a8f2f71816d17887caaf39e46225e47165a9

I usually create the commit with a dummy message then go back and use git commit --amend to fill it in later.

like image 98
Andrew Aylett Avatar answered Oct 03 '22 15:10

Andrew Aylett