Redo bad git conflict resolution after push

為{幸葍}努か 提交于 2019-11-30 03:27:38

问题


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 merged In.
  • Conflicts resolved from merge (creates merge commit).
  • Push to remote.
  • Other people merge into Branch 'A' and push to remote.
  • Oh dear I have realised my conflict resolution was wrong, I went with theirs instead of mine, whatever.
  • Now what?

I essentially want to re-do the conflict resolution part.

I don't have the option of re-setting my HEAD as the branch has already been pushed to the remote; and has the possibility of other people having committed on it, before I had realised the conflict resolution was wrong.

I also want to avoid making a direct fix on branch 'A'.

I want to avoid cherry picking. I know I can do a standard revert and cherry pick my commits etc, I don't want to do this.

So is there any graceful way of doing this?

I have tried reverting the merge commit then reverting the revert and merging branch 'B' back in again, but unfortunately it does not ask me to resolve any conflicts the second time round, I just get the standard 'Already up to date' message.

Putting it simply, I want to re-create my conflict so I can resolve it correctly the second time round.

Any help will be much appreciated.

Thanks.


回答1:


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.



来源:https://stackoverflow.com/questions/43007243/redo-bad-git-conflict-resolution-after-push

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