home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / diffutils-2.7-bin.lha / info / diff.info-1 (.txt) < prev    next >
GNU Info File  |  1996-10-12  |  48KB  |  907 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: Top,  Up: (dir)
  19.    This file documents the the GNU `diff', `diff3', `sdiff', and `cmp'
  20. commands for showing the differences between text files and the `patch'
  21. command for using their output to update files.
  22.    This is Edition 1.2, for `diff' 2.4 and `patch' 2.1.
  23. * Menu:
  24. * Overview::        Preliminary information.
  25. * Comparison::        What file comparison means.
  26. * Output Formats::    Formats for difference reports.
  27. * Comparing Directories::    Comparing files and directories.
  28. * Adjusting Output::    Making `diff' output prettier.
  29. * diff Performance::    Making `diff' smarter or faster.
  30. * Comparing Three Files:: Formats for three-way difference reports.
  31. * diff3 Merging::    Merging from a common ancestor.
  32. * Interactive Merging::    Interactive merging with `sdiff'.
  33. * Merging with patch::    Using `patch' to change old files into new ones.
  34. * Making Patches::    Tips for making patch distributions.
  35. * Invoking cmp::    How to run `cmp' and a summary of its options.
  36. * Invoking diff::    How to run `diff' and a summary of its options.
  37. * Invoking diff3::    How to run `diff3' and a summary of its options.
  38. * Invoking patch::    How to run `patch' and a summary of its options.
  39. * Invoking sdiff::    How to run `sdiff' and a summary of its options.
  40. * Incomplete Lines::    Lines that lack trailing newlines.
  41. * Projects::        If you think you've found a bug or other shortcoming.
  42. * Concept Index::    Index of concepts.
  43. File: diff.info,  Node: Overview,  Next: Comparison,  Up: Top
  44. Overview
  45. ********
  46.    Computer users often find occasion to ask how two files differ.
  47. Perhaps one file is a newer version of the other file.  Or maybe the
  48. two files started out as identical copies but were changed by different
  49. people.
  50.    You can use the `diff' command to show differences between two
  51. files, or each corresponding file in two directories.  `diff' outputs
  52. differences between files line by line in any of several formats,
  53. selectable by command line options.  This set of differences is often
  54. called a "diff" or "patch".  For files that are identical, `diff'
  55. normally produces no output; for binary (non-text) files, `diff'
  56. normally reports only that they are different.
  57.    You can use the `cmp' command to show the offsets and line numbers
  58. where two files differ.  `cmp' can also show all the characters that
  59. differ between the two files, side by side.  Another way to compare two
  60. files character by character is the Emacs command `M-x
  61. compare-windows'.  *Note Other Window: (emacs)Other Window, for more
  62. information on that command.
  63.    You can use the `diff3' command to show differences among three
  64. files.  When two people have made independent changes to a common
  65. original, `diff3' can report the differences between the original and
  66. the two changed versions, and can produce a merged file that contains
  67. both persons' changes together with warnings about conflicts.
  68.    You can use the `sdiff' command to merge two files interactively.
  69.    You can use the set of differences produced by `diff' to distribute
  70. updates to text files (such as program source code) to other people.
  71. This method is especially useful when the differences are small compared
  72. to the complete files.  Given `diff' output, you can use the `patch'
  73. program to update, or "patch", a copy of the file.  If you think of
  74. `diff' as subtracting one file from another to produce their
  75. difference, you can think of `patch' as adding the difference to one
  76. file to reproduce the other.
  77.    This manual first concentrates on making diffs, and later shows how
  78. to use diffs to update files.
  79.    GNU `diff' was written by Mike Haertel, David Hayes, Richard
  80. Stallman, Len Tower, and Paul Eggert.  Wayne Davison designed and
  81. implemented the unified output format.  The basic algorithm is described
  82. in "An O(ND) Difference Algorithm and its Variations", Eugene W. Myers,
  83. `Algorithmica' Vol. 1 No. 2, 1986, pp. 251-266; and in "A File
  84. Comparison Program", Webb Miller and Eugene W. Myers,
  85. `Software--Practice and Experience' Vol. 15 No. 11, 1985, pp. 1025-1040.
  86. The algorithm was independently discovered as described in "Algorithms
  87. for Approximate String Matching", E. Ukkonen, `Information and Control'
  88. Vol. 64, 1985, pp. 100-118.
  89.    GNU `diff3' was written by Randy Smith.  GNU `sdiff' was written by
  90. Thomas Lord.  GNU `cmp' was written by Torbjorn Granlund and David
  91. MacKenzie.
  92.    `patch' was written mainly by Larry Wall; the GNU enhancements were
  93. written mainly by Wayne Davison and David MacKenzie.  Parts of this
  94. manual are adapted from a manual page written by Larry Wall, with his
  95. permission.
  96. File: diff.info,  Node: Comparison,  Next: Output Formats,  Prev: Overview,  Up: Top
  97. What Comparison Means
  98. *********************
  99.    There are several ways to think about the differences between two
  100. files.  One way to think of the differences is as a series of lines
  101. that were deleted from, inserted in, or changed in one file to produce
  102. the other file.  `diff' compares two files line by line, finds groups of
  103. lines that differ, and reports each group of differing lines.  It can
  104. report the differing lines in several formats, which have different
  105. purposes.
  106.    GNU `diff' can show whether files are different without detailing
  107. the differences.  It also provides ways to suppress certain kinds of
  108. differences that are not important to you.  Most commonly, such
  109. differences are changes in the amount of white space between words or
  110. lines.  `diff' also provides ways to suppress differences in alphabetic
  111. case or in lines that match a regular expression that you provide.
  112. These options can accumulate; for example, you can ignore changes in
  113. both white space and alphabetic case.
  114.    Another way to think of the differences between two files is as a
  115. sequence of pairs of characters that can be either identical or
  116. different.  `cmp' reports the differences between two files character
  117. by character, instead of line by line.  As a result, it is more useful
  118. than `diff' for comparing binary files.  For text files, `cmp' is
  119. useful mainly when you want to know only whether two files are
  120. identical.
  121.    To illustrate the effect that considering changes character by
  122. character can have compared with considering them line by line, think
  123. of what happens if a single newline character is added to the beginning
  124. of a file.  If that file is then compared with an otherwise identical
  125. file that lacks the newline at the beginning, `diff' will report that a
  126. blank line has been added to the file, while `cmp' will report that
  127. almost every character of the two files differs.
  128.    `diff3' normally compares three input files line by line, finds
  129. groups of lines that differ, and reports each group of differing lines.
  130. Its output is designed to make it easy to inspect two different sets of
  131. changes to the same file.
  132. * Menu:
  133. * Hunks::        Groups of differing lines.
  134. * White Space::        Suppressing differences in white space.
  135. * Blank Lines::        Suppressing differences in blank lines.
  136. * Case Folding::    Suppressing differences in alphabetic case.
  137. * Specified Folding::    Suppressing differences that match regular expressions.
  138. * Brief::        Summarizing which files are different.
  139. * Binary::        Comparing binary files or forcing text comparisons.
  140. File: diff.info,  Node: Hunks,  Next: White Space,  Up: Comparison
  141. Hunks
  142. =====
  143.    When comparing two files, `diff' finds sequences of lines common to
  144. both files, interspersed with groups of differing lines called "hunks".
  145. Comparing two identical files yields one sequence of common lines and
  146. no hunks, because no lines differ.  Comparing two entirely different
  147. files yields no common lines and one large hunk that contains all lines
  148. of both files.  In general, there are many ways to match up lines
  149. between two given files.  `diff' tries to minimize the total hunk size
  150. by finding large sequences of common lines interspersed with small
  151. hunks of differing lines.
  152.    For example, suppose the file `F' contains the three lines `a', `b',
  153. `c', and the file `G' contains the same three lines in reverse order
  154. `c', `b', `a'.  If `diff' finds the line `c' as common, then the command
  155. `diff F G' produces this output:
  156.      1,2d0
  157.      < a
  158.      < b
  159.      3a2,3
  160.      > b
  161.      > a
  162. But if `diff' notices the common line `b' instead, it produces this
  163. output:
  164.      1c1
  165.      < a
  166.      ---
  167.      > c
  168.      3c3
  169.      < c
  170.      ---
  171.      > a
  172. It is also possible to find `a' as the common line.  `diff' does not
  173. always find an optimal matching between the files; it takes shortcuts
  174. to run faster.  But its output is usually close to the shortest
  175. possible.  You can adjust this tradeoff with the `--minimal' option
  176. (*note diff Performance::.).
  177. File: diff.info,  Node: White Space,  Next: Blank Lines,  Prev: Hunks,  Up: Comparison
  178. Suppressing Differences in Blank and Tab Spacing
  179. ================================================
  180.    The `-b' and `--ignore-space-change' options ignore white space at
  181. line end, and considers all other sequences of one or more white space
  182. characters to be equivalent.  With these options, `diff' considers the
  183. following two lines to be equivalent, where `$' denotes the line end:
  184.      Here lyeth  muche rychnesse  in lytell space.   -- John Heywood$
  185.      Here lyeth muche rychnesse in lytell space. -- John Heywood   $
  186.    The `-w' and `--ignore-all-space' options are stronger than `-b'.
  187. They ignore difference even if one file has white space where the other
  188. file has none.  "White space" characters include tab, newline, vertical
  189. tab, form feed, carriage return, and space; some locales may define
  190. additional characters to be white space.  With these options, `diff'
  191. considers the following two lines to be equivalent, where `$' denotes
  192. the line end and `^M' denotes a carriage return:
  193.      Here lyeth  muche  rychnesse in lytell space.--  John Heywood$
  194.        He relyeth much erychnes  seinly tells pace.  --John Heywood   ^M$
  195. File: diff.info,  Node: Blank Lines,  Next: Case Folding,  Prev: White Space,  Up: Comparison
  196. Suppressing Differences in Blank Lines
  197. ======================================
  198.    The `-B' and `--ignore-blank-lines' options ignore insertions or
  199. deletions of blank lines.  These options normally affect only lines
  200. that are completely empty; they do not affect lines that look empty but
  201. contain space or tab characters.  With these options, for example, a
  202. file containing
  203.      1.  A point is that which has no part.
  204.      
  205.      2.  A line is breadthless length.
  206.      -- Euclid, The Elements, I
  207. is considered identical to a file containing
  208.      1.  A point is that which has no part.
  209.      2.  A line is breadthless length.
  210.      
  211.      
  212.      -- Euclid, The Elements, I
  213. File: diff.info,  Node: Case Folding,  Next: Specified Folding,  Prev: Blank Lines,  Up: Comparison
  214. Suppressing Case Differences
  215. ============================
  216.    GNU `diff' can treat lowercase letters as equivalent to their
  217. uppercase counterparts, so that, for example, it considers `Funky
  218. Stuff', `funky STUFF', and `fUNKy stuFf' to all be the same.  To
  219. request this, use the `-i' or `--ignore-case' option.
  220. File: diff.info,  Node: Specified Folding,  Next: Brief,  Prev: Case Folding,  Up: Comparison
  221. Suppressing Lines Matching a Regular Expression
  222. ===============================================
  223.    To ignore insertions and deletions of lines that match a regular
  224. expression, use the `-I REGEXP' or `--ignore-matching-lines=REGEXP'
  225. option.  You should escape regular expressions that contain shell
  226. metacharacters to prevent the shell from expanding them.  For example,
  227. `diff -I '^[0-9]'' ignores all changes to lines beginning with a digit.
  228.    However, `-I' only ignores the insertion or deletion of lines that
  229. contain the regular expression if every changed line in the hunk--every
  230. insertion and every deletion--matches the regular expression.  In other
  231. words, for each nonignorable change, `diff' prints the complete set of
  232. changes in its vicinity, including the ignorable ones.
  233.    You can specify more than one regular expression for lines to ignore
  234. by using more than one `-I' option.  `diff' tries to match each line
  235. against each regular expression, starting with the last one given.
  236. File: diff.info,  Node: Brief,  Next: Binary,  Prev: Specified Folding,  Up: Comparison
  237. Summarizing Which Files Differ
  238. ==============================
  239.    When you only want to find out whether files are different, and you
  240. don't care what the differences are, you can use the summary output
  241. format.  In this format, instead of showing the differences between the
  242. files, `diff' simply reports whether files differ.  The `-q' and
  243. `--brief' options select this output format.
  244.    This format is especially useful when comparing the contents of two
  245. directories.  It is also much faster than doing the normal line by line
  246. comparisons, because `diff' can stop analyzing the files as soon as it
  247. knows that there are any differences.
  248.    You can also get a brief indication of whether two files differ by
  249. using `cmp'.  For files that are identical, `cmp' produces no output.
  250. When the files differ, by default, `cmp' outputs the byte offset and
  251. line number where the first difference occurs.  You can use the `-s'
  252. option to suppress that information, so that `cmp' produces no output
  253. and reports whether the files differ using only its exit status (*note
  254. Invoking cmp::.).
  255.    Unlike `diff', `cmp' cannot compare directories; it can only compare
  256. two files.
  257. File: diff.info,  Node: Binary,  Prev: Brief,  Up: Comparison
  258. Binary Files and Forcing Text Comparisons
  259. =========================================
  260.    If `diff' thinks that either of the two files it is comparing is
  261. binary (a non-text file), it normally treats that pair of files much as
  262. if the summary output format had been selected (*note Brief::.), and
  263. reports only that the binary files are different.  This is because line
  264. by line comparisons are usually not meaningful for binary files.
  265.    `diff' determines whether a file is text or binary by checking the
  266. first few bytes in the file; the exact number of bytes is system
  267. dependent, but it is typically several thousand.  If every character in
  268. that part of the file is non-null, `diff' considers the file to be
  269. text; otherwise it considers the file to be binary.
  270.    Sometimes you might want to force `diff' to consider files to be
  271. text.  For example, you might be comparing text files that contain null
  272. characters; `diff' would erroneously decide that those are non-text
  273. files.  Or you might be comparing documents that are in a format used
  274. by a word processing system that uses null characters to indicate
  275. special formatting.  You can force `diff' to consider all files to be
  276. text files, and compare them line by line, by using the `-a' or
  277. `--text' option.  If the files you compare using this option do not in
  278. fact contain text, they will probably contain few newline characters,
  279. and the `diff' output will consist of hunks showing differences between
  280. long lines of whatever characters the files contain.
  281.    You can also force `diff' to consider all files to be binary files,
  282. and report only whether they differ (but not how).  Use the `--brief'
  283. option for this.
  284.    In operating systems that distinguish between text and binary files,
  285. `diff' normally reads and writes all data as text.  Use the `--binary'
  286. option to force `diff' to read and write binary data instead.  This
  287. option has no effect on a Posix-compliant system like GNU or
  288. traditional Unix.  However, many personal computer operating systems
  289. represent the end of a line with a carriage return followed by a
  290. newline.  On such systems, `diff' normally ignores these carriage
  291. returns on input and generates them at the end of each output line, but
  292. with the `--binary' option `diff' treats each carriage return as just
  293. another input character, and does not generate a carriage return at the
  294. end of each output line.  This can be useful when dealing with non-text
  295. files that are meant to be interchanged with Posix-compliant systems.
  296.    If you want to compare two files byte by byte, you can use the `cmp'
  297. program with the `-l' option to show the values of each differing byte
  298. in the two files.  With GNU `cmp', you can also use the `-c' option to
  299. show the ASCII representation of those bytes.  *Note Invoking cmp::,
  300. for more information.
  301.    If `diff3' thinks that any of the files it is comparing is binary (a
  302. non-text file), it normally reports an error, because such comparisons
  303. are usually not useful.  `diff3' uses the same test as `diff' to decide
  304. whether a file is binary.  As with `diff', if the input files contain a
  305. few non-text characters but otherwise are like text files, you can
  306. force `diff3' to consider all files to be text files and compare them
  307. line by line by using the `-a' or `--text' options.
  308. File: diff.info,  Node: Output Formats,  Next: Comparing Directories,  Prev: Comparison,  Up: Top
  309. `diff' Output Formats
  310. *********************
  311.    `diff' has several mutually exclusive options for output format.
  312. The following sections describe each format, illustrating how `diff'
  313. reports the differences between two sample input files.
  314. * Menu:
  315. * Sample diff Input::    Sample `diff' input files for examples.
  316. * Normal::        Showing differences without surrounding text.
  317. * Context::        Showing differences with the surrounding text.
  318. * Side by Side::        Showing differences in two columns.
  319. * Scripts::        Generating scripts for other programs.
  320. * If-then-else::    Merging files with if-then-else.
  321. File: diff.info,  Node: Sample diff Input,  Next: Normal,  Up: Output Formats
  322. Two Sample Input Files
  323. ======================
  324.    Here are two sample files that we will use in numerous examples to
  325. illustrate the output of `diff' and how various options can change it.
  326.    This is the file `lao':
  327.      The Way that can be told of is not the eternal Way;
  328.      The name that can be named is not the eternal name.
  329.      The Nameless is the origin of Heaven and Earth;
  330.      The Named is the mother of all things.
  331.      Therefore let there always be non-being,
  332.        so we may see their subtlety,
  333.      And let there always be being,
  334.        so we may see their outcome.
  335.      The two are the same,
  336.      But after they are produced,
  337.        they have different names.
  338.    This is the file `tzu':
  339.      The Nameless is the origin of Heaven and Earth;
  340.      The named is the mother of all things.
  341.      
  342.      Therefore let there always be non-being,
  343.        so we may see their subtlety,
  344.      And let there always be being,
  345.        so we may see their outcome.
  346.      The two are the same,
  347.      But after they are produced,
  348.        they have different names.
  349.      They both may be called deep and profound.
  350.      Deeper and more profound,
  351.      The door of all subtleties!
  352.    In this example, the first hunk contains just the first two lines of
  353. `lao', the second hunk contains the fourth line of `lao' opposing the
  354. second and third lines of `tzu', and the last hunk contains just the
  355. last three lines of `tzu'.
  356. File: diff.info,  Node: Normal,  Next: Context,  Prev: Sample diff Input,  Up: Output Formats
  357. Showing Differences Without Context
  358. ===================================
  359.    The "normal" `diff' output format shows each hunk of differences
  360. without any surrounding context.  Sometimes such output is the clearest
  361. way to see how lines have changed, without the clutter of nearby
  362. unchanged lines (although you can get similar results with the context
  363. or unified formats by using 0 lines of context).  However, this format
  364. is no longer widely used for sending out patches; for that purpose, the
  365. context format (*note Context Format::.) and the unified format (*note
  366. Unified Format::.) are superior.  Normal format is the default for
  367. compatibility with older versions of `diff' and the Posix standard.
  368. * Menu:
  369. * Detailed Normal::    A detailed description of normal output format.
  370. * Example Normal::    Sample output in the normal format.
  371. File: diff.info,  Node: Detailed Normal,  Next: Example Normal,  Up: Normal
  372. Detailed Description of Normal Format
  373. -------------------------------------
  374.    The normal output format consists of one or more hunks of
  375. differences; each hunk shows one area where the files differ.  Normal
  376. format hunks look like this:
  377.      CHANGE-COMMAND
  378.      < FROM-FILE-LINE
  379.      < FROM-FILE-LINE...
  380.      ---
  381.      > TO-FILE-LINE
  382.      > TO-FILE-LINE...
  383.    There are three types of change commands.  Each consists of a line
  384. number or comma-separated range of lines in the first file, a single
  385. character indicating the kind of change to make, and a line number or
  386. comma-separated range of lines in the second file.  All line numbers are
  387. the original line numbers in each file.  The types of change commands
  388. `LaR'
  389.      Add the lines in range R of the second file after line L of the
  390.      first file.  For example, `8a12,15' means append lines 12-15 of
  391.      file 2 after line 8 of file 1; or, if changing file 2 into file 1,
  392.      delete lines 12-15 of file 2.
  393. `FcT'
  394.      Replace the lines in range F of the first file with lines in range
  395.      T of the second file.  This is like a combined add and delete, but
  396.      more compact.  For example, `5,7c8,10' means change lines 5-7 of
  397.      file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
  398.      file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.
  399. `RdL'
  400.      Delete the lines in range R from the first file; line L is where
  401.      they would have appeared in the second file had they not been
  402.      deleted.  For example, `5,7d3' means delete lines 5-7 of file 1;
  403.      or, if changing file 2 into file 1, append lines 5-7 of file 1
  404.      after line 3 of file 2.
  405. File: diff.info,  Node: Example Normal,  Prev: Detailed Normal,  Up: Normal
  406. An Example of Normal Format
  407. ---------------------------
  408.    Here is the output of the command `diff lao tzu' (*note Sample diff
  409. Input::., for the complete contents of the two files).  Notice that it
  410. shows only the lines that are different between the two files.
  411.      1,2d0
  412.      < The Way that can be told of is not the eternal Way;
  413.      < The name that can be named is not the eternal name.
  414.      4c2,3
  415.      < The Named is the mother of all things.
  416.      ---
  417.      > The named is the mother of all things.
  418.      >
  419.      11a11,13
  420.      > They both may be called deep and profound.
  421.      > Deeper and more profound,
  422.      > The door of all subtleties!
  423. File: diff.info,  Node: Context,  Next: Side by Side,  Prev: Normal,  Up: Output Formats
  424. Showing Differences in Their Context
  425. ====================================
  426.    Usually, when you are looking at the differences between files, you
  427. will also want to see the parts of the files near the lines that
  428. differ, to help you understand exactly what has changed.  These nearby
  429. parts of the files are called the "context".
  430.    GNU `diff' provides two output formats that show context around the
  431. differing lines: "context format" and "unified format".  It can
  432. optionally show in which function or section of the file the differing
  433. lines are found.
  434.    If you are distributing new versions of files to other people in the
  435. form of `diff' output, you should use one of the output formats that
  436. show context so that they can apply the diffs even if they have made
  437. small changes of their own to the files.  `patch' can apply the diffs
  438. in this case by searching in the files for the lines of context around
  439. the differing lines; if those lines are actually a few lines away from
  440. where the diff says they are, `patch' can adjust the line numbers
  441. accordingly and still apply the diff correctly.  *Note Imperfect::, for
  442. more information on using `patch' to apply imperfect diffs.
  443. * Menu:
  444. * Context Format::    An output format that shows surrounding lines.
  445. * Unified Format::    A more compact output format that shows context.
  446. * Sections::        Showing which sections of the files differences are in.
  447. * Alternate Names::    Showing alternate file names in context headers.
  448. File: diff.info,  Node: Context Format,  Next: Unified Format,  Up: Context
  449. Context Format
  450. --------------
  451.    The context output format shows several lines of context around the
  452. lines that differ.  It is the standard format for distributing updates
  453. to source code.
  454.    To select this output format, use the `-C LINES',
  455. `--context[=LINES]', or `-c' option.  The argument LINES that some of
  456. these options take is the number of lines of context to show.  If you
  457. do not specify LINES, it defaults to three.  For proper operation,
  458. `patch' typically needs at least two lines of context.
  459. * Menu:
  460. * Detailed Context::    A detailed description of the context output format.
  461. * Example Context::    Sample output in context format.
  462. * Less Context::    Another sample with less context.
  463. File: diff.info,  Node: Detailed Context,  Next: Example Context,  Up: Context Format
  464. Detailed Description of Context Format
  465. ......................................
  466.    The context output format starts with a two-line header, which looks
  467. like this:
  468.      *** FROM-FILE FROM-FILE-MODIFICATION-TIME
  469.      --- TO-FILE TO-FILE-MODIFICATION TIME
  470. You can change the header's content with the `-L LABEL' or
  471. `--label=LABEL' option; see *Note Alternate Names::.
  472.    Next come one or more hunks of differences; each hunk shows one area
  473. where the files differ.  Context format hunks look like this:
  474.      ***************
  475.      *** FROM-FILE-LINE-RANGE ****
  476.        FROM-FILE-LINE
  477.        FROM-FILE-LINE...
  478.      --- TO-FILE-LINE-RANGE ----
  479.        TO-FILE-LINE
  480.        TO-FILE-LINE...
  481.    The lines of context around the lines that differ start with two
  482. space characters.  The lines that differ between the two files start
  483. with one of the following indicator characters, followed by a space
  484. character:
  485.      A line that is part of a group of one or more lines that changed
  486.      between the two files.  There is a corresponding group of lines
  487.      marked with `!' in the part of this hunk for the other file.
  488.      An "inserted" line in the second file that corresponds to nothing
  489.      in the first file.
  490.      A "deleted" line in the first file that corresponds to nothing in
  491.      the second file.
  492.    If all of the changes in a hunk are insertions, the lines of
  493. FROM-FILE are omitted.  If all of the changes are deletions, the lines
  494. of TO-FILE are omitted.
  495. File: diff.info,  Node: Example Context,  Next: Less Context,  Prev: Detailed Context,  Up: Context Format
  496. An Example of Context Format
  497. ............................
  498.    Here is the output of `diff -c lao tzu' (*note Sample diff Input::.,
  499. for the complete contents of the two files).  Notice that up to three
  500. lines that are not different are shown around each line that is
  501. different; they are the context lines.  Also notice that the first two
  502. hunks have run together, because their contents overlap.
  503.      *** lao    Sat Jan 26 23:30:39 1991
  504.      --- tzu    Sat Jan 26 23:30:50 1991
  505.      ***************
  506.      *** 1,7 ****
  507.      - The Way that can be told of is not the eternal Way;
  508.      - The name that can be named is not the eternal name.
  509.        The Nameless is the origin of Heaven and Earth;
  510.      ! The Named is the mother of all things.
  511.        Therefore let there always be non-being,
  512.          so we may see their subtlety,
  513.        And let there always be being,
  514.      --- 1,6 ----
  515.        The Nameless is the origin of Heaven and Earth;
  516.      ! The named is the mother of all things.
  517.      !
  518.        Therefore let there always be non-being,
  519.          so we may see their subtlety,
  520.        And let there always be being,
  521.      ***************
  522.      *** 9,11 ****
  523.      --- 8,13 ----
  524.        The two are the same,
  525.        But after they are produced,
  526.          they have different names.
  527.      + They both may be called deep and profound.
  528.      + Deeper and more profound,
  529.      + The door of all subtleties!
  530. File: diff.info,  Node: Less Context,  Prev: Example Context,  Up: Context Format
  531. An Example of Context Format with Less Context
  532. ..............................................
  533.    Here is the output of `diff --context=1 lao tzu' (*note Sample diff
  534. Input::., for the complete contents of the two files).  Notice that at
  535. most one context line is reported here.
  536.      *** lao    Sat Jan 26 23:30:39 1991
  537.      --- tzu    Sat Jan 26 23:30:50 1991
  538.      ***************
  539.      *** 1,5 ****
  540.      - The Way that can be told of is not the eternal Way;
  541.      - The name that can be named is not the eternal name.
  542.        The Nameless is the origin of Heaven and Earth;
  543.      ! The Named is the mother of all things.
  544.        Therefore let there always be non-being,
  545.      --- 1,4 ----
  546.        The Nameless is the origin of Heaven and Earth;
  547.      ! The named is the mother of all things.
  548.      !
  549.        Therefore let there always be non-being,
  550.      ***************
  551.      *** 11 ****
  552.      --- 10,13 ----
  553.          they have different names.
  554.      + They both may be called deep and profound.
  555.      + Deeper and more profound,
  556.      + The door of all subtleties!
  557. File: diff.info,  Node: Unified Format,  Next: Sections,  Prev: Context Format,  Up: Context
  558. Unified Format
  559. --------------
  560.    The unified output format is a variation on the context format that
  561. is more compact because it omits redundant context lines.  To select
  562. this output format, use the `-U LINES', `--unified[=LINES]', or `-u'
  563. option.  The argument LINES is the number of lines of context to show.
  564. When it is not given, it defaults to three.
  565.    At present, only GNU `diff' can produce this format and only GNU
  566. `patch' can automatically apply diffs in this format.  For proper
  567. operation, `patch' typically needs at least two lines of context.
  568. * Menu:
  569. * Detailed Unified::    A detailed description of unified format.
  570. * Example Unified::    Sample output in unified format.
  571. File: diff.info,  Node: Detailed Unified,  Next: Example Unified,  Up: Unified Format
  572. Detailed Description of Unified Format
  573. ......................................
  574.    The unified output format starts with a two-line header, which looks
  575. like this:
  576.      --- FROM-FILE FROM-FILE-MODIFICATION-TIME
  577.      +++ TO-FILE TO-FILE-MODIFICATION-TIME
  578. You can change the header's content with the `-L LABEL' or
  579. `--label=LABEL' option; see *Note Alternate Names::.
  580.    Next come one or more hunks of differences; each hunk shows one area
  581. where the files differ.  Unified format hunks look like this:
  582.      @@ FROM-FILE-RANGE TO-FILE-RANGE @@
  583.       LINE-FROM-EITHER-FILE
  584.       LINE-FROM-EITHER-FILE...
  585.    The lines common to both files begin with a space character.  The
  586. lines that actually differ between the two files have one of the
  587. following indicator characters in the left column:
  588.      A line was added here to the first file.
  589.      A line was removed here from the first file.
  590. File: diff.info,  Node: Example Unified,  Prev: Detailed Unified,  Up: Unified Format
  591. An Example of Unified Format
  592. ............................
  593.    Here is the output of the command `diff -u lao tzu' (*note Sample
  594. diff Input::., for the complete contents of the two files):
  595.      --- lao    Sat Jan 26 23:30:39 1991
  596.      +++ tzu    Sat Jan 26 23:30:50 1991
  597.      @@ -1,7 +1,6 @@
  598.      -The Way that can be told of is not the eternal Way;
  599.      -The name that can be named is not the eternal name.
  600.       The Nameless is the origin of Heaven and Earth;
  601.      -The Named is the mother of all things.
  602.      +The named is the mother of all things.
  603.      +
  604.       Therefore let there always be non-being,
  605.         so we may see their subtlety,
  606.       And let there always be being,
  607.      @@ -9,3 +8,6 @@
  608.       The two are the same,
  609.       But after they are produced,
  610.         they have different names.
  611.      +They both may be called deep and profound.
  612.      +Deeper and more profound,
  613.      +The door of all subtleties!
  614. File: diff.info,  Node: Sections,  Next: Alternate Names,  Prev: Unified Format,  Up: Context
  615. Showing Which Sections Differences Are in
  616. -----------------------------------------
  617.    Sometimes you might want to know which part of the files each change
  618. falls in.  If the files are source code, this could mean which function
  619. was changed.  If the files are documents, it could mean which chapter or
  620. appendix was changed.  GNU `diff' can show this by displaying the
  621. nearest section heading line that precedes the differing lines.  Which
  622. lines are "section headings" is determined by a regular expression.
  623. * Menu:
  624. * Specified Headings::    Showing headings that match regular expressions.
  625. * C Function Headings::    Showing headings of C functions.
  626. File: diff.info,  Node: Specified Headings,  Next: C Function Headings,  Up: Sections
  627. Showing Lines That Match Regular Expressions
  628. ............................................
  629.    To show in which sections differences occur for files that are not
  630. source code for C or similar languages, use the `-F REGEXP' or
  631. `--show-function-line=REGEXP' option.  `diff' considers lines that
  632. match the argument REGEXP to be the beginning of a section of the file.
  633. Here are suggested regular expressions for some common languages:
  634. `^[A-Za-z_]'
  635.      C, C++, Prolog
  636.      Lisp
  637. `^@\(chapter\|appendix\|unnumbered\|chapheading\)'
  638.      Texinfo
  639.    This option does not automatically select an output format; in order
  640. to use it, you must select the context format (*note Context Format::.)
  641. or unified format (*note Unified Format::.).  In other output formats it
  642. has no effect.
  643.    The `-F' and `--show-function-line' options find the nearest
  644. unchanged line that precedes each hunk of differences and matches the
  645. given regular expression.  Then they add that line to the end of the
  646. line of asterisks in the context format, or to the `@@' line in unified
  647. format.  If no matching line exists, they leave the output for that
  648. hunk unchanged.  If that line is more than 40 characters long, they
  649. output only the first 40 characters.  You can specify more than one
  650. regular expression for such lines; `diff' tries to match each line
  651. against each regular expression, starting with the last one given.  This
  652. means that you can use `-p' and `-F' together, if you wish.
  653. File: diff.info,  Node: C Function Headings,  Prev: Specified Headings,  Up: Sections
  654. Showing C Function Headings
  655. ...........................
  656.    To show in which functions differences occur for C and similar
  657. languages, you can use the `-p' or `--show-c-function' option.  This
  658. option automatically defaults to the context output format (*note
  659. Context Format::.), with the default number of lines of context.  You
  660. can override that number with `-C LINES' elsewhere in the command line.
  661. You can override both the format and the number with `-U LINES'
  662. elsewhere in the command line.
  663.    The `-p' and `--show-c-function' options are equivalent to
  664. `-F'^[_a-zA-Z$]'' if the unified format is specified, otherwise `-c
  665. -F'^[_a-zA-Z$]'' (*note Specified Headings::.).  GNU `diff' provides
  666. them for the sake of convenience.
  667. File: diff.info,  Node: Alternate Names,  Prev: Sections,  Up: Context
  668. Showing Alternate File Names
  669. ----------------------------
  670.    If you are comparing two files that have meaningless or uninformative
  671. names, you might want `diff' to show alternate names in the header of
  672. the context and unified output formats.  To do this, use the `-L LABEL'
  673. or `--label=LABEL' option.  The first time you give this option, its
  674. argument replaces the name and date of the first file in the header;
  675. the second time, its argument replaces the name and date of the second
  676. file.  If you give this option more than twice, `diff' reports an
  677. error.  The `-L' option does not affect the file names in the `pr'
  678. header when the `-l' or `--paginate' option is used (*note
  679. Pagination::.).
  680.    Here are the first two lines of the output from `diff -C2 -Loriginal
  681. -Lmodified lao tzu':
  682.      *** original
  683.      --- modified
  684. File: diff.info,  Node: Side by Side,  Next: Scripts,  Prev: Context,  Up: Output Formats
  685. Showing Differences Side by Side
  686. ================================
  687.    `diff' can produce a side by side difference listing of two files.
  688. The files are listed in two columns with a gutter between them.  The
  689. gutter contains one of the following markers:
  690. white space
  691.      The corresponding lines are in common.  That is, either the lines
  692.      are identical, or the difference is ignored because of one of the
  693.      `--ignore' options (*note White Space::.).
  694.      The corresponding lines differ, and they are either both complete
  695.      or both incomplete.
  696.      The files differ and only the first file contains the line.
  697.      The files differ and only the second file contains the line.
  698.      Only the first file contains the line, but the difference is
  699.      ignored.
  700.      Only the second file contains the line, but the difference is
  701.      ignored.
  702.      The corresponding lines differ, and only the first line is
  703.      incomplete.
  704.      The corresponding lines differ, and only the second line is
  705.      incomplete.
  706.    Normally, an output line is incomplete if and only if the lines that
  707. it contains are incomplete; *Note Incomplete Lines::.  However, when an
  708. output line represents two differing lines, one might be incomplete
  709. while the other is not.  In this case, the output line is complete, but
  710. its the gutter is marked `\' if the first line is incomplete, `/' if
  711. the second line is.
  712.    Side by side format is sometimes easiest to read, but it has
  713. limitations.  It generates much wider output than usual, and truncates
  714. lines that are too long to fit.  Also, it relies on lining up output
  715. more heavily than usual, so its output looks particularly bad if you
  716. use varying width fonts, nonstandard tab stops, or nonprinting
  717. characters.
  718.    You can use the `sdiff' command to interactively merge side by side
  719. differences.  *Note Interactive Merging::, for more information on
  720. merging files.
  721. * Menu:
  722. * Side by Side Format::        Controlling side by side output format.
  723. * Example Side by Side::    Sample side by side output.
  724. File: diff.info,  Node: Side by Side Format,  Next: Example Side by Side,  Up: Side by Side
  725. Controlling Side by Side Format
  726. ===============================
  727.    The `-y' or `--side-by-side' option selects side by side format.
  728. Because side by side output lines contain two input lines, they are
  729. wider than usual.  They are normally 130 columns, which can fit onto a
  730. traditional printer line.  You can set the length of output lines with
  731. the `-W COLUMNS' or `--width=COLUMNS' option.  The output line is split
  732. into two halves of equal length, separated by a small gutter to mark
  733. differences; the right half is aligned to a tab stop so that tabs line
  734. up.  Input lines that are too long to fit in half of an output line are
  735. truncated for output.
  736.    The `--left-column' option prints only the left column of two common
  737. lines.  The `--suppress-common-lines' option suppresses common lines
  738. entirely.
  739. File: diff.info,  Node: Example Side by Side,  Prev: Side by Side Format,  Up: Side by Side
  740. An Example of Side by Side Format
  741. ---------------------------------
  742.    Here is the output of the command `diff -y -W 72 lao tzu' (*note
  743. Sample diff Input::., for the complete contents of the two files).
  744.      The Way that can be told of is n   <
  745.      The name that can be named is no   <
  746.      The Nameless is the origin of He        The Nameless is the origin of He
  747.      The Named is the mother of all t   |    The named is the mother of all t
  748.                                         >
  749.      Therefore let there always be no        Therefore let there always be no
  750.        so we may see their subtlety,           so we may see their subtlety,
  751.      And let there always be being,          And let there always be being,
  752.        so we may see their outcome.            so we may see their outcome.
  753.      The two are the same,                   The two are the same,
  754.      But after they are produced,            But after they are produced,
  755.        they have different names.              they have different names.
  756.                                         >    They both may be called deep and
  757.                                         >    Deeper and more profound,
  758.                                         >    The door of all subtleties!
  759. File: diff.info,  Node: Scripts,  Next: If-then-else,  Prev: Side by Side,  Up: Output Formats
  760. Making Edit Scripts
  761. ===================
  762.    Several output modes produce command scripts for editing FROM-FILE
  763. to produce TO-FILE.
  764. * Menu:
  765. * ed Scripts::        Using `diff' to produce commands for `ed'.
  766. * Forward ed::        Making forward `ed' scripts.
  767. * RCS::            A special `diff' output format used by RCS.
  768. File: diff.info,  Node: ed Scripts,  Next: Forward ed,  Up: Scripts
  769. `ed' Scripts
  770. ------------
  771.    `diff' can produce commands that direct the `ed' text editor to
  772. change the first file into the second file.  Long ago, this was the
  773. only output mode that was suitable for editing one file into another
  774. automatically; today, with `patch', it is almost obsolete.  Use the
  775. `-e' or `--ed' option to select this output format.
  776.    Like the normal format (*note Normal::.), this output format does not
  777. show any context; unlike the normal format, it does not include the
  778. information necessary to apply the diff in reverse (to produce the first
  779. file if all you have is the second file and the diff).
  780.    If the file `d' contains the output of `diff -e old new', then the
  781. command `(cat d && echo w) | ed - old' edits `old' to make it a copy of
  782. `new'.  More generally, if `d1', `d2', ..., `dN' contain the outputs of
  783. `diff -e old new1', `diff -e new1 new2', ..., `diff -e newN-1 newN',
  784. respectively, then the command `(cat d1 d2 ... dN && echo w) | ed -
  785. old' edits `old' to make it a copy of `newN'.
  786. * Menu:
  787. * Detailed ed::        A detailed description of `ed' format.
  788. * Example ed::        A sample `ed' script.
  789. File: diff.info,  Node: Detailed ed,  Next: Example ed,  Up: ed Scripts
  790. Detailed Description of `ed' Format
  791. ...................................
  792.    The `ed' output format consists of one or more hunks of differences.
  793. The changes closest to the ends of the files come first so that
  794. commands that change the number of lines do not affect how `ed'
  795. interprets line numbers in succeeding commands.  `ed' format hunks look
  796. like this:
  797.      CHANGE-COMMAND
  798.      TO-FILE-LINE
  799.      TO-FILE-LINE...
  800.      .
  801.    Because `ed' uses a single period on a line to indicate the end of
  802. input, GNU `diff' protects lines of changes that contain a single
  803. period on a line by writing two periods instead, then writing a
  804. subsequent `ed' command to change the two periods into one.  The `ed'
  805. format cannot represent an incomplete line, so if the second file ends
  806. in a changed incomplete line, `diff' reports an error and then pretends
  807. that a newline was appended.
  808.    There are three types of change commands.  Each consists of a line
  809. number or comma-separated range of lines in the first file and a single
  810. character indicating the kind of change to make.  All line numbers are
  811. the original line numbers in the file.  The types of change commands
  812.      Add text from the second file after line L in the first file.  For
  813.      example, `8a' means to add the following lines after line 8 of file
  814.      1.
  815.      Replace the lines in range R in the first file with the following
  816.      lines.  Like a combined add and delete, but more compact.  For
  817.      example, `5,7c' means change lines 5-7 of file 1 to read as the
  818.      text file 2.
  819.      Delete the lines in range R from the first file.  For example,
  820.      `5,7d' means delete lines 5-7 of file 1.
  821. File: diff.info,  Node: Example ed,  Prev: Detailed ed,  Up: ed Scripts
  822. Example `ed' Script
  823. ...................
  824.    Here is the output of `diff -e lao tzu' (*note Sample diff Input::.,
  825. for the complete contents of the two files):
  826.      11a
  827.      They both may be called deep and profound.
  828.      Deeper and more profound,
  829.      The door of all subtleties!
  830.      .
  831.      4c
  832.      The named is the mother of all things.
  833.      
  834.      .
  835.      1,2d
  836. File: diff.info,  Node: Forward ed,  Next: RCS,  Prev: ed Scripts,  Up: Scripts
  837. Forward `ed' Scripts
  838. --------------------
  839.    `diff' can produce output that is like an `ed' script, but with
  840. hunks in forward (front to back) order.  The format of the commands is
  841. also changed slightly: command characters precede the lines they
  842. modify, spaces separate line numbers in ranges, and no attempt is made
  843. to disambiguate hunk lines consisting of a single period.  Like `ed'
  844. format, forward `ed' format cannot represent incomplete lines.
  845.    Forward `ed' format is not very useful, because neither `ed' nor
  846. `patch' can apply diffs in this format.  It exists mainly for
  847. compatibility with older versions of `diff'.  Use the `-f' or
  848. `--forward-ed' option to select it.
  849. File: diff.info,  Node: RCS,  Prev: Forward ed,  Up: Scripts
  850. RCS Scripts
  851. -----------
  852.    The RCS output format is designed specifically for use by the
  853. Revision Control System, which is a set of free programs used for
  854. organizing different versions and systems of files.  Use the `-n' or
  855. `--rcs' option to select this output format.  It is like the forward
  856. `ed' format (*note Forward ed::.), but it can represent arbitrary
  857. changes to the contents of a file because it avoids the forward `ed'
  858. format's problems with lines consisting of a single period and with
  859. incomplete lines.  Instead of ending text sections with a line
  860. consisting of a single period, each command specifies the number of
  861. lines it affects; a combination of the `a' and `d' commands are used
  862. instead of `c'.  Also, if the second file ends in a changed incomplete
  863. line, then the output also ends in an incomplete line.
  864.    Here is the output of `diff -n lao tzu' (*note Sample diff Input::.,
  865. for the complete contents of the two files):
  866.      d1 2
  867.      d4 1
  868.      a4 2
  869.      The named is the mother of all things.
  870.      
  871.      a11 3
  872.      They both may be called deep and profound.
  873.      Deeper and more profound,
  874.      The door of all subtleties!
  875. File: diff.info,  Node: If-then-else,  Prev: Scripts,  Up: Output Formats
  876. Merging Files with If-then-else
  877. ===============================
  878.    You can use `diff' to merge two files of C source code.  The output
  879. of `diff' in this format contains all the lines of both files.  Lines
  880. common to both files are output just once; the differing parts are
  881. separated by the C preprocessor directives `#ifdef NAME' or `#ifndef
  882. NAME', `#else', and `#endif'.  When compiling the output, you select
  883. which version to use by either defining or leaving undefined the macro
  884. NAME.
  885.    To merge two files, use `diff' with the `-D NAME' or `--ifdef=NAME'
  886. option.  The argument NAME is the C preprocessor identifier to use in
  887. the `#ifdef' and `#ifndef' directives.
  888.    For example, if you change an instance of `wait (&s)' to `waitpid
  889. (-1, &s, 0)' and then merge the old and new files with the
  890. `--ifdef=HAVE_WAITPID' option, then the affected part of your code
  891. might look like this:
  892.          do {
  893.      #ifndef HAVE_WAITPID
  894.              if ((w = wait (&s)) < 0  &&  errno != EINTR)
  895.      #else /* HAVE_WAITPID */
  896.              if ((w = waitpid (-1, &s, 0)) < 0  &&  errno != EINTR)
  897.      #endif /* HAVE_WAITPID */
  898.                  return w;
  899.          } while (w != child);
  900.    You can specify formats for languages other than C by using line
  901. group formats and line formats, as described in the next sections.
  902. * Menu:
  903. * Line Group Formats::        Formats for general if-then-else line groups.
  904. * Line Formats::        Formats for each line in a line group.
  905. * Detailed If-then-else::    A detailed description of if-then-else format.
  906. * Example If-then-else::    Sample if-then-else format output.
  907.