2

As stated in the title. I tried googling this but found no explanation for it so I looked at the kdiff3 documentation which provided some insight. The situation i'm running into is I do a merge from one branch into another, get a bunch of conflicts and use git mergetool to resolve them one by one. What happens is that for some files when kdiff3 is started, it pops up a dialog that there were x auto resolved conflicts and that there are no conflicts left so i save the file and continue.

According to kdiff3 documentation, conflicts are auto resolved if the line was changed in only one version of the file. Ie. the base is the same as the local or remote file, but not both.

My question is, if my merge tool can auto-resolve this(i've tried a few and they all auto resolve some conflicts) and indeed it seems logical what it does, why do I even get a conflict from git?

A follow up question is: how can I make git auto-resolve these conflicts before i even pop open my merge tool?

An example would be:

base:
line 1
line 2
line 3

local:
line 1
line 2
line 3

remote:
line 1
line abc
line 3

I think the above conflicts in Git but is auto resolved in kdiff3. Though it might be a different case, i've done merges that were auto-resolved before, can't remember the exact scenario since it auto-resolved.

4

1 回答 1

1

可能有很多原因,但很可能是由于合并偏好的不同。

kdiff3 可以配置为忽略的一些差异示例:

  • 空白:一个空行和一个有四个空格的行
  • 评论:/* This is the original comment *//* This is the modified comment */
  • 数字:number_of_diffs = 3number_of_diffs = 7

在每种情况下(可能还有更多),kdiff3 可能只是忽略差异,因此合并没有问题。另一方面,Git 会让你手动解决冲突。

在您的示例中,没有任何(合理的)工具会发出合并冲突的明显原因。但是,如果基础文件是在 Linux 中创建的,而您在 Windows 中编辑了本地文件(反之亦然)怎么办?那么,行尾可能会改变。这可能对您完全不可见,但会导致合并冲突。我刚刚尝试过并得到以下输出:

Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.

然后我跑了:

$ git mergetool
merge tool candidates: meld opendiff kdiff3 tkdiff xxdiff tortoisemerge gvimdiff diffuse ecmerge p4merge araxis bc3 codecompare emerge vimdiff
Merging:
file.txt

Normal merge conflict for 'file.txt':
  {local}: modified file
  {remote}: modified file
Hit return to start merge resolution tool (kdiff3):

点击返回后,kdiff3 默默地合并了两个文件(我什至没有看到它打开),愉快地解决了空白差异。

这可能不是您的情况所发生的确切情况,但它是 Git 未能合并 kdiff3 自动解析的内容的真实示例,仅仅是因为空格。

于 2013-05-22T12:36:13.143 回答