Skip to content
Paul Irish edited this page Mar 9, 2016 · 3 revisions

Diff Details

The git diff format is the evolution of the unified format, proposed to bridge the BSD and GNU diff formats.

Hunks

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>`

Offsets

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 @@@

Context

The hunk context doesn't necessarily show the source from that line, but will often show the function name. see http://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

image

Issues where we dug into the formats:

Clone this wiki locally