Redo bad git conflict resolution after push

别等时光非礼了梦想. 提交于 2019-11-30 19:21:49

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!