@@ -l,s +l,s @@
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.
The hunk range for the original should be the sum of all contextual and deletion (including changed) hunk lines. The hunk range for the new file should be a sum of all contextual and addition (including changed) hunk lines. If hunk size information does not correspond with the number of lines in the hunk, then the diff could be considered invalid and be rejected.
If a line is modified, it is represented as a deletion and addition. Since the hunks of the original and new file appear in the same hunk, such changes would appear adjacent to one another.
original: 1 This part of the 2 document has stayed the 3 same from version to 4 version. It shouldn't 5 be shown if it doesn't 6 change. Otherwise, that 7 would not be helping to 8 compress the size of the 9 changes. 10 11 This paragraph contains 12 text that is outdated. 13 It will be deleted in the 14 near future. 15 16 It is important to spell 17 check this dokument. On 18 the other hand, a 19 misspelled word isn't 20 the end of the world. 21 Nothing in the rest of 22 this paragraph needs to 23 be changed. Things can 24 be added after it. |
new: 1 This is an important 2 notice! It should 3 therefore be located at 4 the beginning of this 5 document! 6 7 This part of the 8 document has stayed the 9 same from version to 10 version. It shouldn't 11 be shown if it doesn't 12 change. Otherwise, that 13 would not be helping to 14 compress anything. 15 16 It is important to spell 17 check this document. On 18 the other hand, a 19 misspelled word isn't 20 the end of the world. 21 Nothing in the rest of 22 this paragraph needs to 23 be changed. Things can 24 be added after it. 25 26 This paragraph contains 27 important new additions 28 to this document. |
--- /path/to/original ''timestamp'' +++ /path/to/new ''timestamp'' @@ -1,3 +1,9 @@ +This is an important +notice! It should +therefore be located at +the beginning of this +document! + This part of the document has stayed the same from version to @@ -5,16 +11,10 @@ be shown if it doesn't change. Otherwise, that would not be helping to -compress the size of the -changes. - -This paragraph contains -text that is outdated. -It will be deleted in the -near future. +compress anything. It is important to spell -check this dokument. On +check this document. On the other hand, a misspelled word isn't the end of the world. @@ -22,3 +22,7 @@ this paragraph needs to be changed. Things can be added after it. + +This paragraph contains +important new additions +to this document. 为啥是@@ -5,16 +11,10 @@,因为5,11代表起始行号,16,10代表影响的范围,原文件中影响了从第5行开始的16行, 新文件中影响了从第11行开始的10行。所以大家就不用关心16和10这两个值了,没什么意义!! 参考文献:http://en.wikipedia.org/wiki/Diff