In the context of a patch both produced and applied by git (i.e. unified diff format)…
What is required for a patch to apply cleanly? Does the context have to match exactly? What happens if a line of context is missing or added? Does it have to match at the exact same line numbers, or does git look nearby in the file if stuff has shifted a bit?
Google had very little to say about this when I searched, nor did the manual.
This is information for
patch, but git behaves similarly:The removed lines (preceded by
-) have to match exactly. The context does not have to match completely; if it fails to match this will be reported as “fuzz”; by default the outer 2 lines of context do not have to match but the inner line (immediately adjacent to the change) does.Changes (“hunks”) can move up or down in the file, but the patch will fail to apply if they are not in the same order.