Git merge conflict only on version tag in pom.xml

14,369

Solution 1

What I always do is change the version of the modules using the maven versions plugin, before merging from another branch (with a different version):

mvn versions:set -DnewVersion=1.1 -DgenerateBackupPoms=false

That'll change the version of all the current modules (parent and children) to the one you specify as the newVersion parameter. After changing the version, make a new commit (git commit...) and then do the merge. I've got all of this automated using a Jenkins task, but it shouldn't be difficult to implement it in other ways (e.g. sh script).

Solution 2

You probably have a few options. None of which are perfect :-/

1) you can use 'git merge -s ours', but you should only do that when you know you don't need the rest of the changes too.

2) You can also use git rerere, which helps resolve conflicts by memorizing what you did last time. You can enable its usage globally so it always "just works" by setting rerere.enabled. Or you can read the man page and do it by hand as well.

Solution 3

You could also use a custom merge driver, as in pom-merge-driver. Depending on your workflow you might want to merge pom as a normal file, except treating the project version differently: always take the merging branch version, or make an exception when merging to the develop branch...

Solution 4

I had the same problem and all solutions that i found didn't do it, imo, correct. Finally i wrote a merge driver which only takes care of the project/parent version and only them. No dependency version is changed nor the format of the xml file.

I released it a few minutes ago @ https://github.com/cecom/pomutils. If you have any questions, let me know.

Solution 5

Take a look at resolve-maven-version-conflicts.pl. It's a mergetool specifically to resolve pom conflicts. It'll ignore any change where both sides are -SNAPSHOT versions, but leave any other conflicts for further resolution.

Share:
14,369
Abidi
Author by

Abidi

Updated on June 22, 2022

Comments

  • Abidi
    Abidi about 2 years

    Is there a way to avoid merge conflicts in version tag in pom.xml when merging master into a branch? I have quite a few pom files, 80, and all of them have same version which is different from one in master. It's laborious and time-consuming to execute git mergetool for 80 pom files just for a version tag.

  • Wes Hardaker
    Wes Hardaker almost 12 years
    rerere rocks. In fact, it rocks so much you frequently forget you're using it.
  • Sven Oppermann
    Sven Oppermann over 9 years
    The tool got now some more improvements. Now you can also auto resolve property values and it is possible to write your own conflict resolution rule. Have a look :-)
  • DarVar
    DarVar over 7 years
    Option 2) won't work if the version changes in anyway since git rerere recorded the merge conflict resolution. So not really an option IMO.