2

I'm trying to script merging branches with pom.xml files that usually only conflict with changes in the version number but often have other non-conflicting changes in them. If I use "git checkout --ours" even non-conflicting changes are skipped is there a workaround for this?

Example of what I mean:

<xml>
   <thing>
<<<<<<< HEAD
        <version>1.1.0</version>
=======
        <version>1.2.0</version>
>>>>>>> origin/remote_branch
    </thing>
    <other>
      <!-- merged changes -->
    </other>
</xml>

I want to achieve with something like "git checkout --ours"

<xml>
   <thing>
        <version>1.1.0</version>
    </thing>
    <other>
      <!-- merged changes -->
    </other>
</xml>

Is that possible?

Ivan Wills
  • 134
  • 8

1 Answers1

4

That should be done with a merge strategy option: git merge branch -X ours:

ours:

This option forces conflicting hunks to be auto-resolved cleanly by favoring our version. Changes from the other tree that do not conflict with our side are reflected to the merge result.
For a binary file, the entire contents are taken from our side.

This is an option to the recursive merge strategy.

If you want to apply that option only to certain files, while keeping the default merge resolution for the other files, you can use a custom merge driver in order to call git merge-file --ours on those specific files. You declare it in the config file.

That merge driver is associated to files in a .gitattributes:

pom.xml merge=keepours
Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755