在 diff 输出中显示行内的差异
此 StackOverflow 答案 包含 KDiff3 的图像突出生产线内的差异。有人知道可以在命令行上显示相同内容(例如,通过颜色)的工具吗?
另一种思考方式是希望区分补丁文件中的每个差异。
This StackOverflow answer has an image of KDiff3 highlighting intra-line differences. Does someone know of a tool which can show the same (ex, via color) on the command line?
Another way to think of this is wanting to diff each difference in a patch file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我不知道这是否足以满足您的目的,但是 vimdiff 可以这个(甚至有颜色)。例如,请参阅此 相关问题。
I don't know if this is sufficiently command line for your purpose, but vimdiff can do this (even does colour). See for example the image in this related question.
我尝试了我找到的所有工具:wdiff、dwdiff、kdiff3、vimdiff 来显示两条长且略有不同的行之间的差异。我最喜欢的是
diff-highlight
(git contrib 的一部分),安装
在 Ubuntu 上,你可能已经将它作为 git contrib 的一部分(安装在
git< /code> deb 包)。
将其从
/usr/share/doc/git/contrib/diff-highlight/diff-highlight
复制或链接到 ~/bin 文件夹中用法示例
结果:
I tried all the tools I found: wdiff, dwdiff, kdiff3, vimdiff to show the difference between two long and slightly different lines. My favourite is
diff-highlight
(part of git contrib)Installation
On Ubuntu, you probably already have it as part of git contrib (installed within the
git
deb package).Copy or link it into your ~/bin folder from
/usr/share/doc/git/contrib/diff-highlight/diff-highlight
Usage example
Result:
查看所有字大小差异的另一种直观方法(尽管不是并排)是将
wdiff
与colordiff
一起使用(您可能需要安装两者)。一个例子是:您可以选择将其传递到
less -R
中以滚动浏览输出(-R
用于显示less< 中的颜色) /代码>)。
Another intuitive way to see all word-sized differences (though not side-by-side) is to use
wdiff
together withcolordiff
(you might need to install both). An example of this would be:You can optionally pipe this into
less -R
to scroll through the output (-R
is used to show the colors inless
).ccdiff
是执行该任务的便捷专用工具。下面是一个示例:默认情况下,它突出显示颜色差异,但它也可以在不支持颜色的控制台上使用。
该软件包包含在 Debian 的主存储库中:
ccdiff
is a convenient dedicated tool for the task. Here is what an example may look like with it:By default, it highlights the differences in color, but it can be used on a console without color support too.
The package is included in the main repository of Debian:
我遇到了类似的问题,并且想避免使用 vimdiff。我发现
dwdiff
(在 Debian 中可用)有几个优点通过wdiff
。dwdiff
最有用的功能是您可以使用-d [CHARS]
自定义分隔符,因此它对于比较各种输出非常有用。它还具有使用-c
标志内置的颜色。I had a similar problem and wanted to avoid using
vimdiff
. I founddwdiff
(which is available in Debian) to have several advantages overwdiff
.The most useful feature of
dwdiff
is that you can customise the delimiters with-d [CHARS]
, so it's useful for comparing all kinds of output. It also has color built in with the-c
flag.您可以使用
colordiff
来实现此目的。在他们的手册页中:
我还没有测试过它,但并排输出(由
diff -y file1 file2
生成)可能会为您提供相当于内联差异的结果。You might be able to use
colordiff
for this.In their man page:
I haven't tested it, but the side-by-side output (as produced by
diff -y file1 file2
) might give you the equivalent of in-line differences.icdiff 是另一种选择。它可以独立使用,也可以作为 Git 命令 (
git icdiff
)。示例
icdiff is another option. It can be used standalone, or as a Git command (
git icdiff
).Example