Node:Reversed Patches, Next:Inexact, Previous:Changed White Space, Up:Imperfect
Sometimes people run diff
with the new file first instead of
second. This creates a diff that is "reversed". To apply such
patches, give patch
the -R
or --reverse
option.
patch
then attempts to swap each hunk around before applying it.
Rejects come out in the swapped format.
Often patch
can guess that the patch is reversed. If the first
hunk of a patch fails, patch
reverses the hunk to see if it can
apply it that way. If it can, patch
asks you if you want to have
the -R
option set; if it can't, patch
continues to apply
the patch normally. This method cannot detect a reversed patch if it is
a normal diff and the first command is an append (which should have been
a delete) since appends always succeed, because a null context matches
anywhere. But most patches add or change lines rather than delete them,
so most reversed normal diffs begin with a delete, which fails, and
patch
notices.