100

What does the following mean ?

diff -rBNu src.orig/java/org/apache/nutch/analysis/NutchAnalysisConstants.java src/java/org/apache/nutch/analysis/NutchAnalysisConstants.java
--- src.orig/java/org/apache/nutch/analysis/NutchAnalysisConstants.java 2009-03-10 11:34:01.000000000 -0700
+++ src/java/org/apache/nutch/analysis/NutchAnalysisConstants.java  2009-03-10 14:11:55.000000000 -0700
@@ -4,9 +4,12 @@

+  int CJK = 21;
+  int DIGIT = 22;

   int DEFAULT = 0;

   String[] tokenImage = {
     "<EOF>",
+    "\"OR\"",
     "<WORD>",
     "<ACRONYM>",
     "<SIGRAM>",
@@ -39,6 +42,8 @@
     "\"\\\"\"",
     "\":\"",
     "\"/\"",
+    "\"(\"",
+    "\")\"",
     "\".\"",
     "\"@\"",
     "\"\\\'\"",
2

4 Answers 4

141

The -u option you used specifies the unified format. In that format the first two lines is a header: --- is the original file, +++ is the new file, and the timestamps.

@@ block headers

That is then followed by chunks (change hunks) that starts with the @@ -R,r +R,r @@ syntax.

Those are two ranges, the one with the - is the range for the chunk in the original file, and the one with the + the range in the new file. The R designates the line number where the diff operation is started.

The numbers after the comma are the number of affected lines in each file.

  • Every time you remove a line, the +r number will be smaller than -r.
  • Every time you add a line, the +r number will be bigger than -r
  • Changing a line will add 0 to the +r number. (same scope of lines)

Chunks of code lines

Within these chunks lines are identified as additions or deletions - means delete, + means addition. Lines that did not change in that chunk will have neither + or - front of it.

In your example it means there are two chunks, or sections, that changed between the two files and the lines with + in it are the new ones added, nothing was deleted.

You can find much more information about the syntax by doing a google search for unified diff.

6
  • 3
    You mentioned "@@ -R +R @@" syntax,but it's in fact "@@ -R,r +R,r @@",what does the other number mean?
    – omg
    Jun 12, 2009 at 16:07
  • 4
    the numbers after the comma are the number of affected lines in each file. Every time you remove a line, the +r number will be smaller than -r. Every time you add a line, the +r number will be bigger than -r Mar 5, 2014 at 21:23
  • @NewAlexandria I'd reformat this so that when listing items, each item is on separate line, indented.
    – Bob
    Apr 27, 2016 at 13:53
  • 3
    Lines that did not change in that chunk will have neither + or - front of it. I think it would be more accurate/specific to say it will have a space in front of it. This is important, because if a line in a changed file started with @@, it must not be confused with the diff syntax.
    – Nateowami
    Mar 14, 2017 at 9:45
  • 3
    Alternative explanation of the r: -r is the number of lines in the chunk of the original file; +r is the number of lines in the chunk in the new file. Basically, count the number of lines in the chunk before and after the change.
    – poke
    Mar 7, 2018 at 12:49
31

The old file name

--- src.orig/java/org/apache/nutch/analysis/NutchAnalysisConstants.java 2009-03-10 11:34:01.000000000 -0700

The new file name

+++ src/java/org/apache/nutch/analysis/NutchAnalysisConstants.java  2009-03-10 14:11:55.000000000 -0700
  • -4: chunk begins at line 4 in old file (including context lines);
  • 9: number of lines in the chunk in old file including context lines (so total of lines that have a - or nothing in front of them);
  • +4: chunk begins at line 4 in the new file;
  • 12: number of lines in the chunk in new file including context lines (so total of lines that have a + or nothing in front of them).

Notice: I changed the diff to include a modified line, so a deleted line followed by an added line.

@@ -4,9 +4,12 @@

+  int CJK = 21;
+  int DIGIT = 22;

-  int DEFAULT = 0;
+  int DEFAULT = 42;

   String[] tokenImage = {
     "<EOF>",
+    "\"OR\"",
     "<WORD>",
     "<ACRONYM>",
     "<SIGRAM>",

Same as above, but notice the chunk in the new file starts 3 lines further because the previous chunk added a net worth of 3 lines.

@@ -39,6 +42,8 @@
     "\"\\\"\"",
     "\":\"",
     "\"/\"",
+    "\"(\"",
+    "\")\"",
     "\".\"",
     "\"@\"",
     "\"\\\'\"",
1
  • 4
    Thanks for explaining the 9 and 12 in this example Oct 28, 2019 at 0:37
2

That depends on what you're asking. Diff shows you the differences between two files. In your case you're diffing NutchAnalysisConstants.java from two different places and generating information about those differences.

-r to diff means "recursive diff," although in this case it does nothing since you're diffing files, not directories.

-B means to ignore changes that only involve blank lines.

-N means that if in directory1 I have a file, but it isn't present in directory2, diff should treat it as if the file is present but empty in directory2 (thus effectively giving you the full contents of the file in directory1).

-u means to use the unified output format, which is only supported by GNU diff and GNU patch.

As for what the output means, this link may be useful for you.

1
  • 2
    Link not found. Please fix your comment
    – Quamis
    Apr 21, 2016 at 9:39
1

The + characters mean that those lines were added since the last version of NutchAnalysisConstants.java. The @@ line is telling you that the diff has jumped to another section of the file, in this case line 39 in the original, or line 43 in the new.

3
  • 2
    @@ -39,6 +43,8 @@ what does 6 and 8 mean specifically?
    – omg
    Jun 12, 2009 at 16:03
  • 1
    It's the number of lines the change hunk applies to for the respective file. So, for the old file, it applies to 6 lines, vs 8 for the new file.
    – John G
    Jun 12, 2009 at 16:38
  • But it turns out that new file is not changed ,is that by design?
    – omg
    Jun 12, 2009 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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