Seth Woolley's Man Viewer

patch(1) - patch - apply a diff file to an original - man 1 patch

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

PATCH(1)                                                              PATCH(1)

       patch - apply a diff file(1,n) to an original

       patch [options] [originalfile [patchfile]]

       but usually just

       patch -pnum <patchfile

       patch takes a patch file(1,n) patchfile containing a difference listing pro-
       duced by the diff program and applies those differences to one or  more
       original  files, producing patched versions.  Normally the patched ver-
       sions are put in(1,8) place of the originals.  Backups can be made; see  the
       -b  or  --backup option.  The names of the files to be patched are usu-
       ally taken from the patch file(1,n), but if(3,n) there's  just  one  file(1,n)  to  be
       patched it can specified on the command line as originalfile.

       Upon startup, patch attempts to determine the type of the diff listing,
       unless overruled by a -c (--context), -e (--ed), -n (--normal),  or  -u
       (--unified)  option.  Context diffs (old-style, new-style, and unified)
       and normal diffs are applied by the  patch  program  itself,  while  ed
       diffs are simply fed to the ed(1) editor via a pipe.

       patch  tries to skip any leading garbage, apply the diff, and then skip
       any trailing garbage.  Thus you could feed an article or  message  con-
       taining  a  diff  listing  to patch, and it should work.  If the entire
       diff is indented by a consistent amount, or if(3,n) a context diff  contains
       lines ending in(1,8) CRLF or is encapsulated one or more times by prepending
       "- " to lines starting with "-" as specified by Internet RFC 934,  this
       is taken into account.

       With context diffs, and to a lesser extent with normal diffs, patch can
       detect when the line numbers mentioned in(1,8) the patch are incorrect,  and
       attempts to find the correct place to apply each hunk of the patch.  As
       a first guess, it takes the line number mentioned for the hunk, plus or
       minus  any  offset  used in(1,8) applying the previous hunk.  If that is not
       the correct place, patch scans both forwards and backwards for a set(7,n,1 builtins) of
       lines  matching the context given in(1,8) the hunk.  First patch looks for a
       place where all lines of the context match.  If no such place is found,
       and  it's  a  context  diff, and the maximum fuzz factor(1,6) is set(7,n,1 builtins) to 1 or
       more, then another scan takes place ignoring the first and last line of
       context.   If  that  fails,  and the maximum fuzz factor(1,6) is set(7,n,1 builtins) to 2 or
       more, the first two and last two lines  of  context  are  ignored,  and
       another  scan  is  made.   (The  default maximum fuzz factor(1,6) is 2.)  If
       patch cannot find a place to install that hunk of the  patch,  it  puts(3,n)
       the hunk out to a reject file(1,n), which normally is the name of the output
       file(1,n) plus a .rej suffix, or # if(3,n) .rej would generate a file(1,n)  name  that
       is  too  long  (if(3,n) even appending the single character # makes the file(1,n)
       name too long, then # replaces the file(1,n) name's last  character).   (The
       rejected hunk comes out in(1,8) ordinary context diff form regardless of the
       input patch's form.  If the input was a normal diff, many of  the  con-
       texts  are  simply  null.)  The line numbers on the hunks in(1,8) the reject
       file(1,n) may be different than in(1,8) the patch file: they reflect the approxi-
       mate  location  patch  thinks  the  failed hunks belong in(1,8) the new file(1,n)
       rather than the old one.

       As each hunk is completed, you are told if(3,n) the hunk failed, and  if(3,n)  so
       which  line  (in(1,8) the new file(1,n)) patch thought the hunk should go on.  If
       the hunk is installed at a different line from the line  number  speci-
       fied  in(1,8)  the  diff you are told the offset.  A single large offset may
       indicate that a hunk was installed in(1,8) the wrong place.   You  are  also
       told  if(3,n)  a  fuzz  factor(1,6) was used to make the match, in(1,8) which case you
       should also be slightly suspicious.  If the --verbose option is  given,
       you are also told about hunks that match exactly.

       If  no  original  file(1,n) origfile is specified on the command line, patch
       tries to figure out from the leading garbage what the name of the  file(1,n)
       to edit is, using the following rules.

       First, patch takes an ordered list of candidate file(1,n) names as follows:

         If the header is that of a context diff, patch takes the old and new
          file(1,n) names in(1,8) the header.  A name is ignored if(3,n)  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(1,8) the leading garbage and if(3,n) either  the
          old  and  new  names  are  both  absent or if(3,n) patch is conforming to
          POSIX, patch takes the name in(1,8) the Index: line.

         For the purpose of the following rules, the candidate file(1,n) names are
          considered  to  be in(1,8) the order (old, new, index), regardless of the
          order that they appear in(1,8) the header.

       Then patch selects a file(1,n) name from the candidate list as follows:

         If some of the named(5,8) files exist, patch selects the  first  name  if(3,n)
          conforming to POSIX, and the best name otherwise.

         If patch is not ignoring RCS, ClearCase, and SCCS (see the -g num or
          --get=num option), and no named(5,8) files exist but an  RCS,  ClearCase,
          or  SCCS master(5,8) is found, patch selects the first named(5,8) file(1,n) with an
          RCS, ClearCase, or SCCS master.

         If no named(5,8) files exist, no  RCS,  ClearCase,  or  SCCS  master(5,8)  was
          found,  some  names are given, patch is not conforming to POSIX, and
          the patch appears to create a file(1,n),  patch  selects  the  best  name
          requiring the creation of the fewest directories.

         If no file(1,n) name results from the above heuristics, you are asked for
          the name of the file(1,n) to patch, and patch selects that name.

       To determine the best of a nonempty list of  file(1,n)  names,  patch  first
       takes  all the names with the fewest path name components; of those, it
       then takes all the names with the shortest basename(1,3,3 File::Basename); of those, it  then
       takes  all  the  shortest  names; finally, it takes the first remaining

       Additionally, if(3,n) the leading garbage contains  a  Prereq:  line,  patch
       takes  the  first  word from the prerequisites line (normally a version(1,3,5)
       number) and checks the original file(1,n) to see if(3,n) that word can be  found.
       If not, patch asks for confirmation before proceeding.

       The  upshot  of  all this is that you should be able to say, while in(1,8) a
       news interface, something like the following:

          | patch -d /usr/src/local/blurfl

       and patch a file(1,n) in(1,8) the blurfl directory directly from the article con-
       taining the patch.

       If  the  patch  file(1,n) contains more than one patch, patch tries to apply
       each of them as if(3,n) they came from separate patch  files.   This  means,
       among  other  things,  that  it is assumed that the name of the file(1,n) to
       patch must be determined for each diff listing, and  that  the  garbage
       before each diff listing contains interesting things such as file(1,n) names
       and revision level, as mentioned previously.

       -b  or  --backup
          Make backup files.  That is, when patching a file(1,n),  rename(1,2,n)  or  copy
          the  original  instead  of removing it.  When backing up a file(1,n) that
          does not exist, an empty, unreadable backup file(1,n)  is  created  as  a
          placeholder to represent the nonexistent file.  See the -V or --ver-
          sion-control option for details about  how  backup  file(1,n)  names  are

          Back  up  a file(1,n) if(3,n) the patch does not match the file(1,n) exactly and if(3,n)
          backups are not otherwise requested.  This  is  the  default  unless
          patch is conforming to POSIX.

          Do  not  back up a file(1,n) if(3,n) the patch does not match the file(1,n) exactly
          and if(3,n) backups are not otherwise requested.  This is the default  if(3,n)
          patch is conforming to POSIX.

       -B pref  or  --prefix=pref
          Prefix  pref  to  a file(1,n) name when generating its simple backup file(1,n)
          name.  For example, with -B /junk/ the simple backup file(1,n)  name  for
          src/patch/util.c is /junk/src/patch/util.c.

          Read  and write(1,2) all files in(1,8) binary mode, except for standard output
          and /dev/tty(1,4).  This option has no effect  on  POSIX-conforming  sys-
          tems.  On systems like DOS where this option makes a difference, the
          patch should be generated by diff -a --binary.

       -c  or  --context
          Interpret the patch file(1,n) 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.

          Print the results of applying the patches without actually  changing
          any files.

       -e  or  --ed
          Interpret the patch file(1,n) 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 exam-
          ine the time(1,2,n) stamps on the header to determine whether a file(1,n) should
          exist after patching.  However, if(3,n) the input is not a  context  diff
          or  if(3,n)  patch  is  conforming  to POSIX, patch does not remove empty
          patched files unless this option is given.   When  patch  removes  a
          file(1,n), 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(1,n)  is  to be patched; patch files even though they have the wrong
          version(1,3,5) for the Prereq: line in(1,8) the patch; and assume  that  patches
          are  not reversed even if(3,n) they look(1,8,3 Search::Dict) 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 in(1,8)
          looking for places to install a hunk.  Note that a larger fuzz  fac-
          tor(1,6)  increases  the odds of a faulty patch.  The default fuzz factor(1,6)
          is 2, and it may not be set(7,n,1 builtins) to more than the number of lines of con-
          text in(1,8) the context diff, ordinarily 3.

       -g num  or  --get=num
          This  option  controls  patch's  actions when a file(1,n) is under RCS or
          SCCS control, and does not exist or is  read-only  and  matches  the
          default  version(1,3,5), or when a file(1,n) is under ClearCase control and does
          not exist.  If num is positive, patch gets(3,n) (or checks out) the  file(1,n)
          from  the  revision  control  system;  if(3,n)  zero,  patch ignores RCS,
          ClearCase, and SCCS and does not get  the  file(1,n);  and  if(3,n)  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 vari-
          able  if(3,n)  it  is  set(7,n,1 builtins); if(3,n) not, the default value is zero if(3,n) patch is
          conforming to POSIX, negative otherwise.

          Print a summary of options and exit.

       -i patchfile  or  --input=patchfile
          Read the patch from patchfile.  If patchfile is -, read(2,n,1 builtins)  from  stan-
          dard input, the default.

       -l  or  --ignore-whitespace
          Match  patterns  loosely, in(1,8) case tabs or spaces have been munged in(1,8)
          your files.  Any sequence of one or more blanks in(1,8)  the  patch  file(1,n)
          matches  any  sequence in(1,8) the original file(1,n), 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(1,8)
          the original file.

       -n  or  --normal
          Interpret the patch file(1,n) as a normal diff.

       -N  or  --forward
          Ignore patches that seem to be reversed  or  already  applied.   See
          also -R.

       -o outfile  or  --output=outfile
          Send output to outfile instead of patching files in(1,8) place.

       -pnum  or  --strip=num
          Strip  the  smallest prefix containing num leading slashes from each
          file(1,n) name found in(1,8) the patch file.  A sequence of one or more  adja-
          cent  slashes  is counted as a single slash.  This controls how file(1,n)
          names found in(1,8) the patch file(1,n) are treated, in(1,8)  case  you  keep  your
          files  in(1,8)  a  different  directory  than the person who sent out the
          patch.  For example, supposing the file(1,n) name in(1,8) the patch file(1,n) was


          setting -p0 gives the entire file(1,n) name unmodified, -p1 gives


          without the leading slash, -p4 gives


          and not specifying -p at all just gives you blurfl.c.  Whatever  you
          end  up  with  is looked for either in(1,8) the current directory, or the
          directory specified by the -d option.

          Conform more strictly to the POSIX standard, as follows.

            Take the first existing file(1,n) from the list (old, new, index) when
             intuiting file(1,n) names from diff headers.

            Do not remove files that are empty after patching.

            Do not ask whether to get files from RCS, ClearCase, or SCCS.

            Require that all options precede the files in(1,8) the command line.

            Do not backup files when there is a mismatch.

          Use style word to quote output names.  The word should be one of the

                 Output names as-is.

          shell  Quote names for the shell if(3,n) they contain  shell  metacharac-
                 ters or would cause ambiguous output.

                 Quote  names  for  the shell, even if(3,n) 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

          You can specify the default value of the --quoting-style option with
          the environment variable QUOTING_STYLE.  If that  environment  vari-
          able is not set(7,n,1 builtins), the default value is shell.

       -r rejectfile  or  --reject-file=rejectfile
          Put rejects into rejectfile instead of the default .rej file.

       -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(1,8) the swapped format.  The -R
          option  does not work with ed diff scripts because there is too lit-
          tle information to reconstruct the reverse operation.

          If the first hunk of a patch fails, patch reverses the hunk  to  see
          if(3,n) it can be applied that way.  If it can, you are asked if(3,n) you want
          to have the -R option set.  If it can't, the patch continues  to  be
          applied normally.  (Note: this method cannot detect a reversed patch
          if(3,n) it is a normal diff and if(3,n) the first command is an  append  (i.e.
          it  should  have been a delete) since appends always succeed, due to
          the fact that  a  null  context  matches  anywhere.   Luckily,  most
          patches  add  or  change  lines  rather  than  delete  them, so most
          reversed normal diffs begin with a delete, which  fails,  triggering
          the heuristic.)

       -s  or  --silent  or  --quiet
          Work silently, unless an error(8,n) occurs.

       -t  or  --batch
          Suppress  questions  like  -f,  but make some different assumptions:
          skip patches whose headers do not contain file(1,n) names  (the  same  as
          -f);  skip  patches for which the file(1,n) has the wrong version(1,3,5) for the
          Prereq: line in(1,8) the patch; and assume that patches are  reversed  if(3,n)
          they look(1,8,3 Search::Dict) like they are.

       -T  or  --set-time
          Set  the  modification  and  access(2,5) times of patched files from time(1,2,n)
          stamps given in(1,8) context diff headers, assuming that the context diff
          headers  use  local  time.   This option is not recommended, because
          patches using local time(1,2,n) cannot easily be used by  people  in(1,8)  other
          time(1,2,n)  zones,  and because local time(1,2,n) stamps are ambiguous when local
          clocks  move(3x,7,3x curs_move)  backwards  during  daylight-saving  time(1,2,n)  adjustments.
          Instead  of using this option, generate patches with UTC and use the
          -Z or --set-utc option instead.

       -u  or  --unified
          Interpret the patch file(1,n) 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(1,n) names.  The method can  also  be
          given  by the PATCH_VERSION_CONTROL (or, if(3,n) that's not set(7,n,1 builtins), the VER-
          SION_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.

          The value of method is like the GNU  Emacs  `version-control'  vari-
          able; patch also recognizes synonyms that are more descriptive.  The
          valid values for method are (unique abbreviations are accepted):

          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(1,n) name for F is
             F.~N~ where N is the version(1,3,5) number.

          simple  or  never
             Make simple backups.  The -B or --prefix, -Y  or  --basename-pre-
             fix,  and  -z  or --suffix options specify the simple backup file(1,n)
             name.  If none of these options are given, then a  simple  backup
             suffix is used; it is the value of the SIMPLE_BACKUP_SUFFIX envi-
             ronment variable if(3,n) set(7,n,1 builtins), and is .orig otherwise.

          With numbered or simple backups, if(3,n) the  backup  file(1,n)  name  is  too
          long, the backup suffix ~ is used instead; if(3,n) even appending ~ would
          make the name too long, then ~ replaces the last  character  of  the
          file(1,n) name.

          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
          Prefix  pref to the basename(1,3,3 File::Basename) of a file(1,n) name when generating its sim-
          ple backup file(1,n) name.  For example, with -Y .del/ the simple  backup
          file(1,n) name for src/patch/util.c is src/patch/.del/util.c.

       -z suffix  or  --suffix=suffix
          Use  suffix as the simple backup suffix.  For example, with -z - the
          simple backup file(1,n) name for src/patch/util.c  is  src/patch/util.c-.
          The  backup suffix may also be specified by the SIMPLE_BACKUP_SUFFIX
          environment variable, which is overridden by this option.

       -Z  or  --set-utc
          Set the modification and access(2,5) times of  patched  files  from  time(1,2,n)
          stamps given in(1,8) context diff headers, assuming that the context diff
          headers use Coordinated Universal Time (UTC, often  known  as  GMT).
          Also see the -T or --set-time option.

          The  -Z  or  --set-utc and -T or --set-time options normally refrain
          from setting a file(1,n)'s time(1,2,n) if(3,n) the  file(1,n)'s  original  time(1,2,n)  does  not
          match  the time(1,2,n) given in(1,8) the patch header, or if(3,n) its contents do not
          match the patch exactly.  However, if(3,n) the -f or  --force  option  is
          given, the file(1,n) time(1,2,n) is set(7,n,1 builtins) regardless.

          Due  to  the limitations of diff output format, these options cannot
          update(7,n) the times of files whose contents have not changed.  Also, if(3,n)
          you  use these options, you should remove (e.g. with make clean) all
          files that depend on the patched files, so that later invocations of
          make do not get confused by the patched files' times.

          This  specifies  whether  patch gets(3,n) missing or read-only files from
          RCS, ClearCase, or SCCS by default; see the -g or --get option.

          If set(7,n,1 builtins), patch conforms  more  strictly  to  the  POSIX  standard  by
          default: see the --posix option.

          Default value of the --quoting-style option.

          Extension to use for simple backup file(1,n) names instead of .orig.

          Directory  to  put temporary files in(1,8); patch uses the first environ-
          ment variable in(1,8) this list that  is  set.   If  none  are  set(7,n,1 builtins),  the
          default is system-dependent; it is normally /tmp on Unix hosts.

          Selects  version(1,3,5)  control  style;  see  the  -v or --version-control

          temporary files

          controlling terminal; used to get answers to questions asked of  the

       diff(1), ed(1)

       Marshall  T. Rose and Einar A. Stefferud, Proposed Standard for Message
       Encapsulation,    Internet    RFC    934     <URL:
       notes/rfc934.txt> (1985-01).

       There are several things you should bear in(1,8) mind if(3,n) you are going to be
       sending out patches.

       Create your  patch  systematically.   A  good  method  is  the  command
       diff -Naur old new  where old and new identify the old and new directo-
       ries.  The names old and new should not contain any slashes.  The  diff
       command's  headers  should have dates and times in(1,8) Universal Time using
       traditional Unix format, so that patch recipients can  use  the  -Z  or
       --set-utc  option.  Here is an example command, using Bourne shell syn-

          LC_ALL=C TZ=UTC0 diff -Naur gcc-2.7 gcc-2.8

       Tell your recipients how to apply  the  patch  by  telling  them  which
       directory  to cd to, and which patch options to use.  The option string(3,n)
       -Np1 is recommended.  Test your procedure by pretending to be a recipi-
       ent and applying your patch to a copy of the original files.

       You can save people a lot of grief by keeping a patchlevel.h file(1,n) which
       is patched to increment the patch level as the first diff in(1,8) the  patch
       file(1,n)  you  send(2,n)  out.   If you put a Prereq: line in(1,8) with the patch, it
       won't let them apply patches out of order without some warning.

       You can create a file(1,n) by sending out a diff that compares /dev/null  or
       an empty file(1,n) dated the Epoch (1970-01-01 00:00:00 UTC) to the file(1,n) you
       want to create.  This only works if(3,n) the file(1,n) you want to create doesn't
       exist  already  in(1,8)  the target directory.  Conversely, you can remove a
       file(1,n) by sending out a context diff that compares the file(1,n) to be deleted
       with  an  empty  file(1,n) dated the Epoch.  The file(1,n) will be removed unless
       patch is conforming to POSIX and the -E or --remove-empty-files  option
       is  not  given.  An easy way to generate patches that create and remove
       files is to use GNU diff's -N or --new-file option.

       If the recipient is supposed to use the -pN option, do not send(2,n)  output
       that looks like this:

          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

       because  the two file(1,n) names have different numbers of slashes, and dif-
       ferent versions of patch interpret  the  file(1,n)  names  differently.   To
       avoid confusion, send(2,n) output that looks like this instead:

          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

       Avoid  sending patches that compare backup file(1,n) names like README.orig,
       since this might confuse patch into patching a backup file(1,n)  instead  of
       the  real  file.  Instead, send(2,n) patches that compare the same base file(1,n)
       names in(1,8) different directories, e.g. old/README and new/README.

       Take care not to send(2,n) out reversed patches, since it makes people  won-
       der whether they already applied the patch.

       Try  not to have your patch modify derived files (e.g. the file(1,n) config-
       ure where there is a line configure:  in(1,8)  your  makefile),
       since the recipient should be able to regenerate the derived files any-
       way.  If you must send(2,n) diffs of derived files, generate the diffs using
       UTC,  have  the  recipients  apply  the  patch with the -Z or --set-utc
       option, and have them remove any unpatched files that depend on patched
       files (e.g. with make clean).

       While  you  may be able to get away with putting 582 diff listings into
       one file(1,n), it may be wiser to group related patches into separate  files
       in(1,8) case something goes haywire.

       Diagnostics  generally  indicate  that  patch couldn't parse your patch

       If the --verbose option is given, the  message  Hmm...  indicates  that
       there  is unprocessed text in(1,8) the patch file(1,n) and that patch is attempt-
       ing to intuit whether there is a patch in(1,8) that text and,  if(3,n)  so,  what
       kind of patch it is.

       patch's  exit(3,n,1 builtins)  status  is 0 if(3,n) all hunks are applied successfully, 1 if(3,n)
       some hunks cannot be applied, and 2 if(3,n) there is more  serious  trouble.
       When  applying a set(7,n,1 builtins) of patches in(1,8) a loop it behooves you to check this
       exit(3,n,1 builtins) status so you don't apply a later patch  to  a  partially  patched

       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(1,n) metadata like ownership,
       permissions, or whether one file(1,n) is a hard link(1,2) to another.  If changes
       like  these  are  also  required,  separate  instructions (e.g. a shell
       script) to accomplish them should accompany the patch.

       patch cannot tell if(3,n) the line numbers are off in(1,8) an ed script, and  can
       detect bad line numbers in(1,8) a normal diff only when it finds a change or
       deletion.  A context diff using fuzz factor(1,6) 3 may have the  same  prob-
       lem.  Until a suitable interactive interface is added, you should prob-
       ably do a context diff in(1,8) these cases to see if(3,n) the changes made sense.
       Of  course,  compiling  without errors is a pretty good indication that
       the patch worked, but not always.

       patch usually produces the correct results, even when it has  to  do  a
       lot  of  guessing.   However,  the results are guaranteed to be correct
       only when the patch is applied to exactly the same version(1,3,5) of the  file(1,n)
       that the patch was generated from.

       The  POSIX standard specifies behavior that differs from patch's tradi-
       tional behavior.  You should be aware of these differences if(3,n) 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 oper-
          and, and -p 0 is now equivalent to -p0.  For maximum  compatibility,
          use options like -p0 and -p1.

          Also,  traditional  patch simply counted slashes when stripping path
          prefixes; patch now counts pathname components.  That is, a sequence
          of  one  or more adjacent slashes now counts as a single slash.  For
          maximum portability, avoid sending patches  containing  //  in(1,8)  file(1,n)

         In  traditional patch, backups were enabled by default.  This behav-
          ior is now enabled with the -b or --backup option.

          Conversely, in(1,8) POSIX patch, backups are never made, even when  there
          is  a  mismatch.   In  GNU  patch, this behavior is enabled with the
          --no-backup-if-mismatch option, or by conforming to POSIX  with  the
          --posix  option  or by setting the POSIXLY_CORRECT environment vari-

          The -b suffix option of  traditional  patch  is  equivalent  to  the
          -b -z suffix options of GNU patch.

         Traditional  patch  used a complicated (and incompletely documented)
          method to intuit the name of the file(1,n) 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  bet-
          ter  documented) method that is optionally POSIX-conforming; we hope
          it has fewer gotchas.  The two methods are compatible  if(3,n)  the  file(1,n)
          names in(1,8) the context diff header and the Index: line are all identi-
          cal after prefix-stripping.  Your patch is  normally  compatible  if(3,n)
          each header's file(1,n) names all contain the same number of slashes.

         When  traditional patch asked the user a question, it sent the ques-
          tion to standard error(8,n) and looked for an answer from the first  file(1,n)
          in(1,8)  the following list that was a terminal: standard error(8,n), standard
          output, /dev/tty(1,4), and standard input.  Now patch sends questions  to
          standard  output  and gets(3,n) answers from /dev/tty(1,4).  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(3,n) there was real trouble.  Now patch
          exits  with  status  1  if(3,n) some hunks failed, or with 2 if(3,n) 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(1,8)  the
          following list, and operands are required.

             -d dir
             -D define
             -o outfile
             -r rejectfile

       Please report bugs via email to <>.

       patch  could be smarter about partial matches, excessively deviant off-
       sets and swapped code, but that would take an extra pass.

       If code has been duplicated (for instance with #ifdef OLDCODE ... #else
       ...  #endif),  patch is incapable of patching both versions, and, if(3,n) it
       works at all, will likely patch the wrong one, and  tell  you  that  it
       succeeded to boot.

       If  you  apply  a  patch  you've  already applied, patch thinks it is a
       reversed patch, and offers to un-apply the patch.  This could  be  con-
       strued as a feature.

       Copyright 1984, 1985, 1986, 1988 Larry Wall.
       Copyright  1989,  1990,  1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
       Free Software Foundation, Inc.

       Permission is granted to make and distribute verbatim  copies  of  this
       manual  provided  the  copyright  notice and this permission notice are
       preserved on all copies.

       Permission is granted to copy and distribute modified versions of  this
       manual  under  the  conditions  for verbatim copying, provided that the
       entire resulting derived work is distributed under the terms of a  per-
       mission notice identical to this one.

       Permission  is granted to copy and distribute translations of this man-
       ual into another language, under the above conditions for modified ver-
       sions,  except  that this permission notice may be included in(1,8) transla-
       tions approved by the copyright holders  instead  of  in(1,8)  the  original

       Larry  Wall  wrote  the original version(1,3,5) of patch.  Paul Eggert removed
       patch's arbitrary limits; added support for binary files, setting  file(1,n)
       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.

GNU                               1998/03/21                          PATCH(1)

References for this manual (incoming links)