@@ -9,9 +9,10 @@在diff文件中的含义是什么?

时间:2014-10-31 05:29:02

标签: diff

有人可以解释下面示例diff输出中的第三行(即以@@开头的那一行)吗?我理解其余行所代表的变化,但我很难理解第三行......

--- a/code/c-skeleton/Makefile
+++ b/code/c-skeleton/Makefile
@@ -9,9 +9,10 @@
 TEST_SRC=$(wildcard tests/*_tests.c)
 TESTS=$(patsubst %.c,%,$(TEST_SRC))

1 个答案:

答案 0 :(得分:1)

@@ -9,9 +9,10 @@

...指定源文件和目标文件发生更改的位置,包括正在编辑的块的行号和大小,在更改之前和之后。

具体做法是:

@@ -9,9 +9,10 @@
^  ^^ ^ ^^ ^
|  || | || \----- The "10" is the number of lines in the hunk after being
|  || | ||        modified; this patch, then, must add a line, since the
|  || | ||        new count (of 10) is longer than the old count (of 9).
|  || | |\------- This "9" is the line number in the new file where the
|  || | |         modified hunk is placed.
|  || | \-------- This "+" is a hint that the following numbers refer to
|  || |           the new file, after modification.
|  || \---------- This "9" is the number of lines in the hunk before being
|  ||             modified.
|  |\------------ This "9" is the line number in the original file.
|  \------------- This "-" is a hint that the following numbers refer to the
|                 original file.
\---------------- This "@@" is a marker indicating that this is the start of a
                  new hunk.

也就是说:在原始文件中,被修改的hunk包含从第9行开始的9行;在目标文件中,它是从第9行开始的10行。

请参阅GNU diffutils文档中的detailed description of unified diff format