在 diff 输出中显示行内的差异

发布于 2024-08-03 17:24:18 字数 230 浏览 2 评论 0原文

此 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

泛泛之交 2024-08-10 17:24:18

我不知道这是否足以满足您的目的,但是 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.

方圜几里 2024-08-10 17:24:18

我尝试了我找到的所有工具:wdiff、dwdiff、kdiff3、vimdiff 来显示两条长且略有不同的行之间的差异。我最喜欢的是 diff-highlight (git contrib 的一部分),

  • 它支持 diff 格式 - 比需要两个文件(如 (dwdiff))的工具有很大优势,例如,如果您需要可视化单元测试的输出,
  • 它会突出显示黑色+白色或彩色,如果你将它连接到 colordiff
  • 按字符突出显示 - 有助于比较没有空格的长行(比 wdiff 更好)

安装

在 Ubuntu 上,你可能已经将它作为 git contrib 的一部分(安装在 git< /code> deb 包)。
将其从 /usr/share/doc/git/contrib/diff-highlight/diff-highlight 复制或链接到 ~/bin 文件夹中

用法示例

cat tmp.diff | diff-highlight | colordiff

结果:

在此处输入图像描述

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)

  • it supports diff format - great advantage over tools requiring two files like (dwdiff), e.g. if you need to visualize the output of unit tests
  • it highlights with black+white or with color if you connect it to colordiff
  • highlights characterwise - helpful for comparing long lines without spaces (better than wdiff)

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

cat tmp.diff | diff-highlight | colordiff

Result:

enter image description here

喜爱纠缠 2024-08-10 17:24:18

查看所有字大小差异的另一种直观方法(尽管不是并排)是将 wdiffcolordiff 一起使用(您可能需要安装两者)。一个例子是:

wdiff -n {file-A} {file-A} | colordiff

您可以选择将其传递到 less -R 中以滚动浏览输出(-R 用于显示 less< 中的颜色) /代码>)。

Another intuitive way to see all word-sized differences (though not side-by-side) is to use wdiff together with colordiff (you might need to install both). An example of this would be:

wdiff -n {file-A} {file-A} | colordiff

You can optionally pipe this into less -R to scroll through the output (-R is used to show the colors in less).

聽兲甴掵 2024-08-10 17:24:18

ccdiff 是执行该任务的便捷专用工具。下面是一个示例:

ccdiff 示例输出

默认情况下,它突出显示颜色差异,但它也可以在不支持颜色的控制台上使用。

该软件包包含在 Debian 的主存储库中:

ccdiff 是一种彩色差异,它也在更改的行内着色。

所有显示两个文件之间差异的命令行工具都无法显示明显有用的微小更改。 ccdiff 尝试提供 diff --colorcolordiff 的外观和感觉,但将彩色输出的显示从已删除和已添加的彩色行扩展到已删除和已添加字符的颜色在更改的行内。

ccdiff is a convenient dedicated tool for the task. Here is what an example may look like with it:

ccdiff example output

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:

ccdiff is a colored diff that also colors inside changed lines.

All command-line tools that show the difference between two files fall short in showing minor changes visuably useful. ccdiff tries to give the look and feel of diff --color or colordiff, but extending the display of colored output from colored deleted and added lines to colors for deleted and addedd characters within the changed lines.

檐上三寸雪 2024-08-10 17:24:18

我遇到了类似的问题,并且想避免使用 vimdiff。我发现 dwdiff (在 Debian 中可用)有几个优点通过wdiff

dwdiff 最有用的功能是您可以使用 -d [CHARS] 自定义分隔符,因此它对于比较各种输出非常有用。它还具有使用 -c 标志内置的颜色。

I had a similar problem and wanted to avoid using vimdiff. I found dwdiff (which is available in Debian) to have several advantages over wdiff.

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.

太阳男子 2024-08-10 17:24:18

您可以使用 colordiff 来实现此目的。

在他们的手册页中:

传递给 colordiff 的任何选项都是
传递到 diff 除了
colordiff 特定选项 'difftype',
例如

colordiff --difftype=debdiff file1
文件2

“difftype”的有效值为:diff,
diffc、diffu、diffy、wdiff、debdiff;
这些对应于简单的差异,
上下文差异、统一差异、
并排差异、wdiff 输出和
分别输出 debdiff。使用这些
当 colordiff 无法使用时覆盖
确定 diff 类型
自动。

我还没有测试过它,但并排输出(由 diff -y file1 file2 生成)可能会为您提供相当于内联差异的结果。

You might be able to use colordiff for this.

In their man page:

Any options passed to colordiff are
passed through to diff except for the
colordiff-specific option 'difftype',
e.g.

colordiff --difftype=debdiff file1
file2

Valid values for 'difftype' are: diff,
diffc, diffu, diffy, wdiff, debdiff;
these correspond to plain diffs,
context diffs, unified diffs,
side-by-side diffs, wdiff output and
debdiff output respectively. Use these
overrides when colordiff is not able
to determine the diff-type
automatically.

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.

从来不烧饼 2024-08-10 17:24:18

icdiff 是另一种选择。它可以独立使用,也可以作为 Git 命令 (git icdiff)。

示例

icdiff is another option. It can be used standalone, or as a Git command (git icdiff).

Example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文