看起来-u
可以采取额外的数字参数,但我不安静地得到手册,
它说,
-u, -U NUM, --unified[=NUM]
output NUM (default 3) lines of unified context
有人请举个例子吗?
我找不到一个可以工作的。
答案1
-u 本身输出结果“统一”格式该数字仅更改作为上下文包含的相邻行的数量。
答案2
直接来自维基百科文章diff
:
统一上下文差异最初由 Wayne Davison 于 1990 年 8 月开发(unidiff 出现在 comp.sources.misc 第 14 卷中)。一个月后,Richard Stallman 在 GNU 项目的 diff 实用程序中添加了统一 diff 支持,该功能在 1991 年 1 月发布的 GNU diff 1.15 中首次亮相。GNU diff 自此推广了上下文格式,以允许对 diff 进行任意格式设置。
该格式以与上下文格式相同的两行标题开头,只不过原始文件前面带有“---”,新文件前面带有“+++”。接下来是一个或多个包含文件中行差异的更改块。未更改的上下文行前面有一个空格字符,添加行前面有一个加号,删除行前面有一个减号。
块以范围信息开始,紧随其后的是行添加、行删除和任意数量的上下文行。范围信息由双 at 符号包围,并将上下文格式中出现的两行内容合并到一行中(见上图)。范围信息行的格式如下:
@@ -l,s +l,s @@ optional section heading
然后在整个文件中需要进行更改的地方,您将看到如下行:
-check this dokument. On
+check this document. On
笔记:A-
表示正在删除,a+
表示正在添加。
该命令diff -U
还可以采用一个附加参数(一个数字),表示两个文件之间出现差异的点周围有多少行相邻文本。这有助于更好地了解差异的实际含义。
例子
文件1
$ cat file1.txt
The Rain in Spain by
Servants Poor Professor Higgins!
Poor Professor Higgins! Night and day
He slaves away! Oh, poor Professor Higgins!
All day long On his feet; Up and down until he's numb;
Doesn't rest; Doesn't eat;
文件2
$ cat file2.txt
The Rain in Spain by
added extra line here
Servants Poor Professor Higgins!
Poor Professor Higgins! Night and day
He slaves away! Oh, poor Professor Higgins!
All day long On his feat; Up and down untile he's numb;
Doesn't rest; Doesn't eat;
差异
$ diff -U 2 file1.txt file2.txt
--- file1.txt 2013-04-26 09:39:13.496835363 -0400
+++ file2.txt 2013-04-26 09:38:04.838299195 -0400
@@ -1,6 +1,7 @@
The Rain in Spain by
+added extra line here
Servants Poor Professor Higgins!
Poor Professor Higgins! Night and day
He slaves away! Oh, poor Professor Higgins!
-All day long On his feet; Up and down until he's numb;
+All day long On his feat; Up and down untile he's numb;
Doesn't rest; Doesn't eat;
看维基百科上的差异更多细节。