一尘不染

自动合并2个git分支的脚本?

jenkins

我的git仓库有2个分支:master和development。我想要一个脚本,该脚本可以自动合并从开发到母版的所有更改。

我使用了Jenkins:Git插件会克隆存储库,然后运行以下脚本(“ version”变量是job参数):

# 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 -Xtheirs开发
CONFLICT(删除/修改):在develop中删除test.txt,在HEAD中修改。test.txt的版本HEAD留在树中。
自动合并失败;解决冲突,然后提交结果。

如何 自动 解决此冲突?我希望脚本始终根据’develop’分支添加/修改/删除文件,因为无论如何都不会碰到master …


阅读 541

收藏
2020-07-25

共1个答案

一尘不染

-X theirs合并策略仅适用于文件中解决冲突的帅哥。这些选项的文档中git- merge手册页

      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.

           This should not be confused with the ours merge strategy, which
           does not even look at what the other tree contains at all. It
           discards everything the other tree did, declaring our history
           contains all that happened in it.

       theirs
           This is opposite of ours.

在这种情况下,一个分支删除了文件,而另一个分支修改了文件,这与进行了不同修改的两个分支之间的简单冲突是截然不同的。

2020-07-25