How could I force the mergetool GUI to be always shown and disable any automatic resolving?
Sometimes when there is a conflict during a merge and I use the mergetool
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.
I had this question myself (specifically in regard to KDiff3), and PiQuer's answer got 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).
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:
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.
, 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.
Note that the above command replaces the default command for Git's kdiff3
merge tool rather than creating a separate one.
Regarding a couple of other points in the original question:
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.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.