svn diff -x(v1.6)不接受我的差异选项--unified = 40。

3
我经常使用这个命令行,在Subversion 1.6.11和GNU diff 2.8.1上效果很好。
svn diff -x '--unified --ignore-space-change --ignore-all-space --ignore-eol-style --show-c-function' --no-diff-deleted my-file | vim -

然而,我想使用 diff 选项 --unified=40 来增加上下文行数,但是我所有的尝试都失败了:

$ svn diff -x '--unified=40' my-file
svn: Error parsing diff options: Missing parameter for the specified command line option

$ svn diff -x '--unified 40' my-file
svn: Invalid argument '40' in diff options

$ svn diff -x '--unified\=40' my-file
svn: Error parsing diff options: Bad character specified on command line

$ svn diff -x '-u 40' my-file
svn: Invalid argument '40' in diff options

$ svn diff -x '-u=40' my-file
svn: Error parsing diff options: Bad character specified on command line

$ svn diff -x '-U' my-file
svn: Error parsing diff options: Bad character specified on command line

我也想使用 diff 选项 --ignore-matching-lines='^[ \t]*#' 忽略注释行中的更改,但是出现了相同的错误。
有没有解决这个 svn diff -x 问题的方法?
2个回答

8
Subversion并不使用GNU diff生成差异。 它有自己的diff实现(请参见链接中的章节的最后一段)。从svn help diff的输出可以看出,内部的diff实现只有很少的选项。
-x [--extensions] ARG    : Specify differencing options for external diff or
                          internal diff or blame. Default: '-u'. Options are
                          separated by spaces. Internal diff and blame take:
                            -u, --unified: Show 3 lines of unified context
                            -b, --ignore-space-change: Ignore changes in
                              amount of white space
                            -w, --ignore-all-space: Ignore all white space
                            --ignore-eol-style: Ignore changes in EOL style
                            -p, --show-c-function: Show C function name
你可能想执行svn diff --diff-cmd=/usr/bin/diff -x '--unified=40' my-file,这样Subversion将选择外部diff,位于/usr/bin/diff(或任何你想要的路径)。
你也可以通过配置文件来配置Subversion始终使用外部diff命令。在Subversion书籍中有一个有关使用外部diff和merge工具的章节

0
你可以编写一个小的 "shell 脚本" 来完成这个任务:
#!/bin/bash
diff --unified=40 <(svn cat "$1") "$1"

嗨,Roch。感谢您的回答。但是,请您在回答中添加一个如何使用提供的shell脚本的示例(并给出一个示例输出)。干杯;-) - oHo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接