git 如何在 Mac OS 中设置 kdiff3?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33722301/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:31:21  来源:igfitidea点击:

How to setup kdiff3 in Mac OS?

gitgit-diffosx-leopardkdiff3git-difftool

提问by J4cK

In.gitconfigfile I setup up the git diff as follows:

.gitconfig文件中,我按如下方式设置了 git diff:

[diff]
    tool = kdiff3

[difftool "kdiff3"]
    path = path_directory/kdiff3.app

In this setting kdiff is not accessible and I get the following errorwhen I run in terminal

在此设置中 kdiff 不可访问,当我在终端中运行时出现以下错误

>> git difftool
The diff tool kdiff3 is not available as 'Kdiff_local_software_path/kdiff3.app'
fatal: external diff died, stopping at modified_file

Do you have any suggestion I can fix this issue ? In my current setup Mac OS 10.10.5 git diff tool is git merge toolthat I want to replace with kdiff.

你有什么建议我可以解决这个问题吗?在我当前的设置中git merge tool,我想用 kdiff 替换Mac OS 10.10.5 git diff 工具。

采纳答案by hjpotter92

kdiff3is generally located at the following location:

kdiff3一般位于以下位置:

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

so, try

所以,试试

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

If you installed kdiffusing brew, then you'd not need the difftoolparameter in config for git 1.8 onwards. Just the following would work:

如果您kdiff使用安装brew,那么difftool对于 git 1.8 以后的版本,您将不需要config 中的参数。只需以下操作即可:

[diff]
    tool = kdiff3

If you installed kdiffmounting the dmg file to kdiff.appthen set your local path as following:

如果您安装了kdiff挂载 dmg 文件,kdiff.app则将本地路径设置为如下:

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

回答by Qiushi

  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:

  1. 下载 kdiff3 并安装为应用程序(将 kdiff3 拖放到您的应用程序中):http: //sourceforge.net/projects/kdiff3/files/kdiff3/0.9.98/kdiff3-0.9.98-MacOSX-64Bit.dmg/download

  2. 如下设置 git config 工具,在 MacBook Pro 上对我有用:

git config --global merge.tool kdiff3

git config --global merge.tool kdiff3

and:

和:

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

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

回答by YaOzI

  1. First check whether kdiff3is installed and recognized by git:

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

    In cases where kdiff3is not installed in macOS, gitwill 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. 首先检查是否kdiff3安装和识别git

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

    如果kdiff3macOS 中未安装,git还会显示以下消息:

    $ 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, kdiff3should 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. 然后我们应该安装kdiff3,有很多方法可以做到:

    我个人更喜欢MacPort

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

    在此之后,kdiff3应该可用于 macOS 和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
    
  1. 最后,确保正确配置git

    [diff]
        tool = kdiff3
    [difftool]
        prompt = false
    [merge]
        tool = kdiff3
        conflictstyle = diff3
    

回答by Ilker Cat

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

如其他答案中所述,您无需向 gitconfig 添加任何路径。这就是您需要在 .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. 设置使用木桶

    brew tap caskroom/cask
    
  2. 下载 kdiff3,将其移动到您的应用程序目录并将 kdiff3.sh 链接到 /usr/local/bin/kdiff3

    brew cask install kdiff3