Home > Software engineering >  Save merge conflict resolutions before git merge --abort
Save merge conflict resolutions before git merge --abort

Time:07-12

I am in the midst of a big merge request and already resolved a bunch of conflicts, when I realised that I want to run the merge command again with -Xignore-all-space. If I run git merge --abort I would also have to resolve all the conflicts I already did. Is there a way to record these (which are staged already), abort the merge request, try with the new flag and reapply the old changes where it is possible?

CodePudding user response:

I'm assuming you don't have rerere's auto mode turned on.

git worktree add scratch @
git -C scratch merge otherbranch   
git -C scratch rerere
git worktree remove -f scratch

these will rerun your current merge to get an index showing the un-resolved conflicts and run git rerere to remember them. If your checkouts are immense there's ways to avoid that, hunt up minimum-checkout merging.

Then you can

git rerere

to remember the conflict resolutions you've staged. Every time git rerere runs, it hunts through its memory and the indexed snapshot, looking for conflicts and resolutions in each. Anything new it remembers, if it remembers a resolution for any unresolved conflicts it's seen before it applies them.

And then you can abort your merge, rerun it with the new options, and git rerere a third time to have it reuse the recorded resolutions.

If you say git config rerere.enabled true git will automatically do git rerere after any merge stops with a conflict and before committing any merge that had stopped with a conflict. If you say git config rerere.autoupdate true it will also automatically stage those reapplied resolutions for you.

  • Related