This line @@ -412,7 +457,7 @@ is called a hunk header in a unified diff format, which git diff uses. It tells you where the subsequent block of changes (the "hunk") is located in the old and new versions of the file.
Let's break it down:
@@ ... @@: These are markers indicating the start and end of the hunk header.
-412,7: This refers to the old file (the version before the changes).
-: Indicates this part describes the "old" or "source" file.
412: This is the starting line number in the old file from which this hunk is taken.
7: This is the number of lines that this hunk covers in the old file, starting from line 412. So, this hunk represents lines 412 through 418 (412 + 7 - 1) in the old file.
+457,7: This refers to the new file (the version after the changes).
+: Indicates this part describes the "new" or "destination" file.
457: This is the starting line number in the new file where this hunk will be located.
7: This is the number of lines that this hunk covers in the new file, starting from line 457. So, this hunk represents lines 457 through 463 (457 + 7 - 1) in the new file.
What does this specific example tell us?
Shift in Line Numbers: The starting line number has changed from 412 in the old file to 457 in the new file. This means that 45 lines were added (or fewer lines were deleted) before this specific block of changes. (457 - 412 = 45).
Same Hunk Size: Both the old and new versions of this hunk display 7 lines. This often means that within these 7 lines, there are some modifications, but the total number of lines displayed for this section remains the same. For example, one line might have been modified, which is represented as a deletion and an addition.
Following this hunk header, you'll see the actual lines:
Lines prefixed with a space () are context lines, unchanged and present in both versions.
Lines prefixed with a minus (-) were removed from the old file (or are the "before" state of a modified line).
Lines prefixed with a plus (+) were added to the new file (or are the "after" state of a modified line).
In summary:
The line @@ -412,7 +457,7 @@ tells you that the diff is about to show you a 7-line segment.
In the original file, this segment started at line 412.
In the modified file, this same conceptual segment (with changes) now starts at line 457.
The shift in starting line number indicates that there were net additions of lines before this particular hunk.
User
In this example is the end select before the hunk header?
code
case('v2')
input(:ncol,0*pver+1:1*pver) = state%t(1:ncol,1:pver) ! state_t
input(:ncol,1*pver+1:2*pver) = state%q(1:ncol,1:pver,1) ! state_q0001
@@ -412,7 +457,7 @@ end select
! [TODO] for ensemble, ReLU should be moved before ens-averaging
do i=1,ncol
Assistant
You're looking at a common feature of git diff output.
The end selectafter the @@ -412,7 +457,7 @@ is part of the hunk header itself.
Let's break down that hunk header again with this new information:
@@ -412,7 +457,7 @@ end select
@@ ... @@: Markers for the hunk header.
-412,7: In the old file, the hunk starts at line 412 and is 7 lines long.
+457,7: In the new file, the hunk starts at line 457 and is 7 lines long.
end select (optional section header): This is a piece of text (usually the first line of the hunk, or a nearby function/block name) that Git includes to give you more context about where this hunk begins. It's trying to be helpful by showing you a significant line from the start of the hunk itself.
So, to answer your question directly:
The lines case('v2'), input(...) = state%t(...), and input(...) = state%q(...) are context lines that appear in the diff output before this particular hunk header. They are part of the file content preceding the changes described by this hunk.
The end select that is part of the hunk header line itself indicates that the 7-line block (starting at line 412 in the old file / 457 in the new file) begins with (or very near) an end select statement.
What you would expect to see immediately after this hunk header line is:
code
@@ -412,7 +457,7 @@ end select
end select <-- Likely this line, unchanged (prefixed with a space)
! [TODO] for ensemble, ReLU should be moved before ens-averaging
do i=1,ncol
... (other lines belonging to this 7-line hunk)
The end select in the header is a preview or label for the content of the hunk that follows. The actual end select line from the code will appear after the @@ ... @@ line, usually prefixed with a space if it's an unchanged context line that's part of the hunk.
User
Here I count 8 lines if you include end select:
code
case('v2')
input(:ncol,0*pver+1:1*pver) = state%t(1:ncol,1:pver) ! state_t
input(:ncol,1*pver+1:2*pver) = state%q(1:ncol,1:pver,1) ! state_q0001
@@ -412,7 +457,7 @@ end select
! [TODO] for ensemble, ReLU should be moved before ens-averaging
do i=1,ncol
! ReLU for the last 8 variables
- do k=outputlength-7,outputlength
+ do k=361,368
output(i,k) = max(output(i,k), 0.)
end do
! ! tiny flwds
Assistant
You are absolutely right to be meticulous about counting! This is a very common point of confusion when first learning to read diffs.
Let's break it down again with your full example:
diff
case('v2')
input(:ncol,0*pver+1:1*pver) = state%t(1:ncol,1:pver) ! state_t
input(:ncol,1*pver+1:2*pver) = state%q(1:ncol,1:pver,1) ! state_q0001
@@ -412,7 +457,7 @@ end select
! [TODO] for ensemble, ReLU should be moved before ens-averaging
do i=1,ncol
! ReLU for the last 8 variables
- do k=outputlength-7,outputlength
+ do k=361,368
output(i,k) = max(output(i,k), 0.)
end do
! ! tiny flwds
Here's the key:
The hunk header @@ -412,7 +457,7 @@ end select means:
In the old file (before changes), this hunk consisted of 7 lines starting at line 412.
In the new file (after changes), this hunk consists of 7 lines starting at line 457.
The hunk starts with (or very near) a line containing end select.
How the diff displays changes: When a line is modified, the diff shows it as:
The old line, prefixed with - (removed).
The new line, prefixed with + (added).
Even though this takes up two lines in the diff output, it represents a change to one logical line in the file.
Now let's count the lines within the hunk itself for both the old and new versions, corresponding to the ,7 in the header:
Lines belonging to the hunk (starting with end select):
end select (This is line 1 of the hunk in both old and new versions. It's the line referred to by the end select in the hunk header.)
! [TODO] for ensemble, ReLU should be moved before ens-averaging (Line 2 in both)
do i=1,ncol (Line 3 in both)
! ReLU for the last 8 variables (Line 4 in both)
Old file:do k=outputlength-7,outputlength (Line 5 in old)
New file:do k=361,368 (Line 5 in new)
output(i,k) = max(output(i,k), 0.) (Line 6 in both)
end do (Line 7 in both)
Why you see 8 lines displayed after the @@ ... @@ header:
You are correctly counting the displayed lines in the diff for this hunk:
end select (context)
! [TODO]... (context)
do i=1,ncol (context)
! ReLU... (context)
- do k=outputlength-7,outputlength (removed line)
+ do k=361,368 (added line, replacing the one above)
output(i,k) = max(output(i,k), 0.) (context)
end do (context)
The diff displays 8 lines here because the modification to the do k=... line is shown as one deletion and one addition. However, this modification still means that the hunk occupied 7 lines in the original file and now occupies 7 lines in the new file.
In summary:
The lines before@@ ... @@ (case('v2') etc.) are indeed before the hunk. They are just context lines provided by the diff.
The end selectin the @@ ... @@ line is a label for the start of the hunk.
The actual end select line after the @@ ... @@ line is the first line of the hunk itself.
The hunk header's line counts (-...,7 and +...,7) refer to the number of lines this logical block occupies in the old and new files, respectively. A single modified line will result in two lines in the diff output (- and +) but still counts as one line for the purpose of the hunk header's length.