了解Git Cherry Pick冲突 [英] Understanding Git Cherry Pick conflict

查看:1584
本文介绍了了解Git Cherry Pick冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近从SVN切换到了GIT,在转换以前的工作流程时遇到了一些麻烦.大多数情况下,一切正常,但是今天,我遇到了奇怪的樱桃挑剔冲突.

We recently switched from SVN to GIT, and I'm having some trouble converting our previous workflow. Mostly everything works, but today I got a weird cherry-pick conflict.

我能够解决冲突,但是我想知道这是从哪里来的,因为据我了解,在这种情况下不应有冲突.

I'm able to resolve the conflict, but I would like to know where this came from, because to my understanding there shouldn't be a conflict in this situation.

设置

在我们的存储库中,我们有一个master分支在其上进行开发.我们一年发行四次新版本.我们将master的分支分支到Release-x,并在测试后发货.

In our repository we have a master branch on which we develop. Four times a year we release a new version. We branch of of master into Release-x and this gets shipped after testing.

我们同时生产多个发行版本.如果发现错误,则必须在所有(受支持的)发行分支上修复此错误.因此,使用标签标识不同版本的单个版本分支不是有效的工作流程.

We have several release-versions in production at the same time. If a bug is found, this has to be fixed on all (supported) release branches. So a single release branch using tags to identify the different releases isn't a valid workflow.

因此,我们目前有以下分支:masterRelease-15Q1Release-15Q2Release-15Q3

So we currently have these branches: master, Release-15Q1, Release-15Q2 and Release-15Q3

例如,我们发现一个错字导致master中的错误,我们将对其进行修复,然后将其cherry-pick修复到Release-15Q1Release-15Q2Release-15Q3

Say for example we found a typo causing a bug in master, we would fix it and then cherry-pick it onto Release-15Q1, Release-15Q2 and Release-15Q3

因此,现在我要面对的冲突是:

分支Release-15Q3

Properties.dat (Release-15Q3)

serverip=1.1.1.1
serverport=11
name=MyApp

Properties.dat (master)

serverip=2.2.2.2
serverport=22
name=BetterName

发展继续……一切都很好. 然后我们注意到了一个错误,我们需要在文件中添加一个额外的属性以禁用该错误.

Development went on... all good. Then we noticed a bug where we needed to add an extra property to the file to disable the bug.

Properties.dat (master)

  serverip=2.2.2.2
  serverport=22
  name=BetterName
+ allowBug=false

此修订提交还需要应用于其他三个分支.因此,我转到每个分支并使用cherry-pick命令.

This fix-commit also needs to be applied to the three other branches. So I go to each branch and use the cherry-pick command.

这在前三行给了我冲突,但是我真的不明白为什么.

This is giving me conflicts on the first three lines, but I don't really understand why.

我假设选择樱桃只会重播特定提交,因此只能在正确的位置添加 allowBug = false 行.是否进行了其他更改也没关系,对吧,因为我没有合并分支?

I was under the assumption that with cherry-picking you would only replay that specific commit, so only add the allowBug=false line at the right spot. It shouldn't matter if other changes were made, right?, because I'm not merging the branches?

为什么这会引起冲突?这些其他变化不应该被忽略吗?

Why is this giving a conflict? Shouldn't these other changes be ignored?

推荐答案

在发出cherry-pick时,首先git计算与其父代之间的差异.这将产生一个diff文件(也称为补丁).此修补程序不仅包含已更改的内容(即+ allowBug=false),而且还包含更改后的行的周围环境.因此,修补程序文件看起来像:

When cherry-pick is issued, first git computes the differences with its parent. This results in a diff-file (a.k.a. patch). This patch not only contains what has changed (i.e., + allowBug=false) but also the surrounding context of the changed line(s). Hence, the patch file would look something like:

@@ -1,7 +1,7
serverip=2.2.2.2 
serverport=22  
name=BetterName
+ allowBug=false

一旦计算出补丁,git就会尝试将其应用到您的发行分支中.补丁文件的 context 行(不带+/-的行)告诉git 位置应用+ allowBug=false.由于无法在发行分支的Properties.dat中找到周围的上下文,因此无法应用修补程序,并且git引发冲突.

Once the patch is computed, git will try to apply it into your release branch. The context lines of the patch files (those without +/-) tells git where to apply the + allowBug=false. Since the surrounding context cannot be found in the Properties.dat on release branches, the patch cannot be applied and git raises a conflict.

有点晚了,但希望对您有所帮助:)

A bit late, but hope it helps :)

编辑:您可以看看 查看全文

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