-
Notifications
You must be signed in to change notification settings - Fork 335
Home
The git diff
format is the evolution of the unified format, proposed to bridge the BSD and GNU diff formats.
The official docs on the hunk header: https://github.com/git/git/blob/master/Documentation/diff-generate-patch.txt#L154-L185
Let's take this example:
# example
@@ -108,3 +123,8 @@ function onInputChanged(text, suggest) {`
# generically
@@ -<old_offset, old_line_count> +<new_offset, new_line_count> @@ <hunk_context>`
It starts with @@ -
, though a combined diff (the default) have >2 @
s.
It'll always have the the -A,B
followed by the +C,D
block, except for a file deletion where the first block will be just -A
without a ,B
bit.
You can also end up with a hunk like @@@ -105,13 -104,21 +104,23 @@@
The hunk context doesn't necessarily show the source from that line, but will often show the function name. see https://stackoverflow.com/questions/28111035/where-does-the-excerpt-in-the-git-diff-hunk-header-come-from
In Git this mostly terminates in xdiff: https://github.com/git/git/blob/master/xdiff/xemit.c#L128-L149
However there is also a bunch of language specific patterns used in userdiff.c: https://github.com/git/git/blob/ab5d01a29eb7380ceab070f0807c2939849c44bc/userdiff.c#L15-L152
Issues where we dug into the formats: