2

This question already has an answer here:

Here is an example of Unix Shell program diff, from Version Control with Git, by Loeliger, 2ed:

enter image description here

Let’s look at the diff in detail.

In the header, the original file is denoted by - - - and the new file by +++.

The @@ line provides line number context for both file versions.

What do the numbers in the "@@" line mean exactly?

marked as duplicate by don_crissti, roaima, jimmij, Jeff Schaller, vonbrand Jan 3 '16 at 1:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

They are line-numbers for the old/new files to help the patch (or similar) program decode the unified-diff.

  • The number after the comma is the length of the chunk (in the old or new file), and
  • the number before the comma is the line number for the beginning of the chunk.
  • The + and - signs refer to adding and deleting lines, respectively.

In your example, the line

@@ -1,4 +1,5 @@

uses the - and + signs as an analogy for the < and > signs used in the normal diff output for the left/right files. Both of those formats attempt to interleave lines of difference. (A context diff shows before- and after-chunks, not interleaving).

Unified diff is a particular format of the diff program; other widely-supported formats are discussed in the diff Output Formats section.

Further reading:

  • THanks. (1) What is "unified-diff"? Are there other types of diff? (2) what do the signs in "-1" and "+1" mean? the original file and the other file? – Tim Jan 2 '16 at 23:40
  • @Tim there are three "modes" for diff: normal, unified and context. First one is default for interactive purpose, last two are useful for patches and the like. Manual of diff is extensive, all detailed description is there. – jimmij Jan 2 '16 at 23:58
  • Thanks. Let me clarify my (2): In your edit, "the number before the comma is the line number for the beginning of the chunk." what do the signs in these numbers (e.g. "-1" and "+1") mean? the original file and the other file? (I assume your "The + and - signs refer to adding and deleting lines, respectively" apply to the lines after the @@ line.) – Tim Jan 3 '16 at 0:00
1

The GNU diff documentation explains this, in the section on Unified Format:

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 h ave 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.
  • Thanks. What does "hunk" mean here? – Tim Jan 2 '16 at 23:41
  • @Tim the common English meaning of "a piece of something" works well. – muru Jan 2 '16 at 23:43
  • A piece of what here? – Tim Jan 2 '16 at 23:44
  • @Tim since it says "hunks of differences", what do you think? – muru Jan 2 '16 at 23:45
  • It's the section of output between lines beginning @@ or --- or +++ – Thomas Dickey Jan 2 '16 at 23:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.