How to setup kdiff3 in Mac OS?

只愿长相守 提交于 2019-12-02 19:15:45
hjpotter92

kdiff3 is generally located at the following location:

/Applications/kdiff3.app/Contents/MacOS/kdiff3

so, try

[difftool "kdiff3"]
    path = /Applications/kdiff3.app/Contents/MacOS/kdiff3

If you installed kdiff using brew, then you'd not need the difftool parameter in config for git 1.8 onwards. Just the following would work:

[diff]
    tool = kdiff3

If you installed kdiff mounting the dmg file to kdiff.app then set your local path as following:

[difftool "kdiff3"]
    path = directory_path_where_you_installed/kdiff3.app/Contents/MacOS/kdiff3
  1. Download kdiff3 and install as app(drag and drop the kdiff3 into your Applications): http://sourceforge.net/projects/kdiff3/files/kdiff3/0.9.98/kdiff3-0.9.98-MacOSX-64Bit.dmg/download

  2. Setup git config tool as following, works for me on MacBook Pro:

git config --global merge.tool kdiff3

and:

git config --global mergetool.kdiff3.cmd '/Applications/kdiff3.app/Contents/MacOS/kdiff3 $BASE $LOCAL $REMOTE -o $MERGED'

You don't need to add any paths to your gitconfig as described in the other answers. This is all you need to configure in you .gitconfig

[diff]
    guitool = kdiff3
[merge]
    tool = kdiff3

Assuming you have homebrew installed on your machine:

brew update
brew tap caskroom/cask
brew cask install kdiff3

Explanation:

  1. setup to use cask

    brew tap caskroom/cask
    
  2. downloads kdiff3, moves it to your Applications dir and links kdiff3.sh to /usr/local/bin/kdiff3

    brew cask install kdiff3
    
  1. First check whether kdiff3 is installed and recognized by git:

    $ type -a kdiff3
    -bash: type: kdiff3: not found
    

    In cases where kdiff3 is not installed in macOS, git will also show following messages:

    $ git difftool --tool-help
    $ # OR (both command would do)
    $ git mergetool --tool-help
    'git mergetool --tool=<tool>' may be set to one of the following:
            emerge
            opendiff
            vimdiff
            vimdiff2
            vimdiff3
    
    The following tools are valid, **but not currently available**:
            ...
            gvimdiff3
            kdiff3
            meld
            ...
    
    Some of the tools listed above only work in a windowed
    environment. If run in a terminal-only session, they will fail.
    

  1. Then we should install kdiff3, there are many ways to do it:

    I personally prefer MacPort:

    $ port search kdiff3
    kdiff3 @0.9.98_4 (devel)
        kdiff3 is a file comparing and merging tool.
    $ sudo port install kdiff3
    ...installing process...
    

    After this, kdiff3 should be available to macOS and git

    $ type -a kdiff3
    kdiff3 is /opt/local/bin/kdiff3
    $ git difftool --tool-help
    'git difftool --tool=<tool>' may be set to one of the following:
            emerge
            kdiff3
            opendiff
            ...
    

  1. Finally, make sure the correct configuration for git:

    [diff]
        tool = kdiff3
    [difftool]
        prompt = false
    [merge]
        tool = kdiff3
        conflictstyle = diff3
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!