如何显示正在比较的文件的名称?

Iai*_*der 6 diff

我曾经diff --from-file将我的 Riak dev1 配置与其他三个配置进行比较。

diff --from-file ~/riak/dev/dev1/etc/app.config \
~/riak/dev/dev2/etc/app.config \
~/riak/dev/dev3/etc/app.config \
~/riak/dev/dev4/etc/app.config
Run Code Online (Sandbox Code Playgroud)

它显示配置仅在端口号设置(8091、8092、8093、8094)上有所不同。

很难判断一个文件在哪里结束,下一个文件从哪里开始,因为输出不包含文件名。

11c11
<               {http, [ {"127.0.0.1", 8091 } ]},
---
>               {http, [ {"127.0.0.1", 8092 } ]},
15c15
<               %{https, [{ "127.0.0.1", 8091 }]},
---
>               %{https, [{ "127.0.0.1", 8092 }]},
26c26
<               {handoff_port, 8101 },
---
>               {handoff_port, 8102 },
54c54
<             {pb_port, 8081 },
---
>             {pb_port, 8082 },
11c11
<               {http, [ {"127.0.0.1", 8091 } ]},
---
>               {http, [ {"127.0.0.1", 8093 } ]},
15c15
<               %{https, [{ "127.0.0.1", 8091 }]},
---
>               %{https, [{ "127.0.0.1", 8093 }]},
26c26
<               {handoff_port, 8101 },
---
>               {handoff_port, 8103 },
54c54
<             {pb_port, 8081 },
---
>             {pb_port, 8083 },
11c11
<               {http, [ {"127.0.0.1", 8091 } ]},
---
>               {http, [ {"127.0.0.1", 8094 } ]},
15c15
<               %{https, [{ "127.0.0.1", 8091 }]},
---
>               %{https, [{ "127.0.0.1", 8094 }]},
26c26
<               {handoff_port, 8101 },
---
>               {handoff_port, 8104 },
54c54
<             {pb_port, 8081 },
---
>             {pb_port, 8084 },
Run Code Online (Sandbox Code Playgroud)

在每个“11c11”行之前,我想查看两个文件的名称。

git diff 可以产生这样的输出:

--- a/home/sandport/riak/dev/dev1/etc/app.config
+++ b/home/sandport/riak/dev/dev2/etc/app.config
Run Code Online (Sandbox Code Playgroud)

您将如何使用标准差异来做到这一点?

Iai*_*der 6

添加参数--unified=0以显示每个文件的名称。

--unified部分将输出格式设置为“统一”。统一格式从要比较的文件的名称开始。

=0部件隐藏了上下文线。它使输出更易于目视检查。

使用新参数重新运行原始命令,输出将如下所示:

--- /home/sandport/riak/dev/dev1/etc/app.config 2013-12-11 02:40:09.000000000 +0000
+++ /home/sandport/riak/dev/dev2/etc/app.config 2013-12-11 02:40:09.000000000 +0000
@@ -11 +11 @@
-              {http, [ {"127.0.0.1", 8091 } ]},
+              {http, [ {"127.0.0.1", 8092 } ]},
@@ -15 +15 @@
-              %{https, [{ "127.0.0.1", 8091 }]},
+              %{https, [{ "127.0.0.1", 8092 }]},
@@ -26 +26 @@
-              {handoff_port, 8101 },
+              {handoff_port, 8102 },
@@ -54 +54 @@
-            {pb_port, 8081 },
+            {pb_port, 8082 },
--- /home/sandport/riak/dev/dev1/etc/app.config 2013-12-11 02:40:09.000000000 +0000
+++ /home/sandport/riak/dev/dev3/etc/app.config 2013-12-11 02:40:09.000000000 +0000
[...]
Run Code Online (Sandbox Code Playgroud)