When you look at a diff of a file, it will show you the diff info at the top, and then it highlights the changes below.
However, in every example I have looked at...the line number that Github highlights with the change, is always different than the line number that Git specified in the Diff/Patch info.
For example this commit (note the diff data says
@@ -362,7 +362,7 @@ def association_instance_set(name, association
There is nothing wrong with those patches, they look all exactly how they should look.
Unified diff includes 3 lines for context.
Lets look at the hunk in your first example:
@@ -362,7 +362,7 @@
It says that the patch file starts at line 362, and that 7 lines are included in the diff. If we look at the diff, we can see that it indeed starts at line 362 and is 7 lines long.
If we look at the diff in more detail, we see that line 362, 363, 364 are produced verbatim. Line 365 is labeled with a
+) because it got removed and another line re-inserted. This is highlighted by the red/green color in the output. One thing that is not in the actual diff file is GitHubs highlighting of exactly which parts of the line was changed. Thats a custom enhancement of GitHub.
And after that, the three next context lines which are not changed are displayed verbatim.
Unified diff simply provides context lines and includes them in the diff, and GitHub shows it this way, too.
You have 1 changed line (365), and three lines before and after for context. makes 7 lines in total that are included in the patch/diff file (starting at 362).