Redo bad git conflict resolution after push

后端 未结 1 1562
感情败类
感情败类 2021-01-02 10:31

I want to re-create a merge conflict so I can resolve it correctly the second time round.

Example:

  • Branch \'A\' checked out.
  • Branch \'B\' is
相关标签:
1条回答
  • 2021-01-02 10:36

    There's two steps here. First is recreating the merge and conflict. The second is applying it to the new tip of the branch.

    You have something like this.

    1 - 2 - 5 - 6 - 7 - 9 - 10 [A]
         \         /
          3 - 4 - 8
    

    7 is the merge commit and you want to redo that and apply the fixes on top of A. Rebasing might get messy because too much work has been piled on top.

    First, let's recreate the merge conflict. To do that we'll just do it over again. Checkout 6, that's where A was when you merged, and merge it with 8.

    git checkout 6
    git merge 8
    

    You'll have to use git log --graph to determine the actual commit ids. Now we have the merge conflict. Resolve it as you would but don't commit it. Instead, stash it. git stash save. This will save the diff off in a corner called "the stash". This is just a more formal way of saving patches.

    Now that we've got the conflict resolution as it would have happened, checkout A and apply the fix from the stash.

    git checkout A
    git stash pop
    

    Since there's been changes to A, you may get fresh conflicts out of this. That's fine. Resolve them normally and commit.

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