Stuart P. Bentley
Stuart P. Bentley

Reputation: 10675

How can I make a complex octopus 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?

Upvotes: 8

Views: 2067

Answers (2)

Andrew Aylett
Andrew Aylett

Reputation: 40690

If you'd prefer not to use plumbing directly (and who could blame you?) then you may be able to rebase your problems away.

The trick here is that you have one commit with your actual changes in it, and a single parent, and another with no changes but multiple parents. If you squash changes together, then the first commit's parents remain.

At the moment, your commits are in the wrong order to do a squash: the second commit, with its parents, would be lost. But because that commit has no changes, it should be possible to re-order them so the squash will work.

If you're working on master, and origin/master points at the last commit before you started, then do git rebase -i origin/master which should give you two commits in an editor:

pick 12345 All changes here
pick 67890 Octopus merge

Move the second line up, then squash in the changes:

pick 67890 Octopus merge
squash 12345 All changes here

Save and exit, and I hope that works :).

Upvotes: 3

Andrew Aylett
Andrew Aylett

Reputation: 40690

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.

Upvotes: 12

Related Questions