How can I make a complex octopus merge?

前端 未结 2 1421
一向
一向 2021-02-09 22:11

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 con

相关标签:
2条回答
  • 2021-02-09 22:25

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

    0 讨论(0)
  • 2021-02-09 22:41

    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.

    0 讨论(0)
提交回复
热议问题