Can rerere automatically resolve this conflict even if the numbers are not the same as the last time? I always want it to resolve it in such a way that it takes the higher number (in example above, 13).
No, git rerere
can't do that.
When you use git rerere
, you're asking it to remember two things:
- a specific conflict (that is, the literal text of the hunks which are in conflict and the files that they're in); and
- the resolution that should be applied to that conflict
Because these are hunk literals (e.g. "replace 12 with 13") rather than some kind of transformation function (e.g. "replace N with N + 1"), git is unable to infer that you want to replace each number with a higher one.
If git later encounters a conflict that doesn't match any of its previously remembered conflicts, it's just as if it's never encountered that conflict at all, even if it might be similar (as in your example where the numbers are always one off).
One way out is possible if this XML file is automatically generated. In that case, you might want to consider not keeping it in source control at all, and instead, generating it at runtime. Then you'll never have the corresponding conflicts to clean up.
Another approach is to avoid git rerere
altogether, and instead write a custom merge driver that will resolve things for you. I've done this before, but it's a non-trivial amount of work, and it requires you to write and test some code. If you're interested in this strategy, see the link in Karl's answer.