Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Git support automatic merge conflict resolution for append-only files?

In our project, we store localized strings in an XML file that is loaded by the application. These files are managed by a localization management tool, we don't edit the files directly.

Now whenever two developers add new localized strings on different branches, they produce merge conflicts. In the majority of the cases, localization strings are just added, so manual merge is trivial: Use one version, and append the new strings from the other version.

Even though this is trivial, it would be nice to automate it. Conceptually, this should be possible as far as I can tell.

So my question is, can I tell Git to use a kind of "concatenate merge" for specific files?

like image 596
theDmi Avatar asked Jan 14 '16 17:01

theDmi


1 Answers

Git does support something called custom merge drivers, where you tell git that in the event of a conflict in merging changes to some file <name.ext>, it should run some outside program with arguments naming the base version, "our" version, and "their" version and let that program do the merge.

This StackOverflow question shows an example of how to run a custom merge driver on a specific file. It also points out an issue that can occur (but I think will not affect your case): the custom driver is only run in the event that git views a merge as "three way" in the first place (i.e., there must be changes in both your own branch, and in the branch you're merging-in).

As for an actual "append only" merge driver, this one on github seems likely to do the job. Note: this is not my code, nor have I looked at the actual code itself, only the description.

like image 143
torek Avatar answered Nov 02 '22 20:11

torek