I want to re-create a merge conflict so I can resolve it correctly the second time round.
Example:
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.
On the command line, a simple "git merge --abort" will do this for you. In case you've made a mistake while resolving a conflict and realize this only after completing the merge, you can still easily undo it: just roll back to the commit before the merge happened with "git reset --hard " and start over again.
You can use the git reset --merge command. You can also use the git merge --abort command.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With