Lines Matching full:patch

15 differences between files and the @acronym{GNU} @command{patch} command for
43 * patch: (diff)Invoking patch. Apply a patch to a file.
54 @subtitle for Diffutils @value{VERSION} and @code{patch} 2.5.4
87 * Merging with patch:: Using @command{patch} to change old files into new ones.
88 * Making Patches:: Tips for making and using patch distributions.
93 * Invoking patch:: Apply a diff file to an original.
106 @cindex overview of @command{diff} and @command{patch}
116 often called a @dfn{diff} or @dfn{patch}. For files that are identical,
139 @command{patch} program to update, or @dfn{patch}, a copy of the file. If you
141 their difference, you can think of @command{patch} as adding the difference
180 @acronym{GNU} @command{patch} was written mainly by Larry Wall and Paul Eggert;
579 made small changes of their own to the files. @command{patch} can apply
582 lines away from where the diff says they are, @command{patch} can adjust
584 @xref{Imperfect}, for more information on using @command{patch} to apply
605 defaults to three. For proper operation, @command{patch} typically needs
763 only @acronym{GNU} @command{patch} can automatically apply diffs in this
764 format. For proper operation, @command{patch} typically needs at
1162 automatically; today, with @command{patch}, it is almost obsolete. Use the
1263 nor @command{patch} can apply diffs in this format. It exists mainly for
1703 The @command{patch} @option{-D @var{name}} option behaves like
1705 a file and a diff to produce a merged file; @xref{patch Options}.
1792 the newer directory, you can make the patch smaller by using the
1796 files that were added). At the top of the patch, write instructions for
1797 the user applying the patch to remove the files that were deleted before
1798 applying the patch. @xref{Making Patches}, for more discussion of
1869 @command{patch}, you must give @command{patch} the @option{-l} or
2497 @node Merging with patch
2498 @chapter Merging with @command{patch}
2500 @command{patch} takes comparison output produced by @command{diff} and applies
2502 version. With @command{patch}, you can distribute just the changes to a
2504 correspondents can apply @command{patch} to update their copy of the files
2505 with your changes. @command{patch} automatically determines the diff
2507 determine which file to patch. This lets your correspondents feed a
2509 @command{patch}.
2511 @command{patch} detects and warns about common problems like forward
2516 @command{patch} accepts a series of diffs in its standard input, usually
2517 separated by headers that specify which file to patch. It applies
2519 exactly match the original file, @command{patch} uses heuristics to try to
2520 patch the file as well as it can. If no approximate match can be found,
2521 @command{patch} rejects the hunk and skips to the next hunk. @command{patch}
2525 @xref{Invoking patch}, for detailed information on the options to
2526 @command{patch}.
2529 * patch Input:: Selecting the type of @command{patch} input.
2532 * Creating and Removing:: Creating and removing files with a patch.
2535 * patch Directories:: Changing directory and stripping directories.
2539 * patch Messages:: Messages and questions @command{patch} can produce.
2540 * patch and POSIX:: Conformance to the @acronym{POSIX} standard.
2541 * patch and Tradition:: @acronym{GNU} versus traditional @command{patch}.
2544 @node patch Input
2545 @section Selecting the @command{patch} Input Format
2546 @cindex @command{patch} input format
2548 @command{patch} normally determines which @command{diff} format the patch
2549 file uses by examining its contents. For patch files that contain
2551 following options to force @command{patch} to interpret the patch file as a
2553 ones that @command{patch} can understand.
2582 supported by @command{patch}, @command{patch} normally asks the user
2584 system. Patch currently supports @acronym{RCS}, ClearCase and
2586 @command{patch} also asks when the input file is read-only and matches
2592 positive, @command{patch} gets the file without asking the user; if
2593 zero, @command{patch} neither asks the user nor gets the file; and if
2594 negative, @command{patch} asks the user before getting the file. The
2597 value is zero if @command{patch} is conforming to @acronym{POSIX}, negative
2598 otherwise. @xref{patch and POSIX}.
2606 @cindex imperfect patch application
2608 @command{patch} tries to skip any leading text in the patch file,
2610 mail message directly to @command{patch}, and it should work. If the
2612 @command{patch} automatically ignores the indentation. If a context
2613 diff contains trailing carriage return on each line, @command{patch}
2617 @command{patch} automatically unencapsulates the input.
2625 * Inexact:: Helping @command{patch} find close matches.
2626 * Dry Runs:: Predicting what @command{patch} will do.
2634 or vice versa. If this happens to a patch file or an input file, the
2635 files might look the same, but @command{patch} will not be able to match
2637 @option{--ignore-white-space} option, which makes @command{patch} compare
2639 sequence of blanks in the patch file matches any nonempty sequence of
2650 patches, give @command{patch} the @option{-R} or @option{--reverse} option.
2651 @command{patch} then attempts to swap each hunk around before applying it.
2654 Often @command{patch} can guess that the patch is reversed. If the first
2655 hunk of a patch fails, @command{patch} reverses the hunk to see if it can
2656 apply it that way. If it can, @command{patch} asks you if you want to have
2657 the @option{-R} option set; if it can't, @command{patch} continues to apply
2658 the patch normally. This method cannot detect a reversed patch if it is
2663 @command{patch} notices.
2665 If you apply a patch that you have already applied, @command{patch} thinks
2666 it is a reversed patch and offers to un-apply the patch. This could be
2668 want to un-apply the patch, just answer @samp{n} to this offer and to
2670 @command{patch} process.
2673 @subsection Helping @command{patch} Find Inexact Matches
2677 For context diffs, and to a lesser extent normal diffs, @command{patch} can
2678 detect when the line numbers mentioned in the patch are incorrect, and
2679 it attempts to find the correct place to apply each hunk of the patch.
2682 the correct place, @command{patch} scans both forward and backward for a
2685 First @command{patch} looks for a place where all lines of the context
2688 @command{patch} makes another scan, ignoring the first and last line of
2698 the odds of making a faulty patch. The default fuzz factor is 2; there
2702 If @command{patch} cannot find a place to install a hunk of the patch, it
2705 format no matter what form the input patch is in. If the input is a
2708 in the patch file: they show the approximate location where @command{patch}
2713 as it completes each hunk @command{patch} tells you whether the hunk
2715 @command{patch} thinks the hunk should go. If this is different from the
2717 large offset @emph{may} indicate that @command{patch} installed a hunk in
2718 the wrong place. @command{patch} also tells you if it used a fuzz factor
2721 @command{patch} cannot tell if the line numbers are off in an @command{ed}
2728 is a pretty good indication that the patch worked, but not a guarantee.
2730 A patch against an empty file applies to a nonexistent file, and vice
2733 @command{patch} usually produces the correct results, even when it must
2735 the patch is applied to an exact copy of the file that the patch was
2739 @subsection Predicting what @command{patch} will do
2740 @cindex testing @command{patch}
2741 @cindex dry runs for @command{patch}
2743 It may not be obvious in advance what @command{patch} will do with a
2744 complicated or poorly formatted patch. If you are concerned that the
2745 input might cause @command{patch} to modify the wrong files, you can
2746 use the @option{--dry-run} option, which causes @command{patch} to
2749 to see whether @command{patch} will modify the files that you expect.
2750 If the patch does not do what you want, you can modify the patch (or
2751 the other options to @command{patch}) and try another dry run. Once
2752 you are satisfied with the proposed patch you can apply it by invoking
2753 @command{patch} as before, but this time without the
2766 Epoch (1970-01-01 00:00:00 UTC), @command{diff} outputs a patch that
2767 adds or deletes the contents of this file. When given such a patch,
2768 @command{patch} normally creates a new file or removes the old file.
2769 However, when conforming to @acronym{POSIX} (@pxref{patch and POSIX}),
2770 @command{patch} does not remove the old file, but leaves it empty.
2772 @command{patch} to remove output files that are empty after applying a
2773 patch, even if the patch does not appear to be one that removed the
2776 If the patch appears to create a file that already exists,
2777 @command{patch} asks for confirmation before applying the patch.
2783 When @command{patch} updates a file, it normally sets the file's
2785 @command{patch} to track a software distribution, this can cause
2788 @command{patch} updates @file{syntax.c} and then @file{syntax.y}, then
2792 The @option{-Z} or @option{--set-utc} option causes @command{patch} to
2807 @command{patch} normally refrains from setting a file's time stamps if
2810 match the patch. However, if the @option{-f} or @option{--force}
2814 @command{patch} cannot update the times of files whose contents have
2826 If the patch file contains more than one patch, and if you do not
2827 specify an input file on the command line, @command{patch} tries to
2828 apply each patch as if they came from separate patch files. This
2829 means that it determines the name of the file to patch for each patch,
2830 and that it examines the leading text before each patch for file names
2834 @command{patch} uses the following rules to intuit a file name from
2835 the leading text before a patch. First, @command{patch} takes an
2840 If the header is that of a context diff, @command{patch} takes the old
2848 the old and new names are both absent or if @command{patch} is
2849 conforming to @acronym{POSIX}, @command{patch} takes the name in the
2859 Then @command{patch} selects a file name from the candidate list as
2864 If some of the named files exist, @command{patch} selects the first
2868 If @command{patch} is not ignoring @acronym{RCS}, ClearCase, and @acronym{SCCS}
2870 ClearCase, or @acronym{SCCS} master is found, @command{patch} selects the
2875 was found, some names are given, @command{patch} is not conforming to
2876 @acronym{POSIX}, and the patch appears to create a file, @command{patch}
2882 the name of the file to patch, and @command{patch} selects that name.
2886 @command{patch} first takes all the names with the fewest path name
2891 @xref{patch and POSIX}, to see whether @command{patch} is conforming
2894 @node patch Directories
2896 @cindex directories and patch
2900 option to @command{patch} makes directory @var{directory} the current
2901 directory for interpreting both file names in the patch file, and file
2903 @option{-o}). For example, while in a mail reading program, you can patch
2905 containing the patch like this:
2908 | patch -d /usr/src/emacs
2911 Sometimes the file names given in a patch contain leading directories,
2913 the patch. In those cases, you can use the
2916 count tells @command{patch} how many slashes, along with the directory
2919 default, @command{patch} strips off all leading directories, leaving
2922 For example, suppose the file name in the patch file is
2928 @command{patch} looks for each file (after any slashes have been stripped)
2936 Normally, @command{patch} creates a backup file if the patch does not
2938 original data might not be recovered if you undo the patch with
2939 @samp{patch -R} (@pxref{Reversed Patches}). However, when conforming
2940 to @acronym{POSIX}, @command{patch} does not create backup files by
2941 default. @xref{patch and POSIX}.
2943 The @option{-b} or @option{--backup} option causes @command{patch} to
2944 make a backup file regardless of whether the patch matches the
2946 @command{patch} to create backup files for mismatches files; this is
2948 @option{--no-backup-if-mismatch} option causes @command{patch} to not
2960 Normally, @command{patch} renames an original input file into a backup
2963 long.@footnote{A coding error in @acronym{GNU} @command{patch} version
2966 @option{--suffix=@var{backup-suffix}} option causes @command{patch} to
2974 @command{patch} can also create numbered backup files the way
2976 single backup of each file, @command{patch} makes a new backup file
2986 control the type of backups that @command{patch} makes with the
3016 You can also tell @command{patch} to prepend a prefix, such as a
3039 @command{patch} could not find a place to apply) are normally the name
3043 Alternatively, you can tell @command{patch} to place all of the rejected
3048 @node patch Messages
3049 @section Messages and Questions from @command{patch}
3050 @cindex @command{patch} messages and questions
3051 @cindex diagnostics from @command{patch}
3052 @cindex messages from @command{patch}
3054 @command{patch} can produce a variety of messages, especially if it
3056 sure how to proceed, @command{patch} normally prompts you for more
3062 * More or Fewer Messages:: Controlling the verbosity of @command{patch}.
3063 * patch and Keyboard Input:: Inhibiting keyboard input.
3064 * patch Quoting Style:: Quoting file names in diagnostics.
3067 @command{patch} exits with status 0 if all hunks are applied successfully,
3070 exit status, so you don't apply a later patch to a partially patched
3074 @subsection Controlling the Verbosity of @command{patch}
3075 @cindex verbose messages from @command{patch}
3076 @cindex inhibit messages from @command{patch}
3078 You can cause @command{patch} to produce more messages by using the
3080 the message @samp{Hmm...} indicates that @command{patch} is reading text in
3081 the patch file, attempting to determine whether there is a patch in that
3082 text, and if so, what kind of patch it is.
3084 You can inhibit all terminal output from @command{patch}, unless an error
3088 @node patch and Keyboard Input
3090 @cindex keyboard input to @command{patch}
3092 There are two ways you can prevent @command{patch} from asking you any
3094 what you are doing. It causes @command{patch} to do the following:
3101 Patch files even though they have the wrong version for the
3102 @samp{Prereq:} line in the patch;
3119 @samp{Prereq:} line in the patch;
3125 @node patch Quoting Style
3126 @subsection @command{patch} Quoting Style
3129 When @command{patch} outputs a file name in a diagnostic message, it
3149 @c The following are not yet implemented in patch 2.5.4.
3163 but this default may change in a future version of @command{patch}.
3165 @node patch and POSIX
3166 @section @command{patch} and the @acronym{POSIX} Standard
3171 @env{POSIXLY_CORRECT} environment variable, @command{patch} conforms
3195 @node patch and Tradition
3196 @section @acronym{GNU} @command{patch} and Traditional @command{patch}
3197 @cindex traditional @command{patch}
3199 The current version of @acronym{GNU} @command{patch} normally follows the
3200 @acronym{POSIX} standard. @xref{patch and POSIX}, for the few exceptions
3203 Unfortunately, @acronym{POSIX} redefined the behavior of @command{patch} in
3205 differences if you must interoperate with traditional @command{patch},
3206 or with @acronym{GNU} @command{patch} version 2.1 and earlier.
3210 In traditional @command{patch}, the @option{-p} option's operand was
3216 Also, traditional @command{patch} simply counted slashes when
3217 stripping path prefixes; @command{patch} now counts pathname
3223 In traditional @command{patch}, backups were enabled by default. This
3227 Conversely, in @acronym{POSIX} @command{patch}, backups are never made,
3228 even when there is a mismatch. In @acronym{GNU} @command{patch}, this
3232 The @option{-b@ @var{suffix}} option of traditional @command{patch} is
3234 @command{patch}.
3237 Traditional @command{patch} used a complicated (and incompletely
3239 the patch header. This method did not conform to @acronym{POSIX}, and had
3240 a few gotchas. Now @command{patch} uses a different, equally
3245 patch is normally compatible if each header's file names all contain
3249 When traditional @command{patch} asked the user a question, it sent
3253 @command{patch} sends questions to standard output and gets answers
3255 that @command{patch} never goes into an infinite loop when using
3259 Traditional @command{patch} exited with a status value that counted
3261 Now @command{patch} exits with status 1 if some hunks failed, or with
3266 meant to be executed by anyone running @acronym{GNU} @command{patch},
3267 traditional @command{patch}, or a @command{patch} that conforms to
3293 harder-to-digest patch that covers all the subjects.
3299 * Tips for Patch Producers:: Advice for making patches.
3300 * Tips for Patch Consumers:: Advice for using patches.
3301 * Avoiding Common Mistakes:: Avoiding common mistakes when using @command{patch}.
3305 @node Tips for Patch Producers
3306 @section Tips for Patch Producers
3307 @cindex patch producer tips
3309 To create a patch that changes an older version of a package into a
3314 To generate the patch, use the command @samp{diff -Naur @var{old}
3317 slashes. The @option{-N} option lets the patch create and remove
3318 files; @option{-a} lets the patch update non-text files; @option{-u}
3320 the patch update subdirectories. Here is an example command, using
3328 which working directory to use, and which @command{patch} options to
3334 generating a patch.
3336 @node Tips for Patch Consumers
3337 @section Tips for Patch Consumers
3338 @cindex patch consumer tips
3340 A patch producer should tell recipients how to apply the patches, so
3341 the first rule of thumb for a patch consumer is to follow the
3342 instructions supplied with the patch.
3346 @command{patch} cannot patch such files. If you are having trouble
3348 @command{patch}.
3353 @cindex patch, common mistakes
3355 When producing a patch for multiple files, apply @command{diff} to
3357 when the patch consumer specifies the @option{-p@var{number}} option,
3360 send a patch with a header that looks like this:
3370 different versions of @command{patch} interpret the file names
3383 already applied the patch.
3387 @command{patch} into patching a backup file instead of the real file.
3391 To save people from partially applying a patch before other patches that
3392 should have gone before it, you can make the first patch in the patch
3394 @file{version.c}, which contains a patch level or version number. If
3395 the input file contains the wrong version number, @command{patch} will
3399 line before the patch. If the leading text in the patch file contains a
3400 line that starts with @samp{Prereq:}, @command{patch} takes the next word
3403 white space or a newline. If not, @command{patch} prompts you for
3411 The simplest way to generate a patch is to use @samp{diff -Naur}
3412 (@pxref{Tips for Patch Producers}), but you might be able to reduce
3413 the size of the patch by renaming or removing some files before making
3414 the patch. If the older version of the package contains any files
3418 applying the patch. Then run those commands yourself in the scratch
3421 If there are any files that you don't need to include in the patch
3424 exclude them from the patch by giving @command{diff} the @option{-x
3426 your patch to modify a derived file because your recipients lack tools
3427 to build it, make sure that the patch for the derived file follows any
3431 Now you can create the patch using @samp{diff -Naur}. Make sure to
3434 Add to the top of the patch a note telling the user any @command{rm} and
3435 @command{mv} commands to run before applying the patch. Then you can
3438 You can also shrink the patch size by using fewer lines of context,
3439 but bear in mind that @command{patch} typically needs at least two
3712 For proper operation, @command{patch} typically needs at least two lines of
3898 For proper operation, @command{patch} typically needs at least two lines of
4057 @node Invoking patch
4058 @chapter Invoking @command{patch}
4059 @cindex invoking @command{patch}
4060 @cindex @command{patch} invocation
4062 Normally @command{patch} is invoked like this:
4065 patch <@var{patchfile}
4068 The full format for invoking @command{patch} is:
4071 patch @var{options}@dots{} @r{[}@var{origfile} @r{[}@var{patchfile}@r{]}@r{]}
4074 You can also specify where to read the patch from with the @option{-i
4077 @file{-}, @command{patch} reads the patch (that is, the @command{diff} output)
4080 If you do not specify an input file on the command line, @command{patch}
4081 tries to intuit from the @dfn{leading text} (any text in the patch
4085 By default, @command{patch} replaces the original input file with the
4088 @command{patch} names backup files). You can also specify where to
4094 * patch Options:: Summary table of options to @command{patch}.
4097 @node patch Options
4098 @section Options to @command{patch}
4099 @cindex @command{patch} options
4100 @cindex options for @command{patch}
4102 Here is a summary of all of the options that @acronym{GNU} @command{patch}
4103 accepts. @xref{patch and Tradition}, for which of these options are
4104 safe to use in older versions of @command{patch}.
4120 Back up the original contents of each file if the patch does not
4128 this option makes a difference, the patch should be generated by
4133 Interpret the patch file as a context diff. @xref{patch Input}.
4138 both file names in the patch file, and file names given as arguments to
4139 other options. @xref{patch Directories}.
4151 Interpret the patch file as an @command{ed} script. @xref{patch Input}.
4161 ask any questions. @xref{patch Messages}.
4178 Read the patch from @var{patchfile} rather than from standard input.
4179 @xref{patch Options}.
4183 Let any sequence of blanks (spaces or tabs) in the patch file match
4188 Interpret the patch file as a normal diff. @xref{patch Input}.
4192 Ignore patches that @command{patch} thinks are reversed or already applied.
4201 Use @var{file} as the output file name. @xref{patch Options}.
4205 Set the file name strip count to @var{number}. @xref{patch Directories}.
4209 variable had been set. @xref{patch and POSIX}.
4214 @xref{patch Quoting Style}.
4222 Assume that this patch was created with the old and new files swapped.
4228 Work silently unless an error occurs. @xref{patch Messages}.
4232 Do not ask any questions. @xref{patch Messages}.
4242 Interpret the patch file as a unified diff. @xref{patch Input}.
4253 Print more diagnostics than usual. @xref{patch Messages}.
4257 Set internal debugging flags. Of interest only to @command{patch}
4455 @command{patch}. The @acronym{GNU} project has identified some
4470 @section Suggested Projects for Improving @acronym{GNU} @command{diff} and @command{patch}
4474 patch from any pair of directory trees, and given the patch and a copy
4475 of one such tree, use @command{patch} to generate a faithful copy of
4477 expressed using current patch formats; also, @command{patch} does not
4511 ….software.ibm.com/developer/opensource/linux/patches/i18n/diffutils-2.7.2-i18n-0.1.patch.gz,patches
4520 @command{diff} and @command{patch} do not handle some changes to directory
4524 information for @command{patch} to transform the directory subtree into
4528 having to include its entire contents in the patch file. There should
4529 also be a way to tell @command{patch} that a file was renamed, even if
4531 There should be a way to tell @command{patch} that a file's time stamp
4535 to represent changes in directory structure, and extending @command{patch}
4550 that @command{patch} cannot represent changes to such files. For
4558 and @command{patch} should be extended to understand these extensions.
4565 white space, @samp{diff -r} generates a patch that @command{patch} cannot
4567 @command{patch}, because with odd enough file names one can cause
4568 @command{diff} to generate a patch that is syntactically correct but
4575 Applying @command{patch} to a multiple-file diff can result in files
4576 whose time stamps are out of order. @acronym{GNU} @command{patch} has
4579 a patch that works even if the recipient does not have @acronym{GNU} patch,
4623 bug reports for @acronym{GNU} @command{patch} to
4624 @email{bug-patch@@gnu.org}. Send as precise a description of the
4628 have a patch, please send it too. It may simplify the maintainer's
4629 job if the patch is relative to a recent test release, which you can