Git 合并冲突仅在 pom.xml 中的版本标记上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12197191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git merge conflict only on version tag in pom.xml
提问by Abidi
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.
pom.xml
将 master 合并到分支时,有没有办法避免版本标记中的合并冲突?我有很多 pom 文件,80 个,并且它们的版本都相同,与 master 中的版本不同。git mergetool
只为一个版本标签执行80 个 pom 文件既费力又费时。
回答by Wes Hardaker
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.
1) 您可以使用“git merge -s ours”,但只有在您知道不需要其余更改时才应该这样做。
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.
2) 你也可以使用 git rerere,它通过记住你上次所做的事情来帮助解决冲突。您可以通过设置 rerere.enabled 全局启用它的使用,以便它始终“正常工作”。或者您也可以阅读手册页并手动完成。
回答by emerino
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):
在从另一个分支(具有不同版本)合并之前,我总是使用maven 版本插件更改模块的版本:
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).
这会将所有当前模块(父和子)的版本更改为您指定为 newVersion 参数的版本。更改版本后,进行新的提交(git commit...),然后进行合并。我已经使用 Jenkins 任务自动完成了所有这些,但是以其他方式(例如 sh 脚本)实现它应该不难。
回答by A.M.
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...
您还可以使用自定义合并驱动程序,如pom-merge-driver。根据您的工作流程,您可能希望将 pom 合并为一个普通文件,但对项目版本的处理方式不同:始终采用合并分支版本,或者在合并到开发分支时例外...
回答by Sven Oppermann
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.
我遇到了同样的问题,我发现的所有解决方案都没有做到,imo,正确。最后,我编写了一个合并驱动程序,它只处理项目/父版本和它们。没有更改依赖项版本,也没有更改 xml 文件的格式。
I released it a few minutes ago @ https://github.com/cecom/pomutils. If you have any questions, let me know.
我在几分钟前发布了它@ https://github.com/cecom/pomutils。如果您有任何问题,请告诉我。
回答by Joe
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.
看看resolve-maven-version-conflicts.pl
。它是一个专门用于解决 pom 冲突的合并工具。它将忽略双方都是-SNAPSHOT
版本的任何更改,但留下任何其他冲突以供进一步解决。
回答by рüффп
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 beforeversion 3.10.0-SNAPSHOT
- 示例:mybranch 中的一些功能
- pom.xml 中的 mybranch 版本是:3.11.0-SNAPSHOT
- mybranch在3.10.0-SNAPSHOT 版本之前分叉
To merge the new features into develop and force the pom.xml from the feature branch:
将新功能合并到 develop 并从功能分支强制 pom.xml:
git checkout develop
develop version in pom.xml is still: 3.10.0-SNAPSHOT
git merge mybranch
pom.xml 中的开发版本仍然是:3.10.0-SNAPSHOT
git 合并 mybranch
all pom.xml are in conflicts + eventually some othe files.
所有 pom.xml 都存在冲突 + 最终还有一些其他文件。
take all the pom (assuming nothing else than version has conflicts)
拿走所有的 pom(假设除了版本没有冲突)
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.
在运行 find 命令之前,我必须解决一些其他冲突,例如在我的新分支中删除的子项目。
After that, all my pom.xml were in new version and compiling without any issue.
在那之后,我所有的 pom.xml 都是新版本并且编译没有任何问题。