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.
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.
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).
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...
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.
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.
In my case I have some future development to merge into develop:
- example: some features in mybranch
- mybranch version in pom.xml is: 3.11.0-SNAPSHOT
- mybranch was forked before version 3.10.0-SNAPSHOT
To merge the new features into develop and force the pom.xml from the feature branch:
git checkout develop
develop version in pom.xml is still: 3.10.0-SNAPSHOT
git merge mybranch
all pom.xml are in conflicts + eventually some othe files.
take all the pom (assuming nothing else than version has conflicts)
find -name pom.xml -not -path "**/target*" -exec git co --theirs {} +
I had to resove some others conflicts like e.g. a deleted sub-project in my new branch before running the find command.
After that, all my pom.xml were in new version and compiling without any issue.
来源:https://stackoverflow.com/questions/12197191/git-merge-conflict-only-on-version-tag-in-pom-xml