patch – apply patches

patch [ –R ] [ –p nstrip ] [ patch ... ]

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.

The following options are supported:
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.

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:
@@ –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 indicates a file deletion. In this case, the file printed is the file being removed.

diff(1), git/export(1)


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.