git告诉我,我合并了冲突,但也告诉我没有文件需要合并

问题描述 投票:10回答:3

我在分支new进行了一些更改。

我结帐了master

当我尝试合并时:

$ git merge new
Auto-merging js/site.js
CONFLICT (content): Merge conflict in js/site.js
Automatic merge failed; fix conflicts and then commit the result.

所以我安装了kdiff3并配置了我的配置文件,当我尝试使用mergetools时,我得到了:

$ git mergetool kdiff3
No files need merging

我跑了一个差异,它输出了这个:

diff --cc js/site.js
index 8c17d62,7955b13..0000000
--- a/js/site.js
+++ b/js/site.js
@@@ -72,4 -81,18 +81,22 @@@ function doSmallScreen()

  $(document).ready(function () {
      calculateScreen();
- });
++<<<<<<< HEAD
++});
++=======
+     $(window).resize(function () {
+         delay(function () {
+             calculateScreen();
+         }, 500);
+     });
+ });
+
+
+ var delay = (function () {
+     var timer = 0;
+     return function (callback, ms) {
+         clearTimeout(timer);
+         timer = setTimeout(callback, ms);
+     };
 -})();
++})();
++>>>>>>> new

我很困惑如何解决这个问题,我想以最简单的方式解决这个问题,我真的不在乎我是否丢失了来自分支机构的新信息,但我想知道出了什么问题以及为什么我可以'使用合并工具。

我觉得有一个合并冲突似乎很奇怪但是没有文件需要合并。

git branching-and-merging git-merge kdiff3 mergetool
3个回答
5
投票

我认为你的mergetool命令是错误的。应该

$ git mergetool

要么

$ git mergetool --tool=kdiff3

如果你遇到git命令,你可以随时查看手册(git mergetool --help)。

更多信息:https://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html


9
投票

我试过了

git mergetool .

似乎工作。


6
投票

即使只是运行正确的命令,我也遇到了这个问题:

$ git mergetool

它可能与启用rerere有关(请参阅此链接[编辑:链接不再工作])

我通过在.gitconfig中创建两个别名解决了这个问题,它为每个冲突的文件启动了mergetool:

将其添加到.gitconfig中

# List conflicted files
list-conflicts = !git ls-files -u | cut -f 2 | sort -u

# Force mergetool to recognize conflicts
force-mergetool = !git list-conflicts | xargs git mergetool

tl; dr根据要求,这里有一个简要的解释:

  • git ls-files -u:在合并尝试冲突后,列出所有未合并的文件,以及一些无关的信息和重复;如果在合并后立即运行,这实际上是所有具有冲突的文件
  • | cut -f 2删除了此输出的第二个字段,这实际上是文件路径
  • | sort -u消除了重复
  • | xargs git mergetool将这个文件列表管理到mergetool命令中,该命令启动你的GUI合并工具(假设你有一个设置)

因此,如果您只想查看列出的文件,则可以运行第一个命令。第二个命令会将这些全部输入到您的合并工具中(如果这是您的偏好,您可以使用merge而不是mergetool)。

如果要在添加别名之前自行尝试,可以通过命令行运行以下两个命令之一:

git ls-files -u | cut -f 2 | sort -u

git ls-files -u | cut -f 2 | sort -u | xargs git mergetool

© www.soinside.com 2019 - 2024. All rights reserved.