脚本自动合并2个git分支? [英] Script to merge 2 git branches automatically?

查看:1129
本文介绍了脚本自动合并2个git分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我使用Jenkins:Git插件克隆存储库,然后这个脚本('version'变量是

 #合并
git checkout -b开发原点/开发
git checkout master
git merge -Xtheirs --squash develop -mv $ {version}

#commit
git commit -mv $ {version}

#tag
git tag v $ {version} -mv $ {version}

#push
git push origin v $ {version}

我在测试资源库中尝试过它,并且失败:


git合并-X他们开发

CONFLICT(删除/修改):test.txt在HEAD中开发和修改时删除。 test.txt的HEAD版本留在树中。

自动合并失败;修正冲突并提交结果。


如何自动解决冲突 我希望脚本根据'develop'分支总是添加/修改/删除文件,因为master永远不会被触摸...

解决方案

-X theirs 合并策略仅用于解决文件中冲突的区块。这些选项的文档位于 git-merge

 我们
这个选项强制冲突的hunk被自动设置,通过支持我们的版本,很好地解决了
。来自与我方不冲突的其他树
的更改反映为合并
结果。

这不应与我们的合并策略混淆,其中
甚至不会查看其他树包含的内容。它
丢弃了其他树的所有内容,声明我们的历史
包含发生在其中的所有内容。

他们
这与我们的相反。

在这种情况下,一个分支删除了文件,而另一个修改了它,这是一个独特的来自两个分支之间的简单冲突的大块,它们进行了不同的修改。


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...

解决方案

The -X theirs merge strategy only works to resolve conflicting hunks within a file. The documentation for these options is in the git-merge man page:

      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.

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.

这篇关于脚本自动合并2个git分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆