git-rerere is the exact solution to a problem I have ... except that the merges that need to be "learnt" have already been performed and are non-trivial to repeat.
How can I "teach" rerere about those commits with the minimum manual intervention.
Supposing that existing, but conflicting, branches A and B were merged together to form commit C with resolved conflicts.
Then I was hoping to do:
git checkout Agit merge B- merge pauses when conflicts observed.
git reset --soft C- working files are now in the desired final state - i.e. the conflicts were "resolved".
git merge --continuerereresees the updated files as the appropriate resolution, and "learns" this resolution.
But the reset step doesn't work :(
- A
--softreset isn't permitted during a merge. - A
--mixedreset nukesMERGE_HEAD(and I assume generally screws around with the git state, such that the merge cannot be resumed)
EDIT:
Manually "resetting" the files, by checking out C before hand and copying over the relevant files works but is quite slow and tedious due to the large and complex nature of the repositor.
(lots of projects in separate folders, each with their own node_modules/packages folders that will tank the copy time, unless I target specific folders :( )
I'm hoping for something automated. #optimism
In Git 2.36 and later, you can use
git show --remerge-diffto create a diff showing how a merge was resolved. This can be used to do exactly what you want, with a few tricks.First, we recreate the merge conflict, but with predictable conflict markers. Just after the failed
git merge B, you can run:This will recreate the merge conflict, but use
oursandtheirson the merge conflict markers lines. The top pathspec (:/) is used so this works from any directory in your repository.Then we use
git show --remerge-diff, pass its output tosedto also useoursandtheirsas conflict markers, and finally apply this diff:Note that in contrast to rerere, this approach allows you to also reapply any changes that were done in the merge outside of conflict regions.