自动合并2个git分支的脚本?
我的 git 存储库有 2 个分支:master 和development。我想要一个能够自动合并从开发到主控的所有更改的脚本。
我使用 Jenkins:Git 插件克隆存储库,然后运行此脚本(“版本”变量是作业参数):
# merge
git checkout -b develop origin/develop
git checkout master
git merge -Xtheirs --squash develop -m "v${version}"
# commit
git commit -m "v${version}"
# tag
git tag v${version} -m "v${version}"
# push
git push origin v${version}
我在测试存储库上尝试了它,但失败了:
git merge -X他们的开发
冲突(删除/修改):在develop中删除test.txt并在HEAD中修改。 test.txt 的版本 HEAD 留在树中。
自动合并失败;修复冲突,然后提交结果。
如何自动解决此冲突?我希望脚本始终根据“开发”分支添加/修改/删除文件,因为无论如何都不会触及 master 。 。
My git repository has 2 branches: master and develop. I want a script that merges all changes from develop to master automatically.
I used Jenkins: The Git plugin clones the repository and then this script (the 'version' variable is a job parameter) is run:
# merge
git checkout -b develop origin/develop
git checkout master
git merge -Xtheirs --squash develop -m "v${version}"
# commit
git commit -m "v${version}"
# tag
git tag v${version} -m "v${version}"
# push
git push origin v${version}
I tried it on a test repository and it fails with:
git merge -Xtheirs develop
CONFLICT (delete/modify): test.txt deleted in develop and modified in HEAD. Version HEAD of test.txt left in tree.
Automatic merge failed; fix conflicts and then commit the result.
How do I resolve this conflict automatically? I want the script to always add/modify/delete files according to the 'develop' branch, since master is never touched anyway...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
-X thoses
合并策略仅适用于解决文件中存在冲突的块。这些选项的文档位于git-merge
手册中page:在这种情况下,一个分支删除了该文件,而另一个分支修改了该文件,这与进行不同修改的两个分支之间的简单冲突块是不同的情况。
The
-X theirs
merge strategy only works to resolve conflicting hunks within a file. The documentation for these options is in thegit-merge
man page:In this case, one branch has deleted the file while the other has modified it, which is a distinct case from a simple conflicting hunk between two branches that have made different modifications.
5 岁了……但仍然相关。
这是我的解决方案:
我删除主分支并从我想要“合并”的分支创建一个新的主分支:
5 years old.... But still relevant.
Here's my solution:
I delete the master branch and create a new master branch from the branch I want to 'merge' from: