Lines Matching refs:patch
16 differences between files and the @sc{gnu} @command{patch} command for
44 * patch: (diff)Invoking patch. Apply a patch to a file.
55 @subtitle for Diffutils @value{VERSION} and @code{patch} 2.5.4
88 * Merging with patch:: Using @command{patch} to change old files into new ones.
89 * Making Patches:: Tips for making and using patch distributions.
94 * 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
172 @command{patch} was written mainly by Larry Wall and Paul Eggert;
652 made small changes of their own to the files. @command{patch} can apply
655 lines away from where the diff says they are, @command{patch} can adjust
657 @xref{Imperfect}, for more information on using @command{patch} to apply
678 defaults to three. For proper operation, @command{patch} typically needs
830 only @sc{gnu} @command{patch} can automatically apply diffs in this
831 format. For proper operation, @command{patch} typically needs at
1127 automatically; today, with @command{patch}, it is almost obsolete. Use the
1227 nor @command{patch} can apply diffs in this format. It exists mainly for
1635 The @command{patch} @option{-D @var{name}} option behaves like
1637 a file and a diff to produce a merged file; @xref{patch Options}.
1755 the newer directory, you can make the patch smaller by using the
1759 files that were added). At the top of the patch, write instructions for
1760 the user applying the patch to remove the files that were deleted before
1761 applying the patch. @xref{Making Patches}, for more discussion of
1831 @command{patch}, you must give @command{patch} the @option{-l} or
2450 @node Merging with patch
2451 @chapter Merging with @command{patch}
2453 @command{patch} takes comparison output produced by @command{diff} and applies
2455 version. With @command{patch}, you can distribute just the changes to a
2457 correspondents can apply @command{patch} to update their copy of the files
2458 with your changes. @command{patch} automatically determines the diff
2460 determine which file to patch. This lets your correspondents feed a
2462 @command{patch}.
2464 @command{patch} detects and warns about common problems like forward
2469 @command{patch} accepts a series of diffs in its standard input, usually
2470 separated by headers that specify which file to patch. It applies
2472 exactly match the original file, @command{patch} uses heuristics to try to
2473 patch the file as well as it can. If no approximate match can be found,
2474 @command{patch} rejects the hunk and skips to the next hunk. @command{patch}
2478 @xref{Invoking patch}, for detailed information on the options to
2479 @command{patch}.
2482 * patch Input:: Selecting the type of @command{patch} input.
2485 * Creating and Removing:: Creating and removing files with a patch.
2488 * patch Directories:: Changing directory and stripping directories.
2492 * patch Messages:: Messages and questions @command{patch} can produce.
2493 * patch and POSIX:: Conformance to the @sc{posix} standard.
2494 * patch and Tradition:: @sc{gnu} versus traditional @command{patch}.
2497 @node patch Input
2498 @section Selecting the @command{patch} Input Format
2499 @cindex @command{patch} input format
2501 @command{patch} normally determines which @command{diff} format the patch
2502 file uses by examining its contents. For patch files that contain
2504 following options to force @command{patch} to interpret the patch file as a
2506 ones that @command{patch} can understand.
2535 supported by @command{patch}, @command{patch} normally asks the user
2538 Under @sc{rcs} and @sc{sccs}, @command{patch} also asks when the input
2545 positive, @command{patch} gets the file without asking the user; if
2546 zero, @command{patch} neither asks the user nor gets the file; and if
2547 negative, @command{patch} asks the user before getting the file. The
2550 value is zero if @command{patch} is conforming to @sc{posix}, negative
2551 otherwise. @xref{patch and POSIX}.
2559 @cindex imperfect patch application
2561 @command{patch} tries to skip any leading text in the patch file,
2563 mail message directly to @command{patch}, and it should work. If the
2565 @command{patch} automatically ignores the indentation. If a context
2566 diff contains trailing carriage return on each line, @command{patch}
2570 @command{patch} automatically unencapsulates the input.
2578 * Inexact:: Helping @command{patch} find close matches.
2579 * Dry Runs:: Predicting what @command{patch} will do.
2587 or vice versa. If this happens to a patch file or an input file, the
2588 files might look the same, but @command{patch} will not be able to match
2590 @option{--ignore-white-space} option, which makes @command{patch} compare
2592 sequence of blanks in the patch file matches any nonempty sequence of
2603 patches, give @command{patch} the @option{-R} or @option{--reverse} option.
2604 @command{patch} then attempts to swap each hunk around before applying it.
2607 Often @command{patch} can guess that the patch is reversed. If the first
2608 hunk of a patch fails, @command{patch} reverses the hunk to see if it can
2609 apply it that way. If it can, @command{patch} asks you if you want to have
2610 the @option{-R} option set; if it can't, @command{patch} continues to apply
2611 the patch normally. This method cannot detect a reversed patch if it is
2616 @command{patch} notices.
2618 If you apply a patch that you have already applied, @command{patch} thinks
2619 it is a reversed patch and offers to un-apply the patch. This could be
2621 want to un-apply the patch, just answer @samp{n} to this offer and to
2623 @command{patch} process.
2626 @subsection Helping @command{patch} Find Inexact Matches
2630 For context diffs, and to a lesser extent normal diffs, @command{patch} can
2631 detect when the line numbers mentioned in the patch are incorrect, and
2632 it attempts to find the correct place to apply each hunk of the patch.
2635 the correct place, @command{patch} scans both forward and backward for a
2638 First @command{patch} looks for a place where all lines of the context
2641 @command{patch} makes another scan, ignoring the first and last line of
2651 the odds of making a faulty patch. The default fuzz factor is 2; there
2655 If @command{patch} cannot find a place to install a hunk of the patch, it
2658 format no matter what form the input patch is in. If the input is a
2661 in the patch file: they show the approximate location where @command{patch}
2666 as it completes each hunk @command{patch} tells you whether the hunk
2668 @command{patch} thinks the hunk should go. If this is different from the
2670 large offset @emph{may} indicate that @command{patch} installed a hunk in
2671 the wrong place. @command{patch} also tells you if it used a fuzz factor
2674 @command{patch} cannot tell if the line numbers are off in an @command{ed}
2681 is a pretty good indication that the patch worked, but not a guarantee.
2683 A patch against an empty file applies to a nonexistent file, and vice
2686 @command{patch} usually produces the correct results, even when it must
2688 the patch is applied to an exact copy of the file that the patch was
2692 @subsection Predicting what @command{patch} will do
2693 @cindex testing @command{patch}
2694 @cindex dry runs for @command{patch}
2696 It may not be obvious in advance what @command{patch} will do with a
2697 complicated or poorly formatted patch. If you are concerned that the
2698 input might cause @command{patch} to modify the wrong files, you can
2699 use the @option{--dry-run} option, which causes @command{patch} to
2702 to see whether @command{patch} will modify the files that you expect.
2703 If the patch does not do what you want, you can modify the patch (or
2704 the other options to @command{patch}) and try another dry run. Once
2705 you are satisfied with the proposed patch you can apply it by invoking
2706 @command{patch} as before, but this time without the
2719 Epoch (1970-01-01 00:00:00 UTC), @command{diff} outputs a patch that
2720 adds or deletes the contents of this file. When given such a patch,
2721 @command{patch} normally creates a new file or removes the old file.
2722 However, when conforming to @sc{posix} (@pxref{patch and POSIX}),
2723 @command{patch} does not remove the old file, but leaves it empty.
2725 @command{patch} to remove output files that are empty after applying a
2726 patch, even if the patch does not appear to be one that removed the
2729 If the patch appears to create a file that already exists,
2730 @command{patch} asks for confirmation before applying the patch.
2736 When @command{patch} updates a file, it normally sets the file's
2738 @command{patch} to track a software distribution, this can cause
2741 @command{patch} updates @file{syntax.c} and then @file{syntax.y}, then
2745 The @option{-Z} or @option{--set-utc} option causes @command{patch} to
2760 @command{patch} normally refrains from setting a file's time stamps if
2763 match the patch. However, if the @option{-f} or @option{--force}
2767 @command{patch} cannot update the times of files whose contents have
2779 If the patch file contains more than one patch, and if you do not
2780 specify an input file on the command line, @command{patch} tries to
2781 apply each patch as if they came from separate patch files. This
2782 means that it determines the name of the file to patch for each patch,
2783 and that it examines the leading text before each patch for file names
2787 @command{patch} uses the following rules to intuit a file name from
2788 the leading text before a patch. First, @command{patch} takes an
2793 If the header is that of a context diff, @command{patch} takes the old
2801 the old and new names are both absent or if @command{patch} is
2802 conforming to @sc{posix}, @command{patch} takes the name in the
2812 Then @command{patch} selects a file name from the candidate list as
2817 If some of the named files exist, @command{patch} selects the first
2821 If @command{patch} is not ignoring @sc{rcs}, ClearCase, and @sc{sccs}
2823 ClearCase, or @sc{sccs} master is found, @command{patch} selects the
2828 was found, some names are given, @command{patch} is not conforming to
2829 @sc{posix}, and the patch appears to create a file, @command{patch}
2835 the name of the file to patch, and @command{patch} selects that name.
2839 @command{patch} first takes all the names with the fewest path name
2844 @xref{patch and POSIX}, to see whether @command{patch} is conforming
2847 @node patch Directories
2849 @cindex directories and patch
2853 option to @command{patch} makes directory @var{directory} the current
2854 directory for interpreting both file names in the patch file, and file
2856 @option{-o}). For example, while in a mail reading program, you can patch
2858 containing the patch like this:
2861 | patch -d /usr/src/emacs
2864 Sometimes the file names given in a patch contain leading directories,
2866 the patch. In those cases, you can use the
2869 count tells @command{patch} how many slashes, along with the directory
2872 default, @command{patch} strips off all leading directories, leaving
2875 For example, suppose the file name in the patch file is
2881 @command{patch} looks for each file (after any slashes have been stripped)
2889 Normally, @command{patch} creates a backup file if the patch does not
2891 original data might not be recovered if you undo the patch with
2892 @samp{patch -R} (@pxref{Reversed Patches}). However, when conforming
2893 to @sc{posix}, @command{patch} does not create backup files by
2894 default. @xref{patch and POSIX}.
2896 The @option{-b} or @option{--backup} option causes @command{patch} to
2897 make a backup file regardless of whether the patch matches the
2899 @command{patch} to create backup files for mismatches files; this is
2901 @option{--no-backup-if-mismatch} option causes @command{patch} to not
2913 Normally, @command{patch} renames an original input file into a backup
2916 long.@footnote{A coding error in @sc{gnu} @command{patch} version
2919 @option{--suffix=@var{backup-suffix}} option causes @command{patch} to
2927 @command{patch} can also create numbered backup files the way @sc{gnu} Emacs
2929 @command{patch} makes a new backup file name each time it patches a file.
2938 control the type of backups that @command{patch} makes with the
2968 You can also tell @command{patch} to prepend a prefix, such as a
2991 @command{patch} could not find a place to apply) are normally the name
2995 Alternatively, you can tell @command{patch} to place all of the rejected
3000 @node patch Messages
3001 @section Messages and Questions from @command{patch}
3002 @cindex @command{patch} messages and questions
3003 @cindex diagnostics from @command{patch}
3004 @cindex messages from @command{patch}
3006 @command{patch} can produce a variety of messages, especially if it
3008 sure how to proceed, @command{patch} normally prompts you for more
3014 * More or Fewer Messages:: Controlling the verbosity of @command{patch}.
3015 * patch and Keyboard Input:: Inhibiting keyboard input.
3016 * patch Quoting Style:: Quoting file names in diagnostics.
3019 @command{patch} exits with status 0 if all hunks are applied successfully,
3022 exit status, so you don't apply a later patch to a partially patched
3026 @subsection Controlling the Verbosity of @command{patch}
3027 @cindex verbose messages from @command{patch}
3028 @cindex inhibit messages from @command{patch}
3030 You can cause @command{patch} to produce more messages by using the
3032 the message @samp{Hmm...} indicates that @command{patch} is reading text in
3033 the patch file, attempting to determine whether there is a patch in that
3034 text, and if so, what kind of patch it is.
3036 You can inhibit all terminal output from @command{patch}, unless an error
3040 @node patch and Keyboard Input
3042 @cindex keyboard input to @command{patch}
3044 There are two ways you can prevent @command{patch} from asking you any
3046 what you are doing. It causes @command{patch} to do the following:
3054 @samp{Prereq:} line in the patch;
3071 @samp{Prereq:} line in the patch;
3077 @node patch Quoting Style
3078 @subsection @command{patch} Quoting Style
3081 When @command{patch} outputs a file name in a diagnostic message, it
3101 @c The following are not yet implemented in patch 2.5.4.
3115 but this default may change in a future version of @command{patch}.
3117 @node patch and POSIX
3118 @section @command{patch} and the @sc{posix} Standard
3123 @env{POSIXLY_CORRECT} environment variable, @command{patch} conforms
3147 @node patch and Tradition
3148 @section @sc{gnu} @command{patch} and Traditional @command{patch}
3149 @cindex traditional @command{patch}
3151 The current version of @sc{gnu} @command{patch} normally follows the
3152 @sc{posix} standard. @xref{patch and POSIX}, for the few exceptions
3155 Unfortunately, @sc{posix} redefined the behavior of @command{patch} in
3157 differences if you must interoperate with traditional @command{patch},
3158 or with @sc{gnu} @command{patch} version 2.1 and earlier.
3162 In traditional @command{patch}, the @option{-p} option's operand was
3168 Also, traditional @command{patch} simply counted slashes when
3169 stripping path prefixes; @command{patch} now counts pathname
3175 In traditional @command{patch}, backups were enabled by default. This
3179 Conversely, in @sc{posix} @command{patch}, backups are never made,
3180 even when there is a mismatch. In @sc{gnu} @command{patch}, this
3184 The @option{-b@ @var{suffix}} option of traditional @command{patch} is
3186 @command{patch}.
3189 Traditional @command{patch} used a complicated (and incompletely
3191 the patch header. This method did not conform to @sc{posix}, and had
3192 a few gotchas. Now @command{patch} uses a different, equally
3197 patch is normally compatible if each header's file names all contain
3201 When traditional @command{patch} asked the user a question, it sent
3205 @command{patch} sends questions to standard output and gets answers
3207 that @command{patch} never goes into an infinite loop when using
3211 Traditional @command{patch} exited with a status value that counted
3213 Now @command{patch} exits with status 1 if some hunks failed, or with
3218 meant to be executed by anyone running @sc{gnu} @command{patch},
3219 traditional @command{patch}, or a @command{patch} that conforms to
3245 harder-to-digest patch that covers all the subjects.
3253 * Avoiding Common Mistakes:: Avoiding common mistakes when using @command{patch}.
3259 @cindex patch producer tips
3261 To create a patch that changes an older version of a package into a
3266 To generate the patch, use the command @samp{diff -Naur @var{old}
3269 slashes. The @option{-N} option lets the patch create and remove
3270 files; @option{-a} lets the patch update non-text files; @option{-u}
3272 the patch update subdirectories. Here is an example command, using
3280 which working directory to use, and which @command{patch} options to
3286 generating a patch.
3290 @cindex patch consumer tips
3292 A patch producer should tell recipients how to apply the patches, so
3293 the first rule of thumb for a patch consumer is to follow the
3294 instructions supplied with the patch.
3298 @command{patch} cannot patch such files. If you are having trouble
3300 @command{patch}.
3305 @cindex patch, common mistakes
3307 When producing a patch for multiple files, apply @command{diff} to
3309 when the patch consumer specifies the @option{-p@var{number}} option,
3312 send a patch with a header that looks like this:
3322 different versions of @command{patch} interpret the file names
3335 already applied the patch.
3339 @command{patch} into patching a backup file instead of the real file.
3343 To save people from partially applying a patch before other patches that
3344 should have gone before it, you can make the first patch in the patch
3346 @file{version.c}, which contains a patch level or version number. If
3347 the input file contains the wrong version number, @command{patch} will
3351 line before the patch. If the leading text in the patch file contains a
3352 line that starts with @samp{Prereq:}, @command{patch} takes the next word
3355 white space or a newline. If not, @command{patch} prompts you for
3363 The simplest way to generate a patch is to use @samp{diff -Naur}
3365 the size of the patch by renaming or removing some files before making
3366 the patch. If the older version of the package contains any files
3370 applying the patch. Then run those commands yourself in the scratch
3373 If there are any files that you don't need to include in the patch
3376 exclude them from the patch by giving @command{diff} the @option{-x
3378 your patch to modify a derived file because your recipients lack tools
3379 to build it, make sure that the patch for the derived file follows any
3383 Now you can create the patch using @samp{diff -Naur}. Make sure to
3386 Add to the top of the patch a note telling the user any @command{rm} and
3387 @command{mv} commands to run before applying the patch. Then you can
3390 You can also shrink the patch size by using fewer lines of context,
3391 but bear in mind that @command{patch} typically needs at least two
3640 For proper operation, @command{patch} typically needs at least two lines of
3822 For proper operation, @command{patch} typically needs at least two lines of
3977 @node Invoking patch
3978 @chapter Invoking @command{patch}
3979 @cindex invoking @command{patch}
3980 @cindex @command{patch} invocation
3982 Normally @command{patch} is invoked like this:
3985 patch <@var{patchfile}
3988 The full format for invoking @command{patch} is:
3991 patch @var{options}@dots{} @r{[}@var{origfile} @r{[}@var{patchfile}@r{]}@r{]}
3994 You can also specify where to read the patch from with the @option{-i
3997 @file{-}, @command{patch} reads the patch (that is, the @command{diff} output)
4000 If you do not specify an input file on the command line, @command{patch}
4001 tries to intuit from the @dfn{leading text} (any text in the patch
4005 By default, @command{patch} replaces the original input file with the
4008 @command{patch} names backup files). You can also specify where to
4014 * patch Options:: Summary table of options to @command{patch}.
4017 @node patch Options
4018 @section Options to @command{patch}
4019 @cindex @command{patch} options
4020 @cindex options for @command{patch}
4022 Here is a summary of all of the options that @sc{gnu} @command{patch}
4023 accepts. @xref{patch and Tradition}, for which of these options are
4024 safe to use in older versions of @command{patch}.
4040 Back up the original contents of each file if the patch does not
4048 this option makes a difference, the patch should be generated by
4053 Interpret the patch file as a context diff. @xref{patch Input}.
4058 both file names in the patch file, and file names given as arguments to
4059 other options. @xref{patch Directories}.
4071 Interpret the patch file as an @command{ed} script. @xref{patch Input}.
4081 ask any questions. @xref{patch Messages}.
4098 Read the patch from @var{patchfile} rather than from standard input.
4099 @xref{patch Options}.
4103 Let any sequence of blanks (spaces or tabs) in the patch file match
4108 Interpret the patch file as a normal diff. @xref{patch Input}.
4112 Ignore patches that @command{patch} thinks are reversed or already applied.
4121 Use @var{file} as the output file name. @xref{patch Options}.
4125 Set the file name strip count to @var{number}. @xref{patch Directories}.
4129 variable had been set. @xref{patch and POSIX}.
4134 @xref{patch Quoting Style}.
4142 Assume that this patch was created with the old and new files swapped.
4148 Work silently unless an error occurs. @xref{patch Messages}.
4152 Do not ask any questions. @xref{patch Messages}.
4162 Interpret the patch file as a unified diff. @xref{patch Input}.
4173 Print more diagnostics than usual. @xref{patch Messages}.
4177 Set internal debugging flags. Of interest only to @command{patch}
4370 @command{patch}. The @sc{gnu} project has identified some
4385 @section Suggested Projects for Improving @sc{gnu} @command{diff} and @command{patch}
4388 One should be able to use @sc{gnu} @command{diff} to generate a patch from any
4389 pair of directory trees, and given the patch and a copy of one such
4390 tree, use @command{patch} to generate a faithful copy of the other.
4392 current patch formats; also, @command{patch} does not handle some of the
4426 …://oss.software.ibm.com/developer/opensource/linux/patches/i18n/diffutils-2.7.2-i18n-0.1.patch.gz}.
4434 @command{diff} and @command{patch} do not handle some changes to directory
4438 information for @command{patch} to transform the directory subtree into
4442 having to include its entire contents in the patch file. There should
4443 also be a way to tell @command{patch} that a file was renamed, even if
4445 There should be a way to tell @command{patch} that a file's time stamp
4449 to represent changes in directory structure, and extending @command{patch}
4461 directories. This means that @command{patch} cannot represent changes
4469 and @command{patch} should be extended to understand these extensions.
4476 white space, @samp{diff -r} generates a patch that @command{patch} cannot
4478 @command{patch}, because with odd enough file names one can cause
4479 @command{diff} to generate a patch that is syntactically correct but
4486 Applying @command{patch} to a multiple-file diff can result in files
4487 whose time stamps are out of order. @sc{gnu} @command{patch} has
4490 a patch that works even if the recipient does not have @sc{gnu} patch,
4534 bug reports for @sc{gnu} @command{patch} to
4535 @email{bug-patch@@gnu.org}. Send as precise a description of the
4539 have a patch, please send it too. It may simplify the maintainer's
4540 job if the patch is relative to a recent test release, which you can