git 如何强制始终显示合并工具 GUI (KDiff3)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15321472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How could I force mergetool GUI (KDiff3) to be always shown?
提问by Ondrej Peterka
How could I force the mergetool GUI to be always shown and disable any automatic resolving?
如何强制始终显示合并工具 GUI 并禁用任何自动解析?
Sometimes when there is a conflict during a merge and I use the mergetool, it simply immediately returns after I hit Enteron question "Hit return to start merge resolution tool (kdiff3)"and no GUI is shown and the conflict appears to be resolved.
有时,当合并过程中出现冲突并且我使用合并工具时,它会在我遇到Enter问题“点击返回以启动合并解析工具 (kdiff3)”后立即返回,并且没有显示 GUI 并且冲突似乎已解决。
I have Git configured to use KDiff3as the mergetool now, but it happened also when I have codecompare
as the mergetool specified. I know that there is an option "Auto save and quit on merge without conflicts"in KDiff3, which could theoretically cause the described behaviour, but I have this option disabled/unchecked all the time.
我现在已经将 Git 配置为使用KDiff3作为合并工具,但是当我codecompare
指定了合并工具时也会发生这种情况。我知道KDiff3中有一个选项“在没有冲突的情况下自动保存并退出合并”,理论上这可能会导致所描述的行为,但我一直禁用/取消选中此选项。
Also, there is the trustExitCodeoption directly in Git mergetool gitconfig, which I have set to true, but even if I set it to false, the GUI is not shown.
此外,在 Git mergetool gitconfig 中直接有trustExitCode选项,我已将其设置为 true,但即使将其设置为 false,也不会显示 GUI。
I am not sure who does the auto resolving anyway. Mergetool in some preprocessing or KDiff3?
我不确定谁会自动解决。在一些预处理或 KDiff3 中合并工具?
I am running on Windows and have the Git-extensions installed.
我在 Windows 上运行并安装了 Git 扩展。
Similar question specific to KDiff3, was asked also here: Kdiff3 won't open with mergetool command
特定于 KDiff3 的类似问题,也在这里被问到:Kdiff3 不会用 mergetool 命令打开
回答by PiQuer
Git has --auto
hard coded as a command-line option to KDiff3, which causes the GUI not to show up if all conflicts are auto-resolvable by KDiff3. In the KDiff3 settings you can specify command line options to ignore, but putting --auto
there did not work for me.
Git 已--auto
硬编码为 KDiff3 的命令行选项,如果 KDiff3 可自动解决所有冲突,则会导致 GUI 不显示。在 KDiff3 设置中,您可以指定要忽略的命令行选项,但放在--auto
那里对我不起作用。
As a workaround I configured my own variant of KDiff3 as the merge tool:
作为一种解决方法,我将自己的 KDiff3 变体配置为合并工具:
git config --global mergetool.kdiff3NoAuto.cmd "kdiff3 --L1 \"$MERGED (Base)\" --L2 \"$MERGED (Local)\" --L3 \"$MERGED (Remote)\" -o \"$MERGED\" \"$BASE\" \"$LOCAL\" \"$REMOTE\""
This is very similar to what Git uses by default for KDiff3, but without the --auto
flag.
这与 Git 默认使用的 KDiff3 非常相似,但没有--auto
标志。
Now you can call git mergetool -t kdiff3NoAuto
or configure kdiff3NoAuto
as mergetool globally and KDiff3 will always show up when resolving conflicts.
现在您可以全局调用git mergetool -t kdiff3NoAuto
或配置kdiff3NoAuto
为合并工具,并且在解决冲突时 KDiff3 将始终显示。
Regarding the second part of your question, if you really want to disable any automatic resolving, just add --qall
to the kdiff3
command line above. But then you have to manually resolve all changes in the file manually, even the ones that did not result in a Git conflict. The best scenario would be: KDiff3 shows how Git merged the files and leaves the conflicts open for the user to choose.
关于您问题的第二部分,如果您真的想禁用任何自动解析,只需添加--qall
到kdiff3
上面的命令行即可。但是随后您必须手动解决文件中的所有更改,即使是那些没有导致 Git 冲突的更改。最好的情况是:KDiff3 展示了 Git 如何合并文件并让用户选择冲突。
回答by jamezzz
Bob esponja's comment to the accepted answer worked perfectly for me using KDiff3 0.9.98.
Bob esponja 对已接受答案的评论对我使用 KDiff3 0.9.98 非常有效。
Add --auto
to Command line options to ignore:under
添加--auto
到命令行选项以忽略:下
Settings | Configure KDiff3... | Integration tab.
KDiff3 comes up with the Conflicts dialog indicating Nr of unsolved conflicts: 0, but then you have can inspect/modify the merged state as needed.
KDiff3 出现了 Conflicts 对话框,指示未解决冲突的 Nr: 0,但是您可以根据需要检查/修改合并状态。
A bit more convenient than configuring your own variant as it will work as intended whether from git mergetool, Source Tree or whatever tool engages mergetool.
比配置您自己的变体更方便一点,因为无论是来自 git mergetool、Source Tree 还是任何使用 mergetool 的工具,它都可以按预期工作。
回答by Joel Davies
The behavior of git mergetool
is entirely dependent on the merge tool chosen and the command line Git passes to it. Therefore, to change its behavior, you need to find a command line that does what you want and configure Git to use that command line.
的行为git mergetool
完全取决于选择的合并工具和 Git 传递给它的命令行。因此,要更改其行为,您需要找到一个可以执行所需操作的命令行,并将 Git 配置为使用该命令行。
I had this question myself (specifically in regard to KDiff3), and PiQuer's answergot me part of the way, but it got me to thinking. There ought to be a way to replicate Git's default behavior exactly for KDiff3 except without the --auto
option (which is what causes KDiff3 not to display the GUI).
我自己也有这个问题(特别是关于 KDiff3),而PiQuer 的回答让我得到了一部分,但它让我开始思考。应该有一种方法可以完全为 KDiff3 复制 Git 的默认行为,除非没有--auto
选项(这就是导致 KDiff3 不显示 GUI 的原因)。
It looks like the source for the default command for the KDiff3 merge tool is in the file git/mergetools/kdiff3. That looks like a shell script, so we ought to be able to copy it exactly! Putting that on one line, removing --auto
, and escaping things gives us this:
看起来 KDiff3 合并工具的默认命令的源代码在文件git/mergetools/kdiff3 中。这看起来像一个shell脚本,所以我们应该能够准确地复制它!把它放在一行,删除--auto
和转义的东西给了我们这个:
git config --global mergetool.kdiff3.cmd "if \"$base_present\"; then \"$merge_tool_path\" --L1 \"$MERGED (Base)\" --L2 \"$MERGED (Local)\" --L3 \"$MERGED (Remote)\" -o \"$MERGED\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1; else \"$merge_tool_path\" --L1 \"$MERGED (Local)\" --L2 \"$MERGED (Remote)\" -o \"$MERGED\" \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1; fi"
The base_present
and merge_tool_path
variables are not specifically mentioned in the Git documentation as being available to use in mergetool.<tool>.cmd
, so it is possible at some point in the future that this command may not work as-is. However, they could easily be replaced with a command to test whether BASE
refers to a file that exists, and a hard-coded path for KDiff3, respectively.
在base_present
和merge_tool_path
变量没有具体Git的文档为可用在使用中提到mergetool.<tool>.cmd
,所以有可能在某个时刻,在未来的命令可能无法工作原样。但是,它们可以很容易地替换为测试是否BASE
引用存在的文件的命令,以及 KDiff3 的硬编码路径。
Note that the above command replaces the default command for Git's kdiff3
merge tool rather than creating a separate one.
请注意,上述命令替换了 Gitkdiff3
合并工具的默认命令,而不是创建一个单独的命令。
Regarding a couple of other points in the original question:
关于原始问题中的其他几点:
- The
trustExitCode
setting tells Git whether the exit code of the merge tool is a proper indication of whether the merge was successful. It will not affect the behavior of the merge tool but rather the behavior of Git once the merge tool has exited. See the manual for git-mergetool. - The automatic resolution you are seeing after typing
git mergetool
is all done by the merge tool itself.git mergetool
merely invokes the external tool on the file versions that need to be merged.
- 该
trustExitCode
设置告诉 Git 合并工具的退出代码是否是合并是否成功的正确指示。它不会影响合并工具的行为,而是会影响合并工具退出后 Git 的行为。请参阅git-mergetool 手册。 - 您在输入后看到的自动分辨率都是
git mergetool
由合并工具本身完成的。git mergetool
仅对需要合并的文件版本调用外部工具。
回答by Patrizio Bertoni
If the problem strictly relates to unwanted conflict auto-resolution...
如果问题严格涉及不需要的冲突自动解决...
Once KDiff3 has opened, you could just press a Merge / Set Deltas to Conflicts
from the menu, and the state gets updated to a beautiful, man-driven conflict resolution problem.
一旦 KDiff3 打开,您只需按Merge / Set Deltas to Conflicts
菜单中的 a,状态就会更新为一个漂亮的、人为驱动的冲突解决问题。
回答by sophana
Instead of configuring mergetool which is called only when there is a conflict, simply set up a merge driver with KDiff3:
无需配置仅在发生冲突时调用的 mergetool,只需使用 KDiff3 设置合并驱动程序:
git config merge.kdiff.driver 'kdiff3 "%O" "%A" "%B" -o "%A" --L1 "Nearest Common ancestor" -L2 "Working Copy" --L3 "Version from Other Branch"'
You can make this driver global by adding --global
.
But you need to add a .gitattribute in your repository:
您可以通过添加--global
. 但是你需要在你的存储库中添加一个 .gitattribute:
* merge=kdiff