Sortix volatile manual
This manual documents Sortix volatile, a development build that has not been officially released. You can instead view this document in the latest official manual.
PATCH(1) | General Commands Manual | PATCH(1) |
NAME
patch - apply a diff file to an originalDESCRIPTION
patch takes a patch file patchfile containing a difference listing produced by the diff program and applies those differences to one or more original files, producing patched versions. Normally the patched versions are put in place of the originals. Backups can be made; see the -b or --backup option. The names of the files to be patched are usually taken from the patch file, but if there's just one file to be patched it can be specified on the command line as originalfile.- •
- If the header is that of a context diff, patch takes the old and new file names in the header. A name is ignored if it does not have enough slashes to satisfy the -pnum or --strip=num option. The name /dev/null is also ignored.
- •
- If there is an Index: line in the leading garbage and if either the old and new names are both absent or if patch is conforming to POSIX, patch takes the name in the Index: line.
- •
- For the purpose of the following rules, the candidate file names are considered to be in the order (old, new, index), regardless of the order that they appear in the header.
- •
- If some of the named files exist, patch selects the first name if conforming to POSIX, and the best name otherwise.
- •
- If patch is not ignoring RCS, ClearCase, Perforce, and SCCS (see the -g num or --get=num option), and no named files exist but an RCS, ClearCase, Perforce, or SCCS master is found, patch selects the first named file with an RCS, ClearCase, Perforce, or SCCS master.
- •
- If no named files exist, no RCS, ClearCase, Perforce, or SCCS master was found, some names are given, patch is not conforming to POSIX, and the patch appears to create a file, patch selects the best name requiring the creation of the fewest directories.
- •
- If no file name results from the above heuristics, you are asked for the name of the file to patch, and patch selects that name.
| patch -d /usr/src/local/blurfl
OPTIONS
- -b or --backup
- Make backup files. That is, when patching a file, rename or copy the original instead of removing it. When backing up a file that does not exist, an empty, unreadable backup file is created as a placeholder to represent the nonexistent file. See the -V or --version-control option for details about how backup file names are determined.
- --backup-if-mismatch
- Back up a file if the patch does not match the file exactly and if backups are not otherwise requested. This is the default unless patch is conforming to POSIX.
- --no-backup-if-mismatch
- Do not back up a file if the patch does not match the file exactly and if backups are not otherwise requested. This is the default if patch is conforming to POSIX.
- -B pref or --prefix=pref
- Use the simple method to determine backup file names (see the -V method or --version-control method option), and append pref to a file name when generating its backup file name. For example, with -B /junk/ the simple backup file name for src/patch/util.c is /junk/src/patch/util.c.
- --binary
- Write all files in binary mode, except for standard output and /dev/tty. When reading, disable the heuristic for transforming CRLF line endings into LF line endings. This option is needed on POSIX systems when applying patches generated on non-POSIX systems to non-POSIX files. (On POSIX systems, file reads and writes never transform line endings. On Windows, reads and writes do transform line endings by default, and patches should be generated by diff --binary when line endings are significant.)
- -c or --context
- Interpret the patch file as a ordinary context diff.
- -d dir or --directory=dir
- Change to the directory dir immediately, before doing anything else.
- -D define or --ifdef=define
- Use the #ifdef ... #endif construct to mark changes, with define as the differentiating symbol.
- --dry-run
- Print the results of applying the patches without actually changing any files.
- -e or --ed
- Interpret the patch file as an ed script.
- -E or --remove-empty-files
- Remove output files that are empty after the patches have been applied. Normally this option is unnecessary, since patch can examine the time stamps on the header to determine whether a file should exist after patching. However, if the input is not a context diff or if patch is conforming to POSIX, patch does not remove empty patched files unless this option is given. When patch removes a file, it also attempts to remove any empty ancestor directories.
- -f or --force
- Assume that the user knows exactly what he or she is doing, and do not ask any questions. Skip patches whose headers do not say which file is to be patched; patch files even though they have the wrong version for the Prereq: line in the patch; and assume that patches are not reversed even if they look like they are. This option does not suppress commentary; use -s for that.
- -F num or --fuzz=num
- Set the maximum fuzz factor. This option only applies to diffs that have context, and causes patch to ignore up to that many lines of context in looking for places to install a hunk. Note that a larger fuzz factor increases the odds of a faulty patch. The default fuzz factor is 2. A fuzz factor greater than or equal to the number of lines of context in the context diff, ordinarily 3, ignores all context.
- -g num or --get=num
- This option controls patch's actions when a file is under RCS or SCCS control, and does not exist or is read-only and matches the default version, or when a file is under ClearCase or Perforce control and does not exist. If num is positive, patch gets (or checks out) the file from the revision control system; if zero, patch ignores RCS, ClearCase, Perforce, and SCCS and does not get the file; and if negative, patch asks the user whether to get the file. The default value of this option is given by the value of the PATCH_GET environment variable if it is set; if not, the default value is zero.
- --help
- Print a summary of options and exit.
- -i patchfile or --input=patchfile
- Read the patch from patchfile. If patchfile is -, read from standard input, the default.
- -l or --ignore-whitespace
- Match patterns loosely, in case tabs or spaces have been munged in your files. Any sequence of one or more blanks in the patch file matches any sequence in the original file, and sequences of blanks at the ends of lines are ignored. Normal characters must still match exactly. Each line of the context must still match a line in the original file.
- --merge or --merge=merge or --merge=diff3
- Merge a patch file into the original files similar to diff3(1) or merge(1). If a conflict is found, patch outputs a warning and brackets the conflict with <<<<<<< and >>>>>>> lines. A typical conflict will look like this:
<<<<<<< lines from the original file ||||||| original lines from the patch ======= new lines from the patch >>>>>>>
-
-
The optional argument of --merge determines the output format for conflicts: the diff3 format shows the ||||||| section with the original lines from the patch; in the merge format, this section is missing. The merge format is the default.
- -n or --normal
- Interpret the patch file as a normal diff.
- -N or --forward
- When a patch does not apply, patch usually checks if the patch looks like it has been applied already by trying to reverse-apply the first hunk. The --forward option prevents that. See also -R.
- -o outfile or --output=outfile
- Send output to outfile instead of patching files in place. Do not use this option if outfile is one of the files to be patched. When outfile is -, send output to standard output, and send any messages that would usually go to standard output to standard error.
- -pnum or --strip=num
-
Strip the smallest prefix containing num leading slashes from each file name found in the patch file. A sequence of one or more adjacent slashes is counted as a single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out the patch. For example, supposing the file name in the patch file was
/u/howard/src/blurfl/blurfl.c
u/howard/src/blurfl/blurfl.c
blurfl/blurfl.c
- --posix
- Conform more strictly to the POSIX standard, as follows.
- •
- Take the first existing file from the list (old, new, index) when intuiting file names from diff headers.
- •
- Do not remove files that are empty after patching.
- •
- Do not ask whether to get files from RCS, ClearCase, Perforce, or SCCS.
- •
- Require that all options precede the files in the command line.
- •
- Do not backup files when there is a mismatch.
- --quoting-style=word
- Use style word to quote output names. The word should be one of the following:
- literal
- Output names as-is.
- shell
- Quote names for the shell if they contain shell metacharacters or would cause ambiguous output.
- shell-always
- Quote names for the shell, even if they would normally not require quoting.
- c
- Quote names as for a C language string.
- escape
- Quote as with c except omit the surrounding double-quote characters.
- -r rejectfile or --reject-file=rejectfile
- Put rejects into rejectfile instead of the default .rej file. When rejectfile is -, discard rejects.
- -R or --reverse
-
Assume that this patch was created with the old and new files swapped. (Yes, I'm afraid that does happen occasionally, human nature being what it is.) patch attempts to swap each hunk around before applying it. Rejects come out in the swapped format. The -R option does not work with ed diff scripts because there is too little information to reconstruct the reverse operation.
- --read-only=behavior
- Behave as requested when trying to modify a read-only file: ignore the potential problem, warn about it (the default), or fail.
- --reject-format=format
- Produce reject files in the specified format (either context or unified). Without this option, rejected hunks come out in unified diff format if the input patch was of that format, otherwise in ordinary context diff form.
- -s or --silent or --quiet
- Work silently, unless an error occurs.
- --follow-symlinks
- When looking for input files, follow symbolic links. Replaces the symbolic links, instead of modifying the files the symbolic links point to. Git-style patches to symbolic links will no longer apply. This option exists for backwards compatibility with previous versions of patch; its use is discouraged.
- -t or --batch
- Suppress questions like -f, but make some different assumptions: skip patches whose headers do not contain file names (the same as -f); skip patches for which the file has the wrong version for the Prereq: line in the patch; and assume that patches are reversed if they look like they are.
- -T or --set-time
-
Set the modification and access times of patched files from time stamps given in context diff headers. Unless specified in the time stamps, assume that the context diff headers use local time.
- -u or --unified
- Interpret the patch file as a unified context diff.
- -v or --version
- Print out patch's revision header and patch level, and exit.
- -V method or --version-control=method
-
Use method to determine backup file names. The method can also be given by the PATCH_VERSION_CONTROL (or, if that's not set, the VERSION_CONTROL) environment variable, which is overridden by this option. The method does not affect whether backup files are made; it affects only the names of any backup files that are made.
- existing or nil
- Make numbered backups of files that already have them, otherwise simple backups. This is the default.
- numbered or t
- Make numbered backups. The numbered backup file name for F is F.~N~ where N is the version number.
- simple or never
- Make simple backups. The -B or --prefix, -Y or --basename-prefix, and -z or --suffix options specify the simple backup file name. If none of these options are given, then a simple backup suffix is used; it is the value of the SIMPLE_BACKUP_SUFFIX environment variable if set, and is .orig otherwise.
- --verbose
- Output extra information about the work being done.
- -x num or --debug=num
- Set internal debugging flags of interest only to patch patchers.
- -Y pref or --basename-prefix=pref
- Use the simple method to determine backup file names (see the -V method or --version-control method option), and prefix pref to the basename of a file name when generating its backup file name. For example, with -Y .del/ the simple backup file name for src/patch/util.c is src/patch/.del/util.c.
- -z suffix or --suffix=suffix
- Use the simple method to determine backup file names (see the -V method or --version-control method option), and use suffix as the suffix. For example, with -z - the backup file name for src/patch/util.c is src/patch/util.c-.
- -Z or --set-utc
-
Set the modification and access times of patched files from time stamps given in context diff headers. Unless specified in the time stamps, assume that the context diff headers use Coordinated Universal Time (UTC, often known as GMT). Also see the -T or --set-time option.
ENVIRONMENT
- PATCH_GET
- This specifies whether patch gets missing or read-only files from RCS, ClearCase, Perforce, or SCCS by default; see the -g or --get option.
- POSIXLY_CORRECT
- If set, patch conforms more strictly to the POSIX standard by default: see the --posix option.
- QUOTING_STYLE
- Default value of the --quoting-style option.
- SIMPLE_BACKUP_SUFFIX
- Extension to use for simple backup file names instead of .orig.
- TMPDIR, TMP, TEMP
- Directory to put temporary files in; patch uses the first environment variable in this list that is set. If none are set, the default is system-dependent; it is normally /tmp on Unix hosts.
- VERSION_CONTROL or PATCH_VERSION_CONTROL
- Selects version control style; see the -v or --version-control option.
FILES
- $TMPDIR/p*
- temporary files
- /dev/tty
- controlling terminal; used to get answers to questions asked of the user
SEE ALSO
diff(1), ed(1), merge(1).NOTES FOR PATCH SENDERS
There are several things you should bear in mind if you are going to be sending out patches.
LC_ALL=C TZ=UTC0 diff -Naur gcc-2.7 gcc-2.8
diff -Naur v2.0.29/prog/README prog/README
--- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
+++ prog/README Mon Mar 17 14:58:22 1997
diff -Naur v2.0.29/prog/README v2.0.30/prog/README
--- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
+++ v2.0.30/prog/README Mon Mar 17 14:58:22 1997
DIAGNOSTICS
Diagnostics generally indicate that patch couldn't parse your patch file.CAVEATS
Context diffs cannot reliably represent the creation or deletion of empty files, empty directories, or special files such as symbolic links. Nor can they represent changes to file metadata like ownership, permissions, or whether one file is a hard link to another. If changes like these are also required, separate instructions (e.g. a shell script) to accomplish them should accompany the patch.COMPATIBILITY ISSUES
The POSIX standard specifies behavior that differs from patch's traditional behavior. You should be aware of these differences if you must interoperate with patch versions 2.1 and earlier, which do not conform to POSIX.- •
-
In traditional patch, the -p option's operand was optional, and a bare -p was equivalent to -p0. The -p option now requires an operand, and -p 0 is now equivalent to -p0. For maximum compatibility, use options like -p0 and -p1.
- •
-
In traditional patch, backups were enabled by default. This behavior is now enabled with the -b or --backup option.
- •
- Traditional patch used a complicated (and incompletely documented) method to intuit the name of the file to be patched from the patch header. This method did not conform to POSIX, and had a few gotchas. Now patch uses a different, equally complicated (but better documented) method that is optionally POSIX-conforming; we hope it has fewer gotchas. The two methods are compatible if the file names in the context diff header and the Index: line are all identical after prefix-stripping. Your patch is normally compatible if each header's file names all contain the same number of slashes.
- •
- When traditional patch asked the user a question, it sent the question to standard error and looked for an answer from the first file in the following list that was a terminal: standard error, standard output, /dev/tty, and standard input. Now patch sends questions to standard output and gets answers from /dev/tty. Defaults for some answers have been changed so that patch never goes into an infinite loop when using default answers.
- •
- Traditional patch exited with a status value that counted the number of bad hunks, or with status 1 if there was real trouble. Now patch exits with status 1 if some hunks failed, or with 2 if there was real trouble.
- •
-
Limit yourself to the following options when sending instructions meant to be executed by anyone running GNU patch, traditional patch, or a patch that conforms to POSIX. Spaces are significant in the following list, and operands are required.
-c
-d dir
-D define -e -l -n -N
-o outfile
-pnum -R
-r rejectfile
BUGS
Please report bugs via email to <bug-patch@gnu.org>.COPYING
Copyright (C) 1984, 1985, 1986, 1988 Larry Wall.AUTHORS
Larry Wall wrote the original version of patch. Paul Eggert removed patch's arbitrary limits; added support for binary files, setting file times, and deleting files; and made it conform better to POSIX. Other contributors include Wayne Davison, who added unidiff support, and David MacKenzie, who added configuration and backup support. Andreas Grünbacher added support for merging.GNU |