patch - apply changes to files
patch [-blNR] [-c | -e | -n | -u] [-d dir] [-D define] [-i patchfile] [-o outfile] [-p num] [-r rejectfile] [file]
The patch command reads a source (patch) file containing any of the three forms of difference (diff) listings produced by the diff(1) command (normal, context or in the style of ed(1)) and apply those differences to a file. By default, patch reads from the standard input.
patch attempts to determine the type of the diff listing, unless overruled by a -c, -e, or -n option.
If the patch file contains more than one patch, patch attempts to apply each of them as if they came from separate patch files. (In this case the name of the patch file must be determinable for each diff listing.)
The following options are supported:
#ifdef define ... #endif
The option-argument define is used as the differentiating symbol.
The following operand is supported:
The -R option does not work with ed scripts because there is too little information to reconstruct the reverse operation.
The -p option makes it possible to customize a patch file to local user directory structures without manually editing the patch file. For example, if the file name in the patch file was /curds/whey/src/blurfl/blurfl.c:
When using -b in some file system implementations, the saving of a .orig file might produce unwanted results. In the case of 12-, 13-, or 14-character file names, on file systems supporting 14-character maximum file names, the .orig file overwrites the new file.
See environ(5) for descriptions of the following environment variables that affect the execution of patch: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_TIME, and NLSPATH.
Affirmative responses are processed using the extended regular expression defined for the yesexpr keyword in the LC_MESSAGES category of the user's locale. The locale specified in the LC_COLLATE category defines the behavior of ranges, equivalence classes, and multi-character collating elements used in the expression defined for yesexpr. The locale specified in LC_CTYPE determines the locale for interpretation of sequences of bytes of text data a characters, the behavior of character classes used in the expression defined for the yesexpr. See locale(5).
The output of patch the save files (.orig suffixes) and the reject files (.rej suffixes) are text files.
A patch file can contain patching instructions for more than one file. File names are determined as specified in Patch Determination. When the -b option is specified, for each patched file, the original is saved in a file of the same name with the suffix .orig appended to it.
For each patched file, a reject file can also be created as noted in Patch Application. In the absence of an -r option, the name of this file is formed by appending the suffix .rej to the original file name.
The patch file must contain zero or more lines of header information followed by one or more patches. Each patch must contain zero or more lines of file name identification in the format produced by diff -c, and one or more sets of diff output, which are customarily called hunks.
patch recognizes the following expression in the header information:
If all lines (including headers) within a patch begin with the same leading sequence of blank characters, patch removes this sequence before proceeding. Within each patch, if the type of difference is context, patch recognizes the following expressions:
*** filename timestamp
--- filename timestamp
Each hunk within a patch must be the diff output to change a line range within the original file. The line numbers for successive hunks within a patch must occur in ascending order.
If no file operand is specified, patch performs the following steps to obtain a path name:
If the -c, -e, -n, or -u option is present, patch interprets information within each hunk as a context difference, an ed difference, a normal difference, or a unified context difference, respectively. In the absence of any of these options, patch determines the type of difference based on the format of information within the hunk.
For each hunk, patch begins to search for the place to apply the patch at the line number at the beginning of the hunk, plus or minus any offset used in applying the previous hunk. If lines matching the hunk context are not found, patch scans both forwards and backwards at least 1000 bytes for a set of lines that match the hunk context.
If no such place is found and it is a context difference, then another scan takes place, ignoring the first and last line of context. If that fails, the first two and last two lines of context is ignored and another scan is made. Implementations can search more extensively for installation locations.
If no location can be found, patch appends the hunk to the reject file. The rejected hunk is written in context-difference format regardless of the format of the patch file. If the input was a normal or ed -style difference, the reject file can contain differences with zero lines of context. The line numbers on the hunks in the reject file can be different from the line numbers in the patch file since they reflect the approximate locations for the failed hunks in the new file rather than the old one.
If the type of patch is an ed diff, the implementation can accomplish the patching by invoking the ed command.
The following exit values are returned:
See attributes(5) for descriptions of the following attributes:
ed(1), diff(1), attributes(5), environ(5), standards(5)
Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру