home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / diffutils-2.7-bin.lha / info / diff.info-3 (.txt) < prev    next >
GNU Info File  |  1996-10-12  |  47KB  |  919 lines

  1. This is Info file diff.info, produced by Makeinfo-1.64 from the input
  2. file /ade-src/fsf/diffutils/diff.texi.
  3.    This file documents the the GNU `diff', `diff3', `sdiff', and `cmp'
  4. commands for showing the differences between text files and the `patch'
  5. command for using their output to update files.
  6.    Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  7.    Permission is granted to make and distribute verbatim copies of this
  8. manual provided the copyright notice and this permission notice are
  9. preserved on all copies.
  10.    Permission is granted to copy and distribute modified versions of
  11. this manual under the conditions for verbatim copying, provided that
  12. the entire resulting derived work is distributed under the terms of a
  13. permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that this permission notice may be stated in a
  17. translation approved by the Foundation.
  18. File: diff.info,  Node: Making Patches,  Next: Invoking cmp,  Prev: Merging with patch,  Up: Top
  19. Tips for Making Patch Distributions
  20. ***********************************
  21.    Here are some things you should keep in mind if you are going to
  22. distribute patches for updating a software package.
  23.    Make sure you have specified the file names correctly, either in a
  24. context diff header or with an `Index:' line.  If you are patching
  25. files in a subdirectory, be sure to tell the patch user to specify a
  26. `-p' or `--strip' option as needed.  Take care to not send out reversed
  27. patches, since these make people wonder whether they have already
  28. applied the patch.
  29.    To save people from partially applying a patch before other patches
  30. that should have gone before it, you can make the first patch in the
  31. patch file update a file with a name like `patchlevel.h' or
  32. `version.c', which contains a patch level or version number.  If the
  33. input file contains the wrong version number, `patch' will complain
  34. immediately.
  35.    An even clearer way to prevent this problem is to put a `Prereq:'
  36. line before the patch.  If the leading text in the patch file contains a
  37. line that starts with `Prereq:', `patch' takes the next word from that
  38. line (normally a version number) and checks whether the next input file
  39. contains that word, preceded and followed by either white space or a
  40. newline.  If not, `patch' prompts you for confirmation before
  41. proceeding.  This makes it difficult to accidentally apply patches in
  42. the wrong order.
  43.    Since `patch' does not handle incomplete lines properly, make sure
  44. that all the source files in your program end with a newline whenever
  45. you release a version.
  46.    To create a patch that changes an older version of a package into a
  47. newer version, first make a copy of the older version in a scratch
  48. directory.  Typically you do that by unpacking a `tar' or `shar'
  49. archive of the older version.
  50.    You might be able to reduce the size of the patch by renaming or
  51. removing some files before making the patch.  If the older version of
  52. the package contains any files that the newer version does not, or if
  53. any files have been renamed between the two versions, make a list of
  54. `rm' and `mv' commands for the user to execute in the old version
  55. directory before applying the patch.  Then run those commands yourself
  56. in the scratch directory.
  57.    If there are any files that you don't need to include in the patch
  58. because they can easily be rebuilt from other files (for example,
  59. `TAGS' and output from `yacc' and `makeinfo'), replace the versions in
  60. the scratch directory with the newer versions, using `rm' and `ln' or
  61. `cp'.
  62.    Now you can create the patch.  The de-facto standard `diff' format
  63. for patch distributions is context format with two lines of context,
  64. produced by giving `diff' the `-C 2' option.  Do not use less than two
  65. lines of context, because `patch' typically needs at least two lines
  66. for proper operation.  Give `diff' the `-P' option in case the newer
  67. version of the package contains any files that the older one does not.
  68. Make sure to specify the scratch directory first and the newer
  69. directory second.
  70.    Add to the top of the patch a note telling the user any `rm' and
  71. `mv' commands to run before applying the patch.  Then you can remove
  72. the scratch directory.
  73. File: diff.info,  Node: Invoking cmp,  Next: Invoking diff,  Prev: Making Patches,  Up: Top
  74. Invoking `cmp'
  75. **************
  76.    The `cmp' command compares two files, and if they differ, tells the
  77. first byte and line number where they differ.  Its arguments are as
  78. follows:
  79.      cmp OPTIONS... FROM-FILE [TO-FILE]
  80.    The file name `-' is always the standard input.  `cmp' also uses the
  81. standard input if one file name is omitted.
  82.    An exit status of 0 means no differences were found, 1 means some
  83. differences were found, and 2 means trouble.
  84. * Menu:
  85. * cmp Options::        Summary of options to `cmp'.
  86. File: diff.info,  Node: cmp Options,  Up: Invoking cmp
  87. Options to `cmp'
  88. ================
  89.    Below is a summary of all of the options that GNU `cmp' accepts.
  90. Most options have two equivalent names, one of which is a single letter
  91. preceded by `-', and the other of which is a long name preceded by
  92. `--'.  Multiple single letter options (unless they take an argument)
  93. can be combined into a single command line word: `-cl' is equivalent to
  94. `-c -l'.
  95.      Print the differing characters.  Display control characters as a
  96.      `^' followed by a letter of the alphabet and precede characters
  97.      that have the high bit set with `M-' (which stands for "meta").
  98. `--ignore-initial=BYTES'
  99.      Ignore any differences in the the first BYTES bytes of the input
  100.      files.  Treat files with fewer than BYTES bytes as if they are
  101.      empty.
  102.      Print the (decimal) offsets and (octal) values of all differing
  103.      bytes.
  104. `--print-chars'
  105.      Print the differing characters.  Display control characters as a
  106.      `^' followed by a letter of the alphabet and precede characters
  107.      that have the high bit set with `M-' (which stands for "meta").
  108. `--quiet'
  109. `--silent'
  110.      Do not print anything; only return an exit status indicating
  111.      whether the files differ.
  112. `--verbose'
  113.      Print the (decimal) offsets and (octal) values of all differing
  114.      bytes.
  115. `--version'
  116.      Output the version number of `cmp'.
  117. File: diff.info,  Node: Invoking diff,  Next: Invoking diff3,  Prev: Invoking cmp,  Up: Top
  118. Invoking `diff'
  119. ***************
  120.    The format for running the `diff' command is:
  121.      diff OPTIONS... FROM-FILE TO-FILE
  122.    In the simplest case, `diff' compares the contents of the two files
  123. FROM-FILE and TO-FILE.  A file name of `-' stands for text read from
  124. the standard input.  As a special case, `diff - -' compares a copy of
  125. standard input to itself.
  126.    If FROM-FILE is a directory and TO-FILE is not, `diff' compares the
  127. file in FROM-FILE whose file name is that of TO-FILE, and vice versa.
  128. The non-directory file must not be `-'.
  129.    If both FROM-FILE and TO-FILE are directories, `diff' compares
  130. corresponding files in both directories, in alphabetical order; this
  131. comparison is not recursive unless the `-r' or `--recursive' option is
  132. given.  `diff' never compares the actual contents of a directory as if
  133. it were a file.  The file that is fully specified may not be standard
  134. input, because standard input is nameless and the notion of "file with
  135. the same name" does not apply.
  136.    `diff' options begin with `-', so normally FROM-FILE and TO-FILE may
  137. not begin with `-'.  However, `--' as an argument by itself treats the
  138. remaining arguments as file names even if they begin with `-'.
  139.    An exit status of 0 means no differences were found, 1 means some
  140. differences were found, and 2 means trouble.
  141. * Menu:
  142. * diff Options::    Summary of options to `diff'.
  143. File: diff.info,  Node: diff Options,  Up: Invoking diff
  144. Options to `diff'
  145. =================
  146.    Below is a summary of all of the options that GNU `diff' accepts.
  147. Most options have two equivalent names, one of which is a single letter
  148. preceded by `-', and the other of which is a long name preceded by
  149. `--'.  Multiple single letter options (unless they take an argument)
  150. can be combined into a single command line word: `-ac' is equivalent to
  151. `-a -c'.  Long named options can be abbreviated to any unique prefix of
  152. their name.  Brackets ([ and ]) indicate that an option takes an
  153. optional argument.
  154. `-LINES'
  155.      Show LINES (an integer) lines of context.  This option does not
  156.      specify an output format by itself; it has no effect unless it is
  157.      combined with `-c' (*note Context Format::.) or `-u' (*note
  158.      Unified Format::.).  This option is obsolete.  For proper
  159.      operation, `patch' typically needs at least two lines of context.
  160.      Treat all files as text and compare them line-by-line, even if they
  161.      do not seem to be text.  *Note Binary::.
  162.      Ignore changes in amount of white space.  *Note White Space::.
  163.      Ignore changes that just insert or delete blank lines.  *Note
  164.      Blank Lines::.
  165. `--binary'
  166.      Read and write data in binary mode.  *Note Binary::.
  167. `--brief'
  168.      Report only whether the files differ, not the details of the
  169.      differences.  *Note Brief::.
  170.      Use the context output format.  *Note Context Format::.
  171. `-C LINES'
  172. `--context[=LINES]'
  173.      Use the context output format, showing LINES (an integer) lines of
  174.      context, or three if LINES is not given.  *Note Context Format::.
  175.      For proper operation, `patch' typically needs at least two lines of
  176.      context.
  177. `--changed-group-format=FORMAT'
  178.      Use FORMAT to output a line group containing differing lines from
  179.      both files in if-then-else format.  *Note Line Group Formats::.
  180.      Change the algorithm perhaps find a smaller set of changes.  This
  181.      makes `diff' slower (sometimes much slower).  *Note diff
  182.      Performance::.
  183. `-D NAME'
  184.      Make merged `#ifdef' format output, conditional on the preprocessor
  185.      macro NAME.  *Note If-then-else::.
  186. `--ed'
  187.      Make output that is a valid `ed' script.  *Note ed Scripts::.
  188. `--exclude=PATTERN'
  189.      When comparing directories, ignore files and subdirectories whose
  190.      basenames match PATTERN.  *Note Comparing Directories::.
  191. `--exclude-from=FILE'
  192.      When comparing directories, ignore files and subdirectories whose
  193.      basenames match any pattern contained in FILE.  *Note Comparing
  194.      Directories::.
  195. `--expand-tabs'
  196.      Expand tabs to spaces in the output, to preserve the alignment of
  197.      tabs in the input files.  *Note Tabs::.
  198.      Make output that looks vaguely like an `ed' script but has changes
  199.      in the order they appear in the file.  *Note Forward ed::.
  200. `-F REGEXP'
  201.      In context and unified format, for each hunk of differences, show
  202.      some of the last preceding line that matches REGEXP.  *Note
  203.      Specified Headings::.
  204. `--forward-ed'
  205.      Make output that looks vaguely like an `ed' script but has changes
  206.      in the order they appear in the file.  *Note Forward ed::.
  207.      This option currently has no effect; it is present for Unix
  208.      compatibility.
  209.      Use heuristics to speed handling of large files that have numerous
  210.      scattered small changes.  *Note diff Performance::.
  211. `--horizon-lines=LINES'
  212.      Do not discard the last LINES lines of the common prefix and the
  213.      first LINES lines of the common suffix.  *Note diff Performance::.
  214.      Ignore changes in case; consider upper- and lower-case letters
  215.      equivalent.  *Note Case Folding::.
  216. `-I REGEXP'
  217.      Ignore changes that just insert or delete lines that match REGEXP.
  218.      *Note Specified Folding::.
  219. `--ifdef=NAME'
  220.      Make merged if-then-else output using NAME.  *Note If-then-else::.
  221. `--ignore-all-space'
  222.      Ignore white space when comparing lines.  *Note White Space::.
  223. `--ignore-blank-lines'
  224.      Ignore changes that just insert or delete blank lines.  *Note
  225.      Blank Lines::.
  226. `--ignore-case'
  227.      Ignore changes in case; consider upper- and lower-case to be the
  228.      same.  *Note Case Folding::.
  229. `--ignore-matching-lines=REGEXP'
  230.      Ignore changes that just insert or delete lines that match REGEXP.
  231.      *Note Specified Folding::.
  232. `--ignore-space-change'
  233.      Ignore changes in amount of white space.  *Note White Space::.
  234. `--initial-tab'
  235.      Output a tab rather than a space before the text of a line in
  236.      normal or context format.  This causes the alignment of tabs in
  237.      the line to look normal.  *Note Tabs::.
  238.      Pass the output through `pr' to paginate it.  *Note Pagination::.
  239. `-L LABEL'
  240.      Use LABEL instead of the file name in the context format (*note
  241.      Context Format::.) and unified format (*note Unified Format::.)
  242.      headers.  *Note RCS::.
  243. `--label=LABEL'
  244.      Use LABEL instead of the file name in the context format (*note
  245.      Context Format::.) and unified format (*note Unified Format::.)
  246.      headers.
  247. `--left-column'
  248.      Print only the left column of two common lines in side by side
  249.      format.  *Note Side by Side Format::.
  250. `--line-format=FORMAT'
  251.      Use FORMAT to output all input lines in if-then-else format.
  252.      *Note Line Formats::.
  253. `--minimal'
  254.      Change the algorithm to perhaps find a smaller set of changes.
  255.      This makes `diff' slower (sometimes much slower).  *Note diff
  256.      Performance::.
  257.      Output RCS-format diffs; like `-f' except that each command
  258.      specifies the number of lines affected.  *Note RCS::.
  259. `--new-file'
  260.      In directory comparison, if a file is found in only one directory,
  261.      treat it as present but empty in the other directory.  *Note
  262.      Comparing Directories::.
  263. `--new-group-format=FORMAT'
  264.      Use FORMAT to output a group of lines taken from just the second
  265.      file in if-then-else format.  *Note Line Group Formats::.
  266. `--new-line-format=FORMAT'
  267.      Use FORMAT to output a line taken from just the second file in
  268.      if-then-else format.  *Note Line Formats::.
  269. `--old-group-format=FORMAT'
  270.      Use FORMAT to output a group of lines taken from just the first
  271.      file in if-then-else format.  *Note Line Group Formats::.
  272. `--old-line-format=FORMAT'
  273.      Use FORMAT to output a line taken from just the first file in
  274.      if-then-else format.  *Note Line Formats::.
  275.      Show which C function each change is in.  *Note C Function
  276.      Headings::.
  277.      When comparing directories, if a file appears only in the second
  278.      directory of the two, treat it as present but empty in the other.
  279.      *Note Comparing Directories::.
  280. `--paginate'
  281.      Pass the output through `pr' to paginate it.  *Note Pagination::.
  282.      Report only whether the files differ, not the details of the
  283.      differences.  *Note Brief::.
  284.      When comparing directories, recursively compare any subdirectories
  285.      found.  *Note Comparing Directories::.
  286. `--rcs'
  287.      Output RCS-format diffs; like `-f' except that each command
  288.      specifies the number of lines affected.  *Note RCS::.
  289. `--recursive'
  290.      When comparing directories, recursively compare any subdirectories
  291.      found.  *Note Comparing Directories::.
  292. `--report-identical-files'
  293.      Report when two files are the same.  *Note Comparing Directories::.
  294.      Report when two files are the same.  *Note Comparing Directories::.
  295. `-S FILE'
  296.      When comparing directories, start with the file FILE.  This is
  297.      used for resuming an aborted comparison.  *Note Comparing
  298.      Directories::.
  299. `--sdiff-merge-assist'
  300.      Print extra information to help `sdiff'.  `sdiff' uses this option
  301.      when it runs `diff'.  This option is not intended for users to use
  302.      directly.
  303. `--show-c-function'
  304.      Show which C function each change is in.  *Note C Function
  305.      Headings::.
  306. `--show-function-line=REGEXP'
  307.      In context and unified format, for each hunk of differences, show
  308.      some of the last preceding line that matches REGEXP.  *Note
  309.      Specified Headings::.
  310. `--side-by-side'
  311.      Use the side by side output format.  *Note Side by Side Format::.
  312. `--speed-large-files'
  313.      Use heuristics to speed handling of large files that have numerous
  314.      scattered small changes.  *Note diff Performance::.
  315. `--starting-file=FILE'
  316.      When comparing directories, start with the file FILE.  This is
  317.      used for resuming an aborted comparison.  *Note Comparing
  318.      Directories::.
  319. `--suppress-common-lines'
  320.      Do not print common lines in side by side format.  *Note Side by
  321.      Side Format::.
  322.      Expand tabs to spaces in the output, to preserve the alignment of
  323.      tabs in the input files.  *Note Tabs::.
  324.      Output a tab rather than a space before the text of a line in
  325.      normal or context format.  This causes the alignment of tabs in
  326.      the line to look normal.  *Note Tabs::.
  327. `--text'
  328.      Treat all files as text and compare them line-by-line, even if they
  329.      do not appear to be text.  *Note Binary::.
  330.      Use the unified output format.  *Note Unified Format::.
  331. `--unchanged-group-format=FORMAT'
  332.      Use FORMAT to output a group of common lines taken from both files
  333.      in if-then-else format.  *Note Line Group Formats::.
  334. `--unchanged-line-format=FORMAT'
  335.      Use FORMAT to output a line common to both files in if-then-else
  336.      format.  *Note Line Formats::.
  337. `--unidirectional-new-file'
  338.      When comparing directories, if a file appears only in the second
  339.      directory of the two, treat it as present but empty in the other.
  340.      *Note Comparing Directories::.
  341. `-U LINES'
  342. `--unified[=LINES]'
  343.      Use the unified output format, showing LINES (an integer) lines of
  344.      context, or three if LINES is not given.  *Note Unified Format::.
  345.      For proper operation, `patch' typically needs at least two lines of
  346.      context.
  347. `--version'
  348.      Output the version number of `diff'.
  349.      Ignore white space when comparing lines.  *Note White Space::.
  350. `-W COLUMNS'
  351. `--width=COLUMNS'
  352.      Use an output width of COLUMNS in side by side format.  *Note Side
  353.      by Side Format::.
  354. `-x PATTERN'
  355.      When comparing directories, ignore files and subdirectories whose
  356.      basenames match PATTERN.  *Note Comparing Directories::.
  357. `-X FILE'
  358.      When comparing directories, ignore files and subdirectories whose
  359.      basenames match any pattern contained in FILE.  *Note Comparing
  360.      Directories::.
  361.      Use the side by side output format.  *Note Side by Side Format::.
  362. File: diff.info,  Node: Invoking diff3,  Next: Invoking patch,  Prev: Invoking diff,  Up: Top
  363. Invoking `diff3'
  364. ****************
  365.    The `diff3' command compares three files and outputs descriptions of
  366. their differences.  Its arguments are as follows:
  367.      diff3 OPTIONS... MINE OLDER YOURS
  368.    The files to compare are MINE, OLDER, and YOURS.  At most one of
  369. these three file names may be `-', which tells `diff3' to read the
  370. standard input for that file.
  371.    An exit status of 0 means `diff3' was successful, 1 means some
  372. conflicts were found, and 2 means trouble.
  373. * Menu:
  374. * diff3 Options::        Summary of options to `diff3'.
  375. File: diff.info,  Node: diff3 Options,  Up: Invoking diff3
  376. Options to `diff3'
  377. ==================
  378.    Below is a summary of all of the options that GNU `diff3' accepts.
  379. Multiple single letter options (unless they take an argument) can be
  380. combined into a single command line argument.
  381.      Treat all files as text and compare them line-by-line, even if they
  382.      do not appear to be text.  *Note Binary::.
  383.      Incorporate all changes from OLDER to YOURS into MINE, surrounding
  384.      all conflicts with bracket lines.  *Note Marking Conflicts::.
  385.      Generate an `ed' script that incorporates all the changes from
  386.      OLDER to YOURS into MINE.  *Note Which Changes::.
  387.      Like `-e', except bracket lines from overlapping changes' first
  388.      and third files.  *Note Marking Conflicts::.  With `-e', an
  389.      overlapping change looks like this:
  390.           <<<<<<< MINE
  391.           lines from MINE
  392.           =======
  393.           lines from YOURS
  394.           >>>>>>> YOURS
  395. `--ed'
  396.      Generate an `ed' script that incorporates all the changes from
  397.      OLDER to YOURS into MINE.  *Note Which Changes::.
  398. `--easy-only'
  399.      Like `-e', except output only the nonoverlapping changes.  *Note
  400.      Which Changes::.
  401.      Generate `w' and `q' commands at the end of the `ed' script for
  402.      System V compatibility.  This option must be combined with one of
  403.      the `-AeExX3' options, and may not be combined with `-m'.  *Note
  404.      Saving the Changed File::.
  405. `--initial-tab'
  406.      Output a tab rather than two spaces before the text of a line in
  407.      normal format.  This causes the alignment of tabs in the line to
  408.      look normal.  *Note Tabs::.
  409. `-L LABEL'
  410. `--label=LABEL'
  411.      Use the label LABEL for the brackets output by the `-A', `-E' and
  412.      `-X' options.  This option may be given up to three times, one for
  413.      each input file.  The default labels are the names of the input
  414.      files.  Thus `diff3 -L X -L Y -L Z -m A B C' acts like `diff3 -m A
  415.      B C', except that the output looks like it came from files named
  416.      `X', `Y' and `Z' rather than from files named `A', `B' and `C'.
  417.      *Note Marking Conflicts::.
  418. `--merge'
  419.      Apply the edit script to the first file and send the result to
  420.      standard output.  Unlike piping the output from `diff3' to `ed',
  421.      this works even for binary files and incomplete lines.  `-A' is
  422.      assumed if no edit script option is specified.  *Note Bypassing
  423.      ed::.
  424. `--overlap-only'
  425.      Like `-e', except output only the overlapping changes.  *Note
  426.      Which Changes::.
  427. `--show-all'
  428.      Incorporate all unmerged changes from OLDER to YOURS into MINE,
  429.      surrounding all overlapping changes with bracket lines.  *Note
  430.      Marking Conflicts::.
  431. `--show-overlap'
  432.      Like `-e', except bracket lines from overlapping changes' first
  433.      and third files.  *Note Marking Conflicts::.
  434.      Output a tab rather than two spaces before the text of a line in
  435.      normal format.  This causes the alignment of tabs in the line to
  436.      look normal.  *Note Tabs::.
  437. `--text'
  438.      Treat all files as text and compare them line-by-line, even if they
  439.      do not appear to be text.  *Note Binary::.
  440. `--version'
  441.      Output the version number of `diff3'.
  442.      Like `-e', except output only the overlapping changes.  *Note
  443.      Which Changes::.
  444.      Like `-E', except output only the overlapping changes.  In other
  445.      words, like `-x', except bracket changes as in `-E'.  *Note
  446.      Marking Conflicts::.
  447.      Like `-e', except output only the nonoverlapping changes.  *Note
  448.      Which Changes::.
  449. File: diff.info,  Node: Invoking patch,  Next: Invoking sdiff,  Prev: Invoking diff3,  Up: Top
  450. Invoking `patch'
  451. ****************
  452.    Normally `patch' is invoked like this:
  453.      patch <PATCHFILE
  454.    The full format for invoking `patch' is:
  455.      patch OPTIONS... [ORIGFILE [PATCHFILE]] [+ OPTIONS... [ORIGFILE]]...
  456.    If you do not specify PATCHFILE, or if PATCHFILE is `-', `patch'
  457. reads the patch (that is, the `diff' output) from the standard input.
  458.    You can specify one or more of the original files as ORIG arguments;
  459. each one and options for interpreting it is separated from the others
  460. with a `+'.  *Note Multiple Patches::, for more information.
  461.    If you do not specify an input file on the command line, `patch'
  462. tries to figure out from the "leading text" (any text in the patch that
  463. comes before the `diff' output) which file to edit.  In the header of a
  464. context or unified diff, `patch' looks in lines beginning with `***',
  465. `---', or `+++'; among those, it chooses the shortest name of an
  466. existing file.  Otherwise, if there is an `Index:' line in the leading
  467. text, `patch' tries to use the file name from that line.  If `patch'
  468. cannot figure out the name of an existing file from the leading text,
  469. it prompts you for the name of the file to patch.
  470.    If the input file does not exist or is read-only, and a suitable RCS
  471. or SCCS file exists, `patch' attempts to check out or get the file
  472. before proceeding.
  473.    By default, `patch' replaces the original input file with the
  474. patched version, after renaming the original file into a backup file
  475. (*note Backups::., for a description of how `patch' names backup
  476. files).  You can also specify where to put the output with the `-o
  477. OUTPUT-FILE' or `--output=OUTPUT-FILE' option.
  478. * Menu:
  479. * patch Directories::    Changing directory and stripping directories.
  480. * Backups::        Backup file names.
  481. * Rejects::        Reject file names.
  482. * patch Options::    Summary table of options to `patch'.
  483. File: diff.info,  Node: patch Directories,  Next: Backups,  Up: Invoking patch
  484. Applying Patches in Other Directories
  485. =====================================
  486.    The `-d DIRECTORY' or `--directory=DIRECTORY' option to `patch'
  487. makes directory DIRECTORY the current directory for interpreting both
  488. file names in the patch file, and file names given as arguments to
  489. other options (such as `-B' and `-o').  For example, while in a news
  490. reading program, you can patch a file in the `/usr/src/emacs' directory
  491. directly from the article containing the patch like this:
  492.      | patch -d /usr/src/emacs
  493.    Sometimes the file names given in a patch contain leading
  494. directories, but you keep your files in a directory different from the
  495. one given in the patch.  In those cases, you can use the `-p[NUMBER]'
  496. or `--strip[=NUMBER]' option to set the file name strip count to
  497. NUMBER.  The strip count tells `patch' how many slashes, along with the
  498. directory names between them, to strip from the front of file names.
  499. `-p' with no NUMBER given is equivalent to `-p0'.  By default, `patch'
  500. strips off all leading directories, leaving just the base file names,
  501. except that when a file name given in the patch is a relative file name
  502. and all of its leading directories already exist, `patch' does not
  503. strip off the leading directory.  (A "relative" file name is one that
  504. does not start with a slash.)
  505.    `patch' looks for each file (after any slashes have been stripped)
  506. in the current directory, or if you used the `-d DIRECTORY' option, in
  507. that directory.
  508.    For example, suppose the file name in the patch file is
  509. `/gnu/src/emacs/etc/NEWS'.  Using `-p' or `-p0' gives the entire file
  510. name unmodified, `-p1' gives `gnu/src/emacs/etc/NEWS' (no leading
  511. slash), `-p4' gives `etc/NEWS', and not specifying `-p' at all gives
  512. `NEWS'.
  513. File: diff.info,  Node: Backups,  Next: Rejects,  Prev: patch Directories,  Up: Invoking patch
  514. Backup File Names
  515. =================
  516.    Normally, `patch' renames an original input file into a backup file
  517. by appending to its name the extension `.orig', or `~' on systems that
  518. do not support long file names.  The `-b BACKUP-SUFFIX' or
  519. `--suffix=BACKUP-SUFFIX' option uses BACKUP-SUFFIX as the backup
  520. extension instead.
  521.    Alternately, you can specify the extension for backup files with the
  522. `SIMPLE_BACKUP_SUFFIX' environment variable, which the options override.
  523.    `patch' can also create numbered backup files the way GNU Emacs
  524. does.  With this method, instead of having a single backup of each file,
  525. `patch' makes a new backup file name each time it patches a file.  For
  526. example, the backups of a file named `sink' would be called,
  527. successively, `sink.~1~', `sink.~2~', `sink.~3~', etc.
  528.    The `-V BACKUP-STYLE' or `--version-control=BACKUP-STYLE' option
  529. takes as an argument a method for creating backup file names.  You can
  530. alternately control the type of backups that `patch' makes with the
  531. `VERSION_CONTROL' environment variable, which the `-V' option
  532. overrides.  The value of the `VERSION_CONTROL' environment variable and
  533. the argument to the `-V' option are like the GNU Emacs
  534. `version-control' variable (*note emacs: Backups., for more information
  535. on backup versions in Emacs).  They also recognize synonyms that are
  536. more descriptive.  The valid values are listed below; unique
  537. abbreviations are acceptable.
  538. `numbered'
  539.      Always make numbered backups.
  540. `nil'
  541. `existing'
  542.      Make numbered backups of files that already have them, simple
  543.      backups of the others.  This is the default.
  544. `never'
  545. `simple'
  546.      Always make simple backups.
  547.    Alternately, you can tell `patch' to prepend a prefix, such as a
  548. directory name, to produce backup file names.  The `-B BACKUP-PREFIX'
  549. or `--prefix=BACKUP-PREFIX' option makes backup files by prepending
  550. BACKUP-PREFIX to them.  If you use this option, `patch' ignores any
  551. `-b' option that you give.
  552.    If the backup file already exists, `patch' creates a new backup file
  553. name by changing the first lowercase letter in the last component of
  554. the file name into uppercase.  If there are no more lowercase letters
  555. in the name, it removes the first character from the name.  It repeats
  556. this process until it comes up with a backup file name that does not
  557. already exist.
  558.    If you specify the output file with the `-o' option, that file is
  559. the one that is backed up, not the input file.
  560. File: diff.info,  Node: Rejects,  Next: patch Options,  Prev: Backups,  Up: Invoking patch
  561. Reject File Names
  562. =================
  563.    The names for reject files (files containing patches that `patch'
  564. could not find a place to apply) are normally the name of the output
  565. file with `.rej' appended (or `#' on systems that do not support long
  566. file names).
  567.    Alternatively, you can tell `patch' to place all of the rejected
  568. patches in a single file.  The `-r REJECT-FILE' or
  569. `--reject-file=REJECT-FILE' option uses REJECT-FILE as the reject file
  570. name.
  571. File: diff.info,  Node: patch Options,  Prev: Rejects,  Up: Invoking patch
  572. Options to `patch'
  573. ==================
  574.    Here is a summary of all of the options that `patch' accepts.  Older
  575. versions of `patch' do not accept long-named options or the `-t', `-E',
  576. or `-V' options.
  577.    Multiple single-letter options that do not take an argument can be
  578. combined into a single command line argument (with only one dash).
  579. Brackets ([ and ]) indicate that an option takes an optional argument.
  580. `-b BACKUP-SUFFIX'
  581.      Use BACKUP-SUFFIX as the backup extension instead of `.orig' or
  582.      `~'.  *Note Backups::.
  583. `-B BACKUP-PREFIX'
  584.      Use BACKUP-PREFIX as a prefix to the backup file name.  If this
  585.      option is specified, any `-b' option is ignored.  *Note Backups::.
  586. `--batch'
  587.      Do not ask any questions.  *Note patch Messages::.
  588. `--context'
  589.      Interpret the patch file as a context diff.  *Note patch Input::.
  590. `-d DIRECTORY'
  591. `--directory=DIRECTORY'
  592.      Makes directory DIRECTORY the current directory for interpreting
  593.      both file names in the patch file, and file names given as
  594.      arguments to other options.  *Note patch Directories::.
  595. `-D NAME'
  596.      Make merged if-then-else output using FORMAT.  *Note
  597.      If-then-else::.
  598. `--debug=NUMBER'
  599.      Set internal debugging flags.  Of interest only to `patch'
  600.      patchers.
  601. `--ed'
  602.      Interpret the patch file as an `ed' script.  *Note patch Input::.
  603.      Remove output files that are empty after the patches have been
  604.      applied.  *Note Empty Files::.
  605.      Assume that the user knows exactly what he or she is doing, and do
  606.      not ask any questions.  *Note patch Messages::.
  607. `-F LINES'
  608.      Set the maximum fuzz factor to LINES.  *Note Inexact::.
  609. `--force'
  610.      Assume that the user knows exactly what he or she is doing, and do
  611.      not ask any questions.  *Note patch Messages::.
  612. `--forward'
  613.      Ignore patches that `patch' thinks are reversed or already applied.
  614.      See also `-R'.  *Note Reversed Patches::.
  615. `--fuzz=LINES'
  616.      Set the maximum fuzz factor to LINES.  *Note Inexact::.
  617. `--help'
  618.      Print a summary of the options that `patch' recognizes, then exit.
  619. `--ifdef=NAME'
  620.      Make merged if-then-else output using FORMAT.  *Note
  621.      If-then-else::.
  622. `--ignore-white-space'
  623.      Let any sequence of white space in the patch file match any
  624.      sequence of white space in the input file.  *Note Changed White
  625.      Space::.
  626. `--normal'
  627.      Interpret the patch file as a normal diff.  *Note patch Input::.
  628.      Ignore patches that `patch' thinks are reversed or already applied.
  629.      See also `-R'.  *Note Reversed Patches::.
  630. `-o OUTPUT-FILE'
  631. `--output=OUTPUT-FILE'
  632.      Use OUTPUT-FILE as the output file name.  *Note patch Options::.
  633. `-p[NUMBER]'
  634.      Set the file name strip count to NUMBER.  *Note patch
  635.      Directories::.
  636. `--prefix=BACKUP-PREFIX'
  637.      Use BACKUP-PREFIX as a prefix to the backup file name.  If this
  638.      option is specified, any `-b' option is ignored.  *Note Backups::.
  639. `--quiet'
  640.      Work silently unless an error occurs.  *Note patch Messages::.
  641. `-r REJECT-FILE'
  642.      Use REJECT-FILE as the reject file name.  *Note Rejects::.
  643.      Assume that this patch was created with the old and new files
  644.      swapped.  *Note Reversed Patches::.
  645. `--reject-file=REJECT-FILE'
  646.      Use REJECT-FILE as the reject file name.  *Note Rejects::.
  647. `--remove-empty-files'
  648.      Remove output files that are empty after the patches have been
  649.      applied.  *Note Empty Files::.
  650. `--reverse'
  651.      Assume that this patch was created with the old and new files
  652.      swapped.  *Note Reversed Patches::.
  653.      Work silently unless an error occurs.  *Note patch Messages::.
  654.      Ignore this patch from the patch file, but continue looking for
  655.      the next patch in the file.  *Note Multiple Patches::.
  656. `--silent'
  657.      Work silently unless an error occurs.  *Note patch Messages::.
  658. `--skip'
  659.      Ignore this patch from the patch file, but continue looking for
  660.      the next patch in the file.  *Note Multiple Patches::.
  661. `--strip[=NUMBER]'
  662.      Set the file name strip count to NUMBER.  *Note patch
  663.      Directories::.
  664. `--suffix=BACKUP-SUFFIX'
  665.      Use BACKUP-SUFFIX as the backup extension instead of `.orig' or
  666.      `~'.  *Note Backups::.
  667.      Do not ask any questions.  *Note patch Messages::.
  668. `--unified'
  669.      Interpret the patch file as a unified diff.  *Note patch Input::.
  670.      Output the revision header and patch level of `patch'.
  671. `-V BACKUP-STYLE'
  672.      Select the kind of backups to make.  *Note Backups::.
  673. `--version'
  674.      Output the revision header and patch level of `patch', then exit.
  675. `--version=control=BACKUP-STYLE'
  676.      Select the kind of backups to make.  *Note Backups::.
  677. `-x NUMBER'
  678.      Set internal debugging flags.  Of interest only to `patch'
  679.      patchers.
  680. File: diff.info,  Node: Invoking sdiff,  Next: Incomplete Lines,  Prev: Invoking patch,  Up: Top
  681. Invoking `sdiff'
  682. ****************
  683.    The `sdiff' command merges two files and interactively outputs the
  684. results.  Its arguments are as follows:
  685.      sdiff -o OUTFILE OPTIONS... FROM-FILE TO-FILE
  686.    This merges FROM-FILE with TO-FILE, with output to OUTFILE.  If
  687. FROM-FILE is a directory and TO-FILE is not, `sdiff' compares the file
  688. in FROM-FILE whose file name is that of TO-FILE, and vice versa.
  689. FROM-FILE and TO-FILE may not both be directories.
  690.    `sdiff' options begin with `-', so normally FROM-FILE and TO-FILE
  691. may not begin with `-'.  However, `--' as an argument by itself treats
  692. the remaining arguments as file names even if they begin with `-'.  You
  693. may not use `-' as an input file.
  694.    An exit status of 0 means no differences were found, 1 means some
  695. differences were found, and 2 means trouble.
  696.    `sdiff' without `-o' (or `--output') produces a side-by-side
  697. difference.  This usage is obsolete; use `diff --side-by-side' instead.
  698. * Menu:
  699. * sdiff Options::    Summary of options to `diff'.
  700. File: diff.info,  Node: sdiff Options,  Up: Invoking sdiff
  701. Options to `sdiff'
  702. ==================
  703.    Below is a summary of all of the options that GNU `sdiff' accepts.
  704. Each option has two equivalent names, one of which is a single letter
  705. preceded by `-', and the other of which is a long name preceded by
  706. `--'.  Multiple single letter options (unless they take an argument)
  707. can be combined into a single command line argument.  Long named
  708. options can be abbreviated to any unique prefix of their name.
  709.      Treat all files as text and compare them line-by-line, even if they
  710.      do not appear to be text.  *Note Binary::.
  711.      Ignore changes in amount of white space.  *Note White Space::.
  712.      Ignore changes that just insert or delete blank lines.  *Note
  713.      Blank Lines::.
  714.      Change the algorithm to perhaps find a smaller set of changes.
  715.      This makes `sdiff' slower (sometimes much slower).  *Note diff
  716.      Performance::.
  717.      Use heuristics to speed handling of large files that have numerous
  718.      scattered small changes.  *Note diff Performance::.
  719. `--expand-tabs'
  720.      Expand tabs to spaces in the output, to preserve the alignment of
  721.      tabs in the input files.  *Note Tabs::.
  722.      Ignore changes in case; consider upper- and lower-case to be the
  723.      same.  *Note Case Folding::.
  724. `-I REGEXP'
  725.      Ignore changes that just insert or delete lines that match REGEXP.
  726.      *Note Specified Folding::.
  727. `--ignore-all-space'
  728.      Ignore white space when comparing lines.  *Note White Space::.
  729. `--ignore-blank-lines'
  730.      Ignore changes that just insert or delete blank lines.  *Note
  731.      Blank Lines::.
  732. `--ignore-case'
  733.      Ignore changes in case; consider upper- and lower-case to be the
  734.      same.  *Note Case Folding::.
  735. `--ignore-matching-lines=REGEXP'
  736.      Ignore changes that just insert or delete lines that match REGEXP.
  737.      *Note Specified Folding::.
  738. `--ignore-space-change'
  739.      Ignore changes in amount of white space.  *Note White Space::.
  740. `--left-column'
  741.      Print only the left column of two common lines.  *Note Side by
  742.      Side Format::.
  743. `--minimal'
  744.      Change the algorithm to perhaps find a smaller set of changes.
  745.      This makes `sdiff' slower (sometimes much slower).  *Note diff
  746.      Performance::.
  747. `-o FILE'
  748. `--output=FILE'
  749.      Put merged output into FILE.  This option is required for merging.
  750. `--suppress-common-lines'
  751.      Do not print common lines.  *Note Side by Side Format::.
  752. `--speed-large-files'
  753.      Use heuristics to speed handling of large files that have numerous
  754.      scattered small changes.  *Note diff Performance::.
  755.      Expand tabs to spaces in the output, to preserve the alignment of
  756.      tabs in the input files.  *Note Tabs::.
  757. `--text'
  758.      Treat all files as text and compare them line-by-line, even if they
  759.      do not appear to be text.  *Note Binary::.
  760. `--version'
  761.      Output the version number of `sdiff'.
  762. `-w COLUMNS'
  763. `--width=COLUMNS'
  764.      Use an output width of COLUMNS.  *Note Side by Side Format::.
  765.      Note that for historical reasons, this option is `-W' in `diff',
  766.      `-w' in `sdiff'.
  767.      Ignore horizontal white space when comparing lines.  *Note White
  768.      Space::.  Note that for historical reasons, this option is `-w' in
  769.      `diff', `-W' in `sdiff'.
  770. File: diff.info,  Node: Incomplete Lines,  Next: Projects,  Prev: Invoking sdiff,  Up: Top
  771. Incomplete Lines
  772. ****************
  773.    When an input file ends in a non-newline character, its last line is
  774. called an "incomplete line" because its last character is not a
  775. newline.  All other lines are called "full lines" and end in a newline
  776. character.  Incomplete lines do not match full lines unless differences
  777. in white space are ignored (*note White Space::.).
  778.    An incomplete line is normally distinguished on output from a full
  779. line by a following line that starts with `\'.  However, the RCS format
  780. (*note RCS::.) outputs the incomplete line as-is, without any trailing
  781. newline or following line.  The side by side format normally represents
  782. incomplete lines as-is, but in some cases uses a `\' or `/' gutter
  783. marker; *Note Side by Side::.  The if-then-else line format preserves a
  784. line's incompleteness with `%L', and discards the newline with `%l';
  785. *Note Line Formats::.  Finally, with the `ed' and forward `ed' output
  786. formats (*note Output Formats::.) `diff' cannot represent an incomplete
  787. line, so it pretends there was a newline and reports an error.
  788.    For example, suppose `F' and `G' are one-byte files that contain
  789. just `f' and `g', respectively.  Then `diff F G' outputs
  790.      1c1
  791.      < f
  792.      \ No newline at end of file
  793.      ---
  794.      > g
  795.      \ No newline at end of file
  796. (The exact message may differ in non-English locales.) `diff -n F G'
  797. outputs the following without a trailing newline:
  798.      d1 1
  799.      a1 1
  800.      g
  801.    `diff -e F G' reports two errors and outputs the following:
  802.      1c
  803.      g
  804.      .
  805. File: diff.info,  Node: Projects,  Next: Concept Index,  Prev: Incomplete Lines,  Up: Top
  806. Future Projects
  807. ***************
  808.    Here are some ideas for improving GNU `diff' and `patch'.  The GNU
  809. project has identified some improvements as potential programming
  810. projects for volunteers.  You can also help by reporting any bugs that
  811. you find.
  812.    If you are a programmer and would like to contribute something to the
  813. GNU project, please consider volunteering for one of these projects.  If
  814. you are seriously contemplating work, please write to
  815. `gnu@prep.ai.mit.edu' to coordinate with other volunteers.
  816. * Menu:
  817. * Shortcomings::    Suggested projects for improvements.
  818. * Bugs::        Reporting bugs.
  819. File: diff.info,  Node: Shortcomings,  Next: Bugs,  Up: Projects
  820. Suggested Projects for Improving GNU `diff' and `patch'
  821. =======================================================
  822.    One should be able to use GNU `diff' to generate a patch from any
  823. pair of directory trees, and given the patch and a copy of one such
  824. tree, use `patch' to generate a faithful copy of the other.
  825. Unfortunately, some changes to directory trees cannot be expressed using
  826. current patch formats; also, `patch' does not handle some of the
  827. existing formats.  These shortcomings motivate the following suggested
  828. projects.
  829. * Menu:
  830. * Changing Structure::    Handling changes to the directory structure.
  831. * Special Files::    Handling symbolic links, device special files, etc.
  832. * Unusual File Names::    Handling file names that contain unusual characters.
  833. * Arbitrary Limits::    Patching non-text files.
  834. * Large Files::        Handling files that do not fit in memory.
  835. * Ignoring Changes::    Ignoring certain changes while showing others.
  836. File: diff.info,  Node: Changing Structure,  Next: Special Files,  Up: Shortcomings
  837. Handling Changes to the Directory Structure
  838. -------------------------------------------
  839.    `diff' and `patch' do not handle some changes to directory
  840. structure.  For example, suppose one directory tree contains a directory
  841. named `D' with some subsidiary files, and another contains a file with
  842. the same name `D'.  `diff -r' does not output enough information for
  843. `patch' to transform the the directory subtree into the file.
  844.    There should be a way to specify that a file has been deleted without
  845. having to include its entire contents in the patch file.  There should
  846. also be a way to tell `patch' that a file was renamed, even if there is
  847. no way for `diff' to generate such information.
  848.    These problems can be fixed by extending the `diff' output format to
  849. represent changes in directory structure, and extending `patch' to
  850. understand these extensions.
  851. File: diff.info,  Node: Special Files,  Next: Unusual File Names,  Prev: Changing Structure,  Up: Shortcomings
  852. Files that are Neither Directories Nor Regular Files
  853. ----------------------------------------------------
  854.    Some files are neither directories nor regular files: they are
  855. unusual files like symbolic links, device special files, named pipes,
  856. and sockets.  Currently, `diff' treats symbolic links like regular
  857. files; it treats other special files like regular files if they are
  858. specified at the top level, but simply reports their presence when
  859. comparing directories.  This means that `patch' cannot represent changes
  860. to such files.  For example, if you change which file a symbolic link
  861. points to, `diff' outputs the difference between the two files, instead
  862. of the change to the symbolic link.
  863.    `diff' should optionally report changes to special files specially,
  864. and `patch' should be extended to understand these extensions.
  865. File: diff.info,  Node: Unusual File Names,  Next: Arbitrary Limits,  Prev: Special Files,  Up: Shortcomings
  866. File Names that Contain Unusual Characters
  867. ------------------------------------------
  868.    When a file name contains an unusual character like a newline or
  869. white space, `diff -r' generates a patch that `patch' cannot parse.
  870. The problem is with format of `diff' output, not just with `patch',
  871. because with odd enough file names one can cause `diff' to generate a
  872. patch that is syntactically correct but patches the wrong files.  The
  873. format of `diff' output should be extended to handle all possible file
  874. names.
  875. File: diff.info,  Node: Arbitrary Limits,  Next: Large Files,  Prev: Unusual File Names,  Up: Shortcomings
  876. Arbitrary Limits
  877. ----------------
  878.    GNU `diff' can analyze files with arbitrarily long lines and files
  879. that end in incomplete lines.  However, `patch' cannot patch such
  880. files.  The `patch' internal limits on line lengths should be removed,
  881. and `patch' should be extended to parse `diff' reports of incomplete
  882. lines.
  883. File: diff.info,  Node: Large Files,  Next: Ignoring Changes,  Prev: Arbitrary Limits,  Up: Shortcomings
  884. Handling Files that Do Not Fit in Memory
  885. ----------------------------------------
  886.    `diff' operates by reading both files into memory.  This method
  887. fails if the files are too large, and `diff' should have a fallback.
  888.    One way to do this is to scan the files sequentially to compute hash
  889. codes of the lines and put the lines in equivalence classes based only
  890. on hash code.  Then compare the files normally.  This does produce some
  891. false matches.
  892.    Then scan the two files sequentially again, checking each match to
  893. see whether it is real.  When a match is not real, mark both the
  894. "matching" lines as changed.  Then build an edit script as usual.
  895.    The output routines would have to be changed to scan the files
  896. sequentially looking for the text to print.
  897. File: diff.info,  Node: Ignoring Changes,  Prev: Large Files,  Up: Shortcomings
  898. Ignoring Certain Changes
  899. ------------------------
  900.    It would be nice to have a feature for specifying two strings, one in
  901. FROM-FILE and one in TO-FILE, which should be considered to match.
  902. Thus, if the two strings are `foo' and `bar', then if two lines differ
  903. only in that `foo' in file 1 corresponds to `bar' in file 2, the lines
  904. are treated as identical.
  905.    It is not clear how general this feature can or should be, or what
  906. syntax should be used for it.
  907. File: diff.info,  Node: Bugs,  Prev: Shortcomings,  Up: Projects
  908. Reporting Bugs
  909. ==============
  910.    If you think you have found a bug in GNU `cmp', `diff', `diff3',
  911. `sdiff', or `patch', please report it by electronic mail to
  912. `bug-gnu-utils@prep.ai.mit.edu'.  Send as precise a description of the
  913. problem as you can, including sample input files that produce the bug,
  914. if applicable.
  915.    Because Larry Wall has not released a new version of `patch' since
  916. mid 1988 and the GNU version of `patch' has been changed since then,
  917. please send bug reports for `patch' by electronic mail to both
  918. `bug-gnu-utils@prep.ai.mit.edu' and `lwall@netlabs.com'.
  919.