PATCH(1) PATCH(1)
NAME
patch - apply patches
SYNOPSIS
patch [ -nR [ -d rdir ] [ -r rejfile ] [ -p nstrip ] [ patch
... ]
DESCRIPTION
Patch scans its input for a sequence of patches, and applies
them, printing the list of changed files. When an applied
patch does not match precisely, patch will scan the input
file for matching context, applying the patch up to 250
lines away from its original location. If a hunk does not
apply, then the file is left untouched.
When multiple patch files are provided, they are applied in
order, interrupting the process in case of error. Success-
fully applied patches are not rolled back.
The following options are supported:
-d dir
Interpret paths in the patch file relative to dir.
-R Reverse direction of the patch. Additions become
removals, and the new and old file names are swapped.
-n Print the files that would be modified by this patch,
but do not apply it.
-p nstrip
Remove the prefix containing nstrip leading slashes
from each file path in the diff file.
-r rejfile
Apply as much of the patch as possible, saving any
hunks that could not be applied to a rejection file.
INPUT FORMAT
A patch begins with a patch header, and is followed by a
sequence of one or more hunks. All lines before a patch
header or after the last hunk of a patch are comments, and
are ignored by patch. A patch header is a sequence of 2
lines in the following format:
--- oldfile [trailing text]
+++ newfile [trailing text]
A hunk must immediately follow a patch header or another
hunk. It begins with a header line in the following format:
Page 1 Plan 9 (printed 10/27/25)
PATCH(1) PATCH(1)
@@ -count,addr +count,addr @@
And contains a sequence of lines beginning with a `-', `+',
or space characters. A `-' indicates that the line is to be
removed from the old file. A `+' indicates that the line is
to be inserted into the new file. A space indicates that
the line is context. It will be copied unchanged from the
old file to the new file.
If the old file is `/dev/null', the patch indicates a file
creation. If the new file is `/dev/null', the patch indi-
cates a file deletion. In this case, the file printed is
the file being removed.
SEE ALSO
diff(1), git/export(1)
BUGS
The output of diff -c is not handled.
Reject files and backups are not supported.
All files are processed in memory, limiting the maximum file
size to available RAM.
Page 2 Plan 9 (printed 10/27/25)