Ok, here goes my Q. Does "git rerere" compare hashes of two files to figure out the resolution? That is, say I have an XML file which contains this tag:
<number>12</number>
When I have a conflict, that number usually gets changed to something like 13, 14, etc, so I'm stuck with:
<<<<<<<
<number>12</number>
=======
<number>13</number>
>>>>>>>
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). So if it records the resolution for numbers 12 and 13, will it resolve conflict with different numbers? I have a suspicion it won't, but might as well ask.
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:
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.
Vanilla git doesn't compare files that way. It does a strict string comparison and doesn't know anything about the semantics of it.
However, take a look at "Defining a custom merge driver" in the gitattributes man page. It lets you write your own program to resolve certain merges any way you want, including choosing the higher number.
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