62

I have Git on mac OSX Snow Leopard and I tried to edit my merge and diff tool to use kdiff3 instead of emerge.

But when I try to use it does not launch the GUI of kdiff and keeps me with a cmd based interface.

My setting in gitconfig are:

[merge]
     tool = kdiff3
[mergetool "kdiff3"]
    cmd = /Applications/kdiff3.app/Contents/MacOS/kdiff3
    args = $base $local $other -o $output
    trustExitCode = false
[diff]
tool = kdiff3
[difftool "kdiff3"]
cmd = /Applications/kdiff3.app/Contents/MacOS/kdiff3
args = $base $local $other -o $output
trustExitCode = false

There is obviously something missing but what did I do wrong ?

kenorb
  • 118,428
  • 63
  • 588
  • 624
AKFourSeven
  • 1,205
  • 3
  • 18
  • 27

2 Answers2

153

Recent Git versions have built-in support for kdiff3, so there's no need to configure it manually using the generic cmd and args settings. Instead do:

$ git config --global merge.tool kdiff3

And if kdiff3 is not in your PATH environment also do:

$ git config --global mergetool.kdiff3.path /Applications/kdiff3.app/Contents/MacOS/kdiff3

This makes git mergetool launch kdiff3. Note that there is no way to configure Git to automatically launch your merge tool after a manual merge that has conflicts.

In case you really want to see how Git is calling kdiff3 internally, take a look at the built-in mergetool configuration for kdiff3.

Edit: For Beyond Compare 4, which now also supports Mac OS X, simply exchange kdiff3 with bc3 (yes, "3") and adjust the path in the above lines. Starting with Git 2.2.0 you'll be able to use bc as an alias for bc3 so that you do not have to care about the version number.

Community
  • 1
  • 1
sschuberth
  • 23,652
  • 5
  • 80
  • 125
  • 7
    I still had to install kdiff3. If you have homebrew, it's as easy as `brew install kdiff3`. That should be enough to put kdiff3 in the path. – Johnny Oshika Mar 17 '15 at 17:28
  • 2
    git config --global diff.tool kdiff3 – mikelong May 18 '15 at 10:30
  • 1
    @mikelong If `diff.tool` is not configured it falls back to `merge.tool`, so just configuring the latter is enough. – sschuberth May 18 '15 at 10:44
  • @sschuberth I'm having the same problem with Meld for mac, does your solution also work for that? Seems like editting gitignore based on Meld for Mac instructions doesn't do the trick – Saba Ahang Feb 15 '17 at 20:22
  • 1
    @SabaAhang My instructions work for any diff / merge tool that is directly supported by Git, and that includes `meld`. The list of supported tools can be seen from the [source code](https://github.com/git/git/tree/master/mergetools), or by running `git mergetool --tool-help`. – sschuberth Feb 16 '17 at 10:01
  • If you are trying to install from homebrew, kdiff3 has been moved to cask. To install it now you'll need to `brew tap caskroom/cask` and then `brew cask install kdiff3` – rsennewald Oct 20 '17 at 21:41
  • Did everything as written still opens terminal as `mergetool`. – Farid Oct 05 '18 at 03:56
1

Recent Git versions have built-in support for kdiff3

Yes, but only Git 2.12 (Q1 2017) will allow those built-in tools to trust their exit code.

See commit 2967284, commit 7c10605 (29 Nov 2016) by David Aguilar (davvid).
(Merged by Junio C Hamano -- gitster -- in commit c4a44e2, 16 Dec 2016)

mergetool: honor mergetool.$tool.trustExitCode for built-in tools

Built-in merge tools contain a hard-coded assumption about whether or not a tool's exit code can be trusted to determine the success or failure of a merge.
Tools whose exit codes are not trusted contain calls to check_unchanged() in their merge_cmd() functions.

A problem with this is that the trustExitCode configuration is not honored for built-in tools.

Teach built-in tools to honor the trustExitCode configuration.

(See kdiff3)

Extend run_merge_cmd() so that it is responsible for calling check_unchanged() when a tool's exit code cannot be trusted.
Remove check_unchanged() calls from scriptlets since they are no longer responsible for calling it.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283