man diff与安装的diff版本不对应

时间:2016-05-30 23:28:34

标签: macos unix man

执行man diff会告诉您:

NAME
       diff - compare files line by line

SYNOPSIS
       diff [OPTION]... FILES

DESCRIPTION
       Compare files line by line.

       -i  --ignore-case
              Ignore case differences in file contents.

[...]
       -q  --brief
              Output only whether files differ.
[...]

但是当我使用-q选项时,它会失败并显示fatal: invalid diff option/value: -q

为什么diff命令的人与安装的版本不对应?

如何解决?

是否有一个brew包,其中包含带有-q选项的diff命令版本? (brew coreutils和binutils没有diff命令)

OSX 10.11.5

更新您的问题

$ which diff
/usr/bin/diff

$ diff --version
usage: git diff --no-index <path> <path>

$ diff -v
usage: git diff --no-index <path> <path>

$ command diff --version
diff (GNU diffutils) 2.8.1

我使用brew和https://github.com/donnemartin/dev-setup

如果我停用dev-setup安装的.bash_profile,那么which diff仍会返回相同的路径,但diff -q有效。

1 个答案:

答案 0 :(得分:1)

你是否有机会使用类似pretzo之类的东西?像这样的一些框架将(严重地)定义它们自己的函数来替换终端默认函数。

在这种情况下,请尝试运行command diff -q ...并查看是否可以解决问题。

修改:正如@MarkPlotnick指出的那样,dev-setup是另一个覆盖默认diff命令并使用git diff代替的框架:

# Use Git’s colored diff when available
hash git &>/dev/null;
if [ $? -eq 0 ]; then
    function diff() {
        git diff --no-index --color-words "$@";
    }
fi;

参考https://github.com/donnemartin/dev-setup/blob/master/.functions