Diff文件语法是什么?

12

我目前在尝试解析diff文件,但还没有找到一份关于diff文件的可靠文档。

我特别感兴趣的是规范。例如,我不太理解看起来像这样的行(在每个更改的代码块开头):

@@ -296,7 +296,8 @@

我知道它们与行号以及更改的行数有关,但到目前为止我还没有真正弄清楚细节。

diff文件的输出语法是什么(至少是主要部分)?

2个回答

8

请查看GNU diffutils的文档。您将在该文档中找到以下内容:

Next come one or more hunks of differences; each hunk shows one area where the files differ. Unified format hunks look like this:

@@ from-file-line-numbers to-file-line-numbers @@
  line-from-either-file
  line-from-either-file...

If a hunk contains just one line, only its start line number appears. Otherwise its line numbers look like ‘start,count’. An empty hunk is considered to start at the line that follows the hunk.

If a hunk and its context contain two or more lines, its line numbers look like ‘start,count’. Otherwise only its end line number appears. An empty hunk is considered to end at the line that precedes the hunk.

The lines common to both files begin with a space character. The lines that actually differ between the two files have one of the following indicator characters in the left print column:

‘+’ A line was added here to the first file.

‘-’ A line was removed here from the first file.



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