解读“svn diff”输出

5

假设a.c文件中没有任何内容,然后按照以下方式修改该文件:

#include <stdio.h>

int main()
{
    printf("Hello, world\n");
}

执行svn diff命令后,我收到了以下消息。

--- b.c (revision 1)
+++ b.c (working copy)
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main()
+{
+    printf("Hello, world\n");
+}

在代码中添加一行:
#include <stdio.h>

int main()
{
    printf("Hello, world\n");
    printf("Goodbye, world\n");
}

这是 svn diff 的结果:
--- b.c (revision 2)
+++ b.c (working copy)
@@ -3,4 +3,5 @@
 int main()
 {
     printf("Hello, world\n");
+    printf("Goodbye, world\n");
 }

我猜测在旧版本(-)和新版本(+)中,逗号后面的数字是展示总行数。然而,我不确定逗号前面的数字是什么意思。我认为它标志着改变的开始,但对于第一个情况,新版本(+)的数字是1而不是0。

如何解释svn diff的输出?

2个回答

9

来自维基百科的统一差异格式

@@ -l,s +l,s @@ optional section heading

The hunk range information contains two hunk ranges. The range for the hunk of the original file is preceded by a minus symbol, and the range for the new file is preceded by a plus symbol. Each hunk range is of the format l,s where l is the starting line number and s is the number of lines the change hunk applies to for each respective file. In many versions of GNU diff, each range can omit the comma and trailing value s, in which case s defaults to 1. Note that the only really interesting value is the l line number of the first range; all the other values can be computed from the diff.


SVN在哪里记录它使用统一的差异格式? - Jason S

3
我认为这是变化开始的地方,但对于第一个案例,新的(+)版本的数字是1而不是0。
行号从1开始,因此新(+)文件的1,6可以解释为: 1是起始行号,6是显示的行数。
对于行号的0必须是一种特殊情况,表示文件不存在。这样你就可以区分不存在的旧(-)文件 - 0,0 - 和空文件 - 1,0

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