xref: /netbsd-src/external/gpl2/diffutils/dist/doc/diff.info (revision 75f6d617e282811cb173c2ccfbf5df0dd71f7045)
1*75f6d617SchristosThis is diff.info, produced by makeinfo version 4.2 from diff.texi.
2*75f6d617Schristos
3*75f6d617SchristosThis manual is for GNU Diffutils (version 2.8.1, 5 April 2002), and
4*75f6d617Schristosdocuments the GNU `diff', `diff3', `sdiff', and `cmp' commands for
5*75f6d617Schristosshowing the differences between files and the GNU `patch' command for
6*75f6d617Schristosusing their output to update files.
7*75f6d617Schristos
8*75f6d617Schristos   Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free Software
9*75f6d617SchristosFoundation, Inc.
10*75f6d617Schristos
11*75f6d617Schristos     Permission is granted to copy, distribute and/or modify this
12*75f6d617Schristos     document under the terms of the GNU Free Documentation License,
13*75f6d617Schristos     Version 1.1 or any later version published by the Free Software
14*75f6d617Schristos     Foundation; with no Invariant Sections, with the Front-Cover texts
15*75f6d617Schristos     being "A GNU Manual," and with the Back-Cover Texts as in (a)
16*75f6d617Schristos     below.  A copy of the license is included in the section entitled
17*75f6d617Schristos     "GNU Free Documentation License."
18*75f6d617Schristos
19*75f6d617Schristos     (a) The FSF's Back-Cover Text is: "You have freedom to copy and
20*75f6d617Schristos     modify this GNU Manual, like GNU software.  Copies published by
21*75f6d617Schristos     the Free Software Foundation raise funds for GNU development."
22*75f6d617Schristos
23*75f6d617SchristosINFO-DIR-SECTION Individual utilities
24*75f6d617SchristosSTART-INFO-DIR-ENTRY
25*75f6d617Schristos* cmp: (diff)Invoking cmp.                      Compare 2 files byte by byte.
26*75f6d617Schristos* diff: (diff)Invoking diff.                    Compare 2 files line by line.
27*75f6d617Schristos* diff3: (diff)Invoking diff3.                  Compare 3 files line by line.
28*75f6d617Schristos* patch: (diff)Invoking patch.                  Apply a patch to a file.
29*75f6d617Schristos* sdiff: (diff)Invoking sdiff.                  Merge 2 files side-by-side.
30*75f6d617SchristosEND-INFO-DIR-ENTRY
31*75f6d617Schristos
32*75f6d617SchristosINFO-DIR-SECTION GNU packages
33*75f6d617SchristosSTART-INFO-DIR-ENTRY
34*75f6d617Schristos* Diff: (diff).                 Comparing and merging files.
35*75f6d617SchristosEND-INFO-DIR-ENTRY
36*75f6d617Schristos
37*75f6d617Schristos
38*75f6d617SchristosFile: diff.info,  Node: Top,  Next: Overview,  Up: (dir)
39*75f6d617Schristos
40*75f6d617SchristosComparing and Merging Files
41*75f6d617Schristos***************************
42*75f6d617Schristos
43*75f6d617SchristosThis manual is for GNU Diffutils (version 2.8.1, 5 April 2002), and
44*75f6d617Schristosdocuments the GNU `diff', `diff3', `sdiff', and `cmp' commands for
45*75f6d617Schristosshowing the differences between files and the GNU `patch' command for
46*75f6d617Schristosusing their output to update files.
47*75f6d617Schristos
48*75f6d617Schristos   Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free Software
49*75f6d617SchristosFoundation, Inc.
50*75f6d617Schristos
51*75f6d617Schristos     Permission is granted to copy, distribute and/or modify this
52*75f6d617Schristos     document under the terms of the GNU Free Documentation License,
53*75f6d617Schristos     Version 1.1 or any later version published by the Free Software
54*75f6d617Schristos     Foundation; with no Invariant Sections, with the Front-Cover texts
55*75f6d617Schristos     being "A GNU Manual," and with the Back-Cover Texts as in (a)
56*75f6d617Schristos     below.  A copy of the license is included in the section entitled
57*75f6d617Schristos     "GNU Free Documentation License."
58*75f6d617Schristos
59*75f6d617Schristos     (a) The FSF's Back-Cover Text is: "You have freedom to copy and
60*75f6d617Schristos     modify this GNU Manual, like GNU software.  Copies published by
61*75f6d617Schristos     the Free Software Foundation raise funds for GNU development."
62*75f6d617Schristos
63*75f6d617Schristos* Menu:
64*75f6d617Schristos
65*75f6d617Schristos* Overview::              Preliminary information.
66*75f6d617Schristos* Comparison::            What file comparison means.
67*75f6d617Schristos
68*75f6d617Schristos* Output Formats::        Formats for two-way difference reports.
69*75f6d617Schristos* Incomplete Lines::      Lines that lack trailing newlines.
70*75f6d617Schristos* Comparing Directories:: Comparing files and directories.
71*75f6d617Schristos* Adjusting Output::      Making `diff' output prettier.
72*75f6d617Schristos* diff Performance::      Making `diff' smarter or faster.
73*75f6d617Schristos
74*75f6d617Schristos* Comparing Three Files:: Formats for three-way difference reports.
75*75f6d617Schristos* diff3 Merging::         Merging from a common ancestor.
76*75f6d617Schristos
77*75f6d617Schristos* Interactive Merging::   Interactive merging with `sdiff'.
78*75f6d617Schristos
79*75f6d617Schristos* Merging with patch::    Using `patch' to change old files into new ones.
80*75f6d617Schristos* Making Patches::        Tips for making and using patch distributions.
81*75f6d617Schristos
82*75f6d617Schristos* Invoking cmp::          Compare two files byte by byte.
83*75f6d617Schristos* Invoking diff::         Compare two files line by line.
84*75f6d617Schristos* Invoking diff3::        Compare three files line by line.
85*75f6d617Schristos* Invoking patch::        Apply a diff file to an original.
86*75f6d617Schristos* Invoking sdiff::        Side-by-side merge of file differences.
87*75f6d617Schristos
88*75f6d617Schristos* Standards conformance:: Conformance to the POSIX standard.
89*75f6d617Schristos* Projects::              If you've found a bug or other shortcoming.
90*75f6d617Schristos
91*75f6d617Schristos* Copying This Manual::   How to make copies of this manual.
92*75f6d617Schristos* Index::                 Index.
93*75f6d617Schristos
94*75f6d617Schristos
95*75f6d617SchristosFile: diff.info,  Node: Overview,  Next: Comparison,  Prev: Top,  Up: Top
96*75f6d617Schristos
97*75f6d617SchristosOverview
98*75f6d617Schristos********
99*75f6d617Schristos
100*75f6d617Schristos   Computer users often find occasion to ask how two files differ.
101*75f6d617SchristosPerhaps one file is a newer version of the other file.  Or maybe the
102*75f6d617Schristostwo files started out as identical copies but were changed by different
103*75f6d617Schristospeople.
104*75f6d617Schristos
105*75f6d617Schristos   You can use the `diff' command to show differences between two
106*75f6d617Schristosfiles, or each corresponding file in two directories.  `diff' outputs
107*75f6d617Schristosdifferences between files line by line in any of several formats,
108*75f6d617Schristosselectable by command line options.  This set of differences is often
109*75f6d617Schristoscalled a "diff" or "patch".  For files that are identical, `diff'
110*75f6d617Schristosnormally produces no output; for binary (non-text) files, `diff'
111*75f6d617Schristosnormally reports only that they are different.
112*75f6d617Schristos
113*75f6d617Schristos   You can use the `cmp' command to show the byte and line numbers
114*75f6d617Schristoswhere two files differ.  `cmp' can also show all the bytes that differ
115*75f6d617Schristosbetween the two files, side by side.  A way to compare two files
116*75f6d617Schristoscharacter by character is the Emacs command `M-x compare-windows'.
117*75f6d617Schristos*Note Other Window: (emacs)Other Window, for more information on that
118*75f6d617Schristoscommand.
119*75f6d617Schristos
120*75f6d617Schristos   You can use the `diff3' command to show differences among three
121*75f6d617Schristosfiles.  When two people have made independent changes to a common
122*75f6d617Schristosoriginal, `diff3' can report the differences between the original and
123*75f6d617Schristosthe two changed versions, and can produce a merged file that contains
124*75f6d617Schristosboth persons' changes together with warnings about conflicts.
125*75f6d617Schristos
126*75f6d617Schristos   You can use the `sdiff' command to merge two files interactively.
127*75f6d617Schristos
128*75f6d617Schristos   You can use the set of differences produced by `diff' to distribute
129*75f6d617Schristosupdates to text files (such as program source code) to other people.
130*75f6d617SchristosThis method is especially useful when the differences are small compared
131*75f6d617Schristosto the complete files.  Given `diff' output, you can use the `patch'
132*75f6d617Schristosprogram to update, or "patch", a copy of the file.  If you think of
133*75f6d617Schristos`diff' as subtracting one file from another to produce their
134*75f6d617Schristosdifference, you can think of `patch' as adding the difference to one
135*75f6d617Schristosfile to reproduce the other.
136*75f6d617Schristos
137*75f6d617Schristos   This manual first concentrates on making diffs, and later shows how
138*75f6d617Schristosto use diffs to update files.
139*75f6d617Schristos
140*75f6d617Schristos   GNU `diff' was written by Paul Eggert, Mike Haertel, David Hayes,
141*75f6d617SchristosRichard Stallman, and Len Tower.  Wayne Davison designed and
142*75f6d617Schristosimplemented the unified output format.  The basic algorithm is described
143*75f6d617Schristosin "An O(ND) Difference Algorithm and its Variations", Eugene W. Myers,
144*75f6d617Schristos`Algorithmica' Vol. 1 No. 2, 1986, pp. 251-266; and in "A File
145*75f6d617SchristosComparison Program", Webb Miller and Eugene W. Myers,
146*75f6d617Schristos`Software--Practice and Experience' Vol. 15 No. 11, 1985, pp. 1025-1040.
147*75f6d617SchristosThe algorithm was independently discovered as described in "Algorithms
148*75f6d617Schristosfor Approximate String Matching", E. Ukkonen, `Information and Control'
149*75f6d617SchristosVol. 64, 1985, pp. 100-118.
150*75f6d617Schristos
151*75f6d617Schristos   GNU `diff3' was written by Randy Smith.  GNU `sdiff' was written by
152*75f6d617SchristosThomas Lord.  GNU `cmp' was written by Torbjorn Granlund and David
153*75f6d617SchristosMacKenzie.
154*75f6d617Schristos
155*75f6d617Schristos   `patch' was written mainly by Larry Wall and Paul Eggert; several
156*75f6d617SchristosGNU enhancements were contributed by Wayne Davison and David MacKenzie.
157*75f6d617SchristosParts of this manual are adapted from a manual page written by Larry
158*75f6d617SchristosWall, with his permission.
159*75f6d617Schristos
160*75f6d617Schristos
161*75f6d617SchristosFile: diff.info,  Node: Comparison,  Next: Output Formats,  Prev: Overview,  Up: Top
162*75f6d617Schristos
163*75f6d617SchristosWhat Comparison Means
164*75f6d617Schristos*********************
165*75f6d617Schristos
166*75f6d617Schristos   There are several ways to think about the differences between two
167*75f6d617Schristosfiles.  One way to think of the differences is as a series of lines
168*75f6d617Schristosthat were deleted from, inserted in, or changed in one file to produce
169*75f6d617Schristosthe other file.  `diff' compares two files line by line, finds groups of
170*75f6d617Schristoslines that differ, and reports each group of differing lines.  It can
171*75f6d617Schristosreport the differing lines in several formats, which have different
172*75f6d617Schristospurposes.
173*75f6d617Schristos
174*75f6d617Schristos   GNU `diff' can show whether files are different without detailing
175*75f6d617Schristosthe differences.  It also provides ways to suppress certain kinds of
176*75f6d617Schristosdifferences that are not important to you.  Most commonly, such
177*75f6d617Schristosdifferences are changes in the amount of white space between words or
178*75f6d617Schristoslines.  `diff' also provides ways to suppress differences in alphabetic
179*75f6d617Schristoscase or in lines that match a regular expression that you provide.
180*75f6d617SchristosThese options can accumulate; for example, you can ignore changes in
181*75f6d617Schristosboth white space and alphabetic case.
182*75f6d617Schristos
183*75f6d617Schristos   Another way to think of the differences between two files is as a
184*75f6d617Schristossequence of pairs of bytes that can be either identical or different.
185*75f6d617Schristos`cmp' reports the differences between two files byte by byte, instead
186*75f6d617Schristosof line by line.  As a result, it is often more useful than `diff' for
187*75f6d617Schristoscomparing binary files.  For text files, `cmp' is useful mainly when
188*75f6d617Schristosyou want to know only whether two files are identical, or whether one
189*75f6d617Schristosfile is a prefix of the other.
190*75f6d617Schristos
191*75f6d617Schristos   To illustrate the effect that considering changes byte by byte can
192*75f6d617Schristoshave compared with considering them line by line, think of what happens
193*75f6d617Schristosif a single newline character is added to the beginning of a file.  If
194*75f6d617Schristosthat file is then compared with an otherwise identical file that lacks
195*75f6d617Schristosthe newline at the beginning, `diff' will report that a blank line has
196*75f6d617Schristosbeen added to the file, while `cmp' will report that almost every byte
197*75f6d617Schristosof the two files differs.
198*75f6d617Schristos
199*75f6d617Schristos   `diff3' normally compares three input files line by line, finds
200*75f6d617Schristosgroups of lines that differ, and reports each group of differing lines.
201*75f6d617SchristosIts output is designed to make it easy to inspect two different sets of
202*75f6d617Schristoschanges to the same file.
203*75f6d617Schristos
204*75f6d617Schristos* Menu:
205*75f6d617Schristos
206*75f6d617Schristos* Hunks::             Groups of differing lines.
207*75f6d617Schristos* White Space::       Suppressing differences in white space.
208*75f6d617Schristos* Blank Lines::       Suppressing differences in blank lines.
209*75f6d617Schristos* Case Folding::      Suppressing differences in alphabetic case.
210*75f6d617Schristos* Specified Folding:: Suppressing differences that match regular expressions.
211*75f6d617Schristos* Brief::             Summarizing which files are different.
212*75f6d617Schristos* Binary::            Comparing binary files or forcing text comparisons.
213*75f6d617Schristos
214*75f6d617Schristos
215*75f6d617SchristosFile: diff.info,  Node: Hunks,  Next: White Space,  Up: Comparison
216*75f6d617Schristos
217*75f6d617SchristosHunks
218*75f6d617Schristos=====
219*75f6d617Schristos
220*75f6d617Schristos   When comparing two files, `diff' finds sequences of lines common to
221*75f6d617Schristosboth files, interspersed with groups of differing lines called "hunks".
222*75f6d617SchristosComparing two identical files yields one sequence of common lines and
223*75f6d617Schristosno hunks, because no lines differ.  Comparing two entirely different
224*75f6d617Schristosfiles yields no common lines and one large hunk that contains all lines
225*75f6d617Schristosof both files.  In general, there are many ways to match up lines
226*75f6d617Schristosbetween two given files.  `diff' tries to minimize the total hunk size
227*75f6d617Schristosby finding large sequences of common lines interspersed with small
228*75f6d617Schristoshunks of differing lines.
229*75f6d617Schristos
230*75f6d617Schristos   For example, suppose the file `F' contains the three lines `a', `b',
231*75f6d617Schristos`c', and the file `G' contains the same three lines in reverse order
232*75f6d617Schristos`c', `b', `a'.  If `diff' finds the line `c' as common, then the command
233*75f6d617Schristos`diff F G' produces this output:
234*75f6d617Schristos
235*75f6d617Schristos     1,2d0
236*75f6d617Schristos     < a
237*75f6d617Schristos     < b
238*75f6d617Schristos     3a2,3
239*75f6d617Schristos     > b
240*75f6d617Schristos     > a
241*75f6d617Schristos
242*75f6d617SchristosBut if `diff' notices the common line `b' instead, it produces this
243*75f6d617Schristosoutput:
244*75f6d617Schristos
245*75f6d617Schristos     1c1
246*75f6d617Schristos     < a
247*75f6d617Schristos     ---
248*75f6d617Schristos     > c
249*75f6d617Schristos     3c3
250*75f6d617Schristos     < c
251*75f6d617Schristos     ---
252*75f6d617Schristos     > a
253*75f6d617Schristos
254*75f6d617SchristosIt is also possible to find `a' as the common line.  `diff' does not
255*75f6d617Schristosalways find an optimal matching between the files; it takes shortcuts
256*75f6d617Schristosto run faster.  But its output is usually close to the shortest
257*75f6d617Schristospossible.  You can adjust this tradeoff with the `--minimal' option
258*75f6d617Schristos(*note diff Performance::).
259*75f6d617Schristos
260*75f6d617Schristos
261*75f6d617SchristosFile: diff.info,  Node: White Space,  Next: Blank Lines,  Prev: Hunks,  Up: Comparison
262*75f6d617Schristos
263*75f6d617SchristosSuppressing Differences in Blank and Tab Spacing
264*75f6d617Schristos================================================
265*75f6d617Schristos
266*75f6d617Schristos   The `-E' and `--ignore-tab-expansion' options ignore the distinction
267*75f6d617Schristosbetween tabs and spaces on input.  A tab is considered to be equivalent
268*75f6d617Schristosto the number of spaces to the next tab stop.  `diff' assumes that tab
269*75f6d617Schristosstops are set every 8 print columns.
270*75f6d617Schristos
271*75f6d617Schristos   The `-b' and `--ignore-space-change' options are stronger.  They
272*75f6d617Schristosignore white space at line end, and consider all other sequences of one
273*75f6d617Schristosor more white space characters to be equivalent.  With these options,
274*75f6d617Schristos`diff' considers the following two lines to be equivalent, where `$'
275*75f6d617Schristosdenotes the line end:
276*75f6d617Schristos
277*75f6d617Schristos     Here lyeth  muche rychnesse  in lytell space.   -- John Heywood$
278*75f6d617Schristos     Here lyeth muche rychnesse in lytell space. -- John Heywood   $
279*75f6d617Schristos
280*75f6d617Schristos   The `-w' and `--ignore-all-space' options are stronger still.  They
281*75f6d617Schristosignore difference even if one line has white space where the other line
282*75f6d617Schristoshas none.  "White space" characters include tab, newline, vertical tab,
283*75f6d617Schristosform feed, carriage return, and space; some locales may define
284*75f6d617Schristosadditional characters to be white space.  With these options, `diff'
285*75f6d617Schristosconsiders the following two lines to be equivalent, where `$' denotes
286*75f6d617Schristosthe line end and `^M' denotes a carriage return:
287*75f6d617Schristos
288*75f6d617Schristos     Here lyeth  muche  rychnesse in lytell space.--  John Heywood$
289*75f6d617Schristos       He relyeth much erychnes  seinly tells pace.  --John Heywood   ^M$
290*75f6d617Schristos
291*75f6d617Schristos
292*75f6d617SchristosFile: diff.info,  Node: Blank Lines,  Next: Case Folding,  Prev: White Space,  Up: Comparison
293*75f6d617Schristos
294*75f6d617SchristosSuppressing Differences in Blank Lines
295*75f6d617Schristos======================================
296*75f6d617Schristos
297*75f6d617Schristos   The `-B' and `--ignore-blank-lines' options ignore insertions or
298*75f6d617Schristosdeletions of blank lines.  These options affect only lines that are
299*75f6d617Schristoscompletely empty; they do not affect lines that look empty but contain
300*75f6d617Schristosspace or tab characters.  With these options, for example, a file
301*75f6d617Schristoscontaining
302*75f6d617Schristos     1.  A point is that which has no part.
303*75f6d617Schristos
304*75f6d617Schristos     2.  A line is breadthless length.
305*75f6d617Schristos     -- Euclid, The Elements, I
306*75f6d617Schristos
307*75f6d617Schristosis considered identical to a file containing
308*75f6d617Schristos     1.  A point is that which has no part.
309*75f6d617Schristos     2.  A line is breadthless length.
310*75f6d617Schristos
311*75f6d617Schristos
312*75f6d617Schristos     -- Euclid, The Elements, I
313*75f6d617Schristos
314*75f6d617Schristos
315*75f6d617SchristosFile: diff.info,  Node: Case Folding,  Next: Specified Folding,  Prev: Blank Lines,  Up: Comparison
316*75f6d617Schristos
317*75f6d617SchristosSuppressing Case Differences
318*75f6d617Schristos============================
319*75f6d617Schristos
320*75f6d617Schristos   GNU `diff' can treat lower case letters as equivalent to their upper
321*75f6d617Schristoscase counterparts, so that, for example, it considers `Funky Stuff',
322*75f6d617Schristos`funky STUFF', and `fUNKy stuFf' to all be the same.  To request this,
323*75f6d617Schristosuse the `-i' or `--ignore-case' option.
324*75f6d617Schristos
325*75f6d617Schristos
326*75f6d617SchristosFile: diff.info,  Node: Specified Folding,  Next: Brief,  Prev: Case Folding,  Up: Comparison
327*75f6d617Schristos
328*75f6d617SchristosSuppressing Lines Matching a Regular Expression
329*75f6d617Schristos===============================================
330*75f6d617Schristos
331*75f6d617Schristos   To ignore insertions and deletions of lines that match a
332*75f6d617Schristos`grep'-style regular expression, use the `-I REGEXP' or
333*75f6d617Schristos`--ignore-matching-lines=REGEXP' option.  You should escape regular
334*75f6d617Schristosexpressions that contain shell metacharacters to prevent the shell from
335*75f6d617Schristosexpanding them.  For example, `diff -I '^[[:digit:]]'' ignores all
336*75f6d617Schristoschanges to lines beginning with a digit.
337*75f6d617Schristos
338*75f6d617Schristos   However, `-I' only ignores the insertion or deletion of lines that
339*75f6d617Schristoscontain the regular expression if every changed line in the hunk--every
340*75f6d617Schristosinsertion and every deletion--matches the regular expression.  In other
341*75f6d617Schristoswords, for each nonignorable change, `diff' prints the complete set of
342*75f6d617Schristoschanges in its vicinity, including the ignorable ones.
343*75f6d617Schristos
344*75f6d617Schristos   You can specify more than one regular expression for lines to ignore
345*75f6d617Schristosby using more than one `-I' option.  `diff' tries to match each line
346*75f6d617Schristosagainst each regular expression.
347*75f6d617Schristos
348*75f6d617Schristos
349*75f6d617SchristosFile: diff.info,  Node: Brief,  Next: Binary,  Prev: Specified Folding,  Up: Comparison
350*75f6d617Schristos
351*75f6d617SchristosSummarizing Which Files Differ
352*75f6d617Schristos==============================
353*75f6d617Schristos
354*75f6d617Schristos   When you only want to find out whether files are different, and you
355*75f6d617Schristosdon't care what the differences are, you can use the summary output
356*75f6d617Schristosformat.  In this format, instead of showing the differences between the
357*75f6d617Schristosfiles, `diff' simply reports whether files differ.  The `-q' and
358*75f6d617Schristos`--brief' options select this output format.
359*75f6d617Schristos
360*75f6d617Schristos   This format is especially useful when comparing the contents of two
361*75f6d617Schristosdirectories.  It is also much faster than doing the normal line by line
362*75f6d617Schristoscomparisons, because `diff' can stop analyzing the files as soon as it
363*75f6d617Schristosknows that there are any differences.
364*75f6d617Schristos
365*75f6d617Schristos   You can also get a brief indication of whether two files differ by
366*75f6d617Schristosusing `cmp'.  For files that are identical, `cmp' produces no output.
367*75f6d617SchristosWhen the files differ, by default, `cmp' outputs the byte and line
368*75f6d617Schristosnumber where the first difference occurs.  You can use the `-s' option
369*75f6d617Schristosto suppress that information, so that `cmp' produces no output and
370*75f6d617Schristosreports whether the files differ using only its exit status (*note
371*75f6d617SchristosInvoking cmp::).
372*75f6d617Schristos
373*75f6d617Schristos   Unlike `diff', `cmp' cannot compare directories; it can only compare
374*75f6d617Schristostwo files.
375*75f6d617Schristos
376*75f6d617Schristos
377*75f6d617SchristosFile: diff.info,  Node: Binary,  Prev: Brief,  Up: Comparison
378*75f6d617Schristos
379*75f6d617SchristosBinary Files and Forcing Text Comparisons
380*75f6d617Schristos=========================================
381*75f6d617Schristos
382*75f6d617Schristos   If `diff' thinks that either of the two files it is comparing is
383*75f6d617Schristosbinary (a non-text file), it normally treats that pair of files much as
384*75f6d617Schristosif the summary output format had been selected (*note Brief::), and
385*75f6d617Schristosreports only that the binary files are different.  This is because line
386*75f6d617Schristosby line comparisons are usually not meaningful for binary files.
387*75f6d617Schristos
388*75f6d617Schristos   `diff' determines whether a file is text or binary by checking the
389*75f6d617Schristosfirst few bytes in the file; the exact number of bytes is system
390*75f6d617Schristosdependent, but it is typically several thousand.  If every byte in that
391*75f6d617Schristospart of the file is non-null, `diff' considers the file to be text;
392*75f6d617Schristosotherwise it considers the file to be binary.
393*75f6d617Schristos
394*75f6d617Schristos   Sometimes you might want to force `diff' to consider files to be
395*75f6d617Schristostext.  For example, you might be comparing text files that contain null
396*75f6d617Schristoscharacters; `diff' would erroneously decide that those are non-text
397*75f6d617Schristosfiles.  Or you might be comparing documents that are in a format used
398*75f6d617Schristosby a word processing system that uses null characters to indicate
399*75f6d617Schristosspecial formatting.  You can force `diff' to consider all files to be
400*75f6d617Schristostext files, and compare them line by line, by using the `-a' or
401*75f6d617Schristos`--text' option.  If the files you compare using this option do not in
402*75f6d617Schristosfact contain text, they will probably contain few newline characters,
403*75f6d617Schristosand the `diff' output will consist of hunks showing differences between
404*75f6d617Schristoslong lines of whatever characters the files contain.
405*75f6d617Schristos
406*75f6d617Schristos   You can also force `diff' to consider all files to be binary files,
407*75f6d617Schristosand report only whether they differ (but not how).  Use the `-q' or
408*75f6d617Schristos`--brief' option for this.
409*75f6d617Schristos
410*75f6d617Schristos   Differing binary files are considered to cause trouble because the
411*75f6d617Schristosresulting `diff' output does not capture all the differences.  This
412*75f6d617Schristostrouble causes `diff' to exit with status 2.  However, this trouble
413*75f6d617Schristoscannot occur with the `--a' or `--text' option, or with the `-q' or
414*75f6d617Schristos`--brief' option, as these options both cause `diff' to treat binary
415*75f6d617Schristosfiles like text files.
416*75f6d617Schristos
417*75f6d617Schristos   In operating systems that distinguish between text and binary files,
418*75f6d617Schristos`diff' normally reads and writes all data as text.  Use the `--binary'
419*75f6d617Schristosoption to force `diff' to read and write binary data instead.  This
420*75f6d617Schristosoption has no effect on a POSIX-compliant system like GNU or
421*75f6d617Schristostraditional Unix.  However, many personal computer operating systems
422*75f6d617Schristosrepresent the end of a line with a carriage return followed by a
423*75f6d617Schristosnewline.  On such systems, `diff' normally ignores these carriage
424*75f6d617Schristosreturns on input and generates them at the end of each output line, but
425*75f6d617Schristoswith the `--binary' option `diff' treats each carriage return as just
426*75f6d617Schristosanother input character, and does not generate a carriage return at the
427*75f6d617Schristosend of each output line.  This can be useful when dealing with non-text
428*75f6d617Schristosfiles that are meant to be interchanged with POSIX-compliant systems.
429*75f6d617Schristos
430*75f6d617Schristos   The `--strip-trailing-cr' causes `diff' to treat input lines that
431*75f6d617Schristosend in carriage return followed by newline as if they end in plain
432*75f6d617Schristosnewline.  This can be useful when comparing text that is imperfectly
433*75f6d617Schristosimported from many personal computer operating systems.  This option
434*75f6d617Schristosaffects how lines are read, which in turn affects how they are compared
435*75f6d617Schristosand output.
436*75f6d617Schristos
437*75f6d617Schristos   If you want to compare two files byte by byte, you can use the `cmp'
438*75f6d617Schristosprogram with the `-l' option to show the values of each differing byte
439*75f6d617Schristosin the two files.  With GNU `cmp', you can also use the `-b' option to
440*75f6d617Schristosshow the ASCII representation of those bytes.  *Note Invoking cmp::,
441*75f6d617Schristosfor more information.
442*75f6d617Schristos
443*75f6d617Schristos   If `diff3' thinks that any of the files it is comparing is binary (a
444*75f6d617Schristosnon-text file), it normally reports an error, because such comparisons
445*75f6d617Schristosare usually not useful.  `diff3' uses the same test as `diff' to decide
446*75f6d617Schristoswhether a file is binary.  As with `diff', if the input files contain a
447*75f6d617Schristosfew non-text bytes but otherwise are like text files, you can force
448*75f6d617Schristos`diff3' to consider all files to be text files and compare them line by
449*75f6d617Schristosline by using the `-a' or `--text' options.
450*75f6d617Schristos
451*75f6d617Schristos
452*75f6d617SchristosFile: diff.info,  Node: Output Formats,  Next: Incomplete Lines,  Prev: Comparison,  Up: Top
453*75f6d617Schristos
454*75f6d617Schristos`diff' Output Formats
455*75f6d617Schristos*********************
456*75f6d617Schristos
457*75f6d617Schristos   `diff' has several mutually exclusive options for output format.
458*75f6d617SchristosThe following sections describe each format, illustrating how `diff'
459*75f6d617Schristosreports the differences between two sample input files.
460*75f6d617Schristos
461*75f6d617Schristos* Menu:
462*75f6d617Schristos
463*75f6d617Schristos* Sample diff Input:: Sample `diff' input files for examples.
464*75f6d617Schristos* Normal::            Showing differences without surrounding text.
465*75f6d617Schristos* Context::           Showing differences with the surrounding text.
466*75f6d617Schristos* Side by Side::      Showing differences in two columns.
467*75f6d617Schristos* Scripts::           Generating scripts for other programs.
468*75f6d617Schristos* If-then-else::      Merging files with if-then-else.
469*75f6d617Schristos
470*75f6d617Schristos
471*75f6d617SchristosFile: diff.info,  Node: Sample diff Input,  Next: Normal,  Up: Output Formats
472*75f6d617Schristos
473*75f6d617SchristosTwo Sample Input Files
474*75f6d617Schristos======================
475*75f6d617Schristos
476*75f6d617Schristos   Here are two sample files that we will use in numerous examples to
477*75f6d617Schristosillustrate the output of `diff' and how various options can change it.
478*75f6d617Schristos
479*75f6d617Schristos   This is the file `lao':
480*75f6d617Schristos
481*75f6d617Schristos     The Way that can be told of is not the eternal Way;
482*75f6d617Schristos     The name that can be named is not the eternal name.
483*75f6d617Schristos     The Nameless is the origin of Heaven and Earth;
484*75f6d617Schristos     The Named is the mother of all things.
485*75f6d617Schristos     Therefore let there always be non-being,
486*75f6d617Schristos       so we may see their subtlety,
487*75f6d617Schristos     And let there always be being,
488*75f6d617Schristos       so we may see their outcome.
489*75f6d617Schristos     The two are the same,
490*75f6d617Schristos     But after they are produced,
491*75f6d617Schristos       they have different names.
492*75f6d617Schristos
493*75f6d617Schristos   This is the file `tzu':
494*75f6d617Schristos
495*75f6d617Schristos     The Nameless is the origin of Heaven and Earth;
496*75f6d617Schristos     The named is the mother of all things.
497*75f6d617Schristos
498*75f6d617Schristos     Therefore let there always be non-being,
499*75f6d617Schristos       so we may see their subtlety,
500*75f6d617Schristos     And let there always be being,
501*75f6d617Schristos       so we may see their outcome.
502*75f6d617Schristos     The two are the same,
503*75f6d617Schristos     But after they are produced,
504*75f6d617Schristos       they have different names.
505*75f6d617Schristos     They both may be called deep and profound.
506*75f6d617Schristos     Deeper and more profound,
507*75f6d617Schristos     The door of all subtleties!
508*75f6d617Schristos
509*75f6d617Schristos   In this example, the first hunk contains just the first two lines of
510*75f6d617Schristos`lao', the second hunk contains the fourth line of `lao' opposing the
511*75f6d617Schristossecond and third lines of `tzu', and the last hunk contains just the
512*75f6d617Schristoslast three lines of `tzu'.
513*75f6d617Schristos
514*75f6d617Schristos
515*75f6d617SchristosFile: diff.info,  Node: Normal,  Next: Context,  Prev: Sample diff Input,  Up: Output Formats
516*75f6d617Schristos
517*75f6d617SchristosShowing Differences Without Context
518*75f6d617Schristos===================================
519*75f6d617Schristos
520*75f6d617Schristos   The "normal" `diff' output format shows each hunk of differences
521*75f6d617Schristoswithout any surrounding context.  Sometimes such output is the clearest
522*75f6d617Schristosway to see how lines have changed, without the clutter of nearby
523*75f6d617Schristosunchanged lines (although you can get similar results with the context
524*75f6d617Schristosor unified formats by using 0 lines of context).  However, this format
525*75f6d617Schristosis no longer widely used for sending out patches; for that purpose, the
526*75f6d617Schristoscontext format (*note Context Format::) and the unified format (*note
527*75f6d617SchristosUnified Format::) are superior.  Normal format is the default for
528*75f6d617Schristoscompatibility with older versions of `diff' and the POSIX standard.
529*75f6d617SchristosUse the `--normal' option to select this output format explicitly.
530*75f6d617Schristos
531*75f6d617Schristos* Menu:
532*75f6d617Schristos
533*75f6d617Schristos* Detailed Normal:: A detailed description of normal output format.
534*75f6d617Schristos* Example Normal::  Sample output in the normal format.
535*75f6d617Schristos
536*75f6d617Schristos
537*75f6d617SchristosFile: diff.info,  Node: Detailed Normal,  Next: Example Normal,  Up: Normal
538*75f6d617Schristos
539*75f6d617SchristosDetailed Description of Normal Format
540*75f6d617Schristos-------------------------------------
541*75f6d617Schristos
542*75f6d617Schristos   The normal output format consists of one or more hunks of
543*75f6d617Schristosdifferences; each hunk shows one area where the files differ.  Normal
544*75f6d617Schristosformat hunks look like this:
545*75f6d617Schristos
546*75f6d617Schristos     CHANGE-COMMAND
547*75f6d617Schristos     < FROM-FILE-LINE
548*75f6d617Schristos     < FROM-FILE-LINE...
549*75f6d617Schristos     ---
550*75f6d617Schristos     > TO-FILE-LINE
551*75f6d617Schristos     > TO-FILE-LINE...
552*75f6d617Schristos
553*75f6d617Schristos   There are three types of change commands.  Each consists of a line
554*75f6d617Schristosnumber or comma-separated range of lines in the first file, a single
555*75f6d617Schristoscharacter indicating the kind of change to make, and a line number or
556*75f6d617Schristoscomma-separated range of lines in the second file.  All line numbers are
557*75f6d617Schristosthe original line numbers in each file.  The types of change commands
558*75f6d617Schristosare:
559*75f6d617Schristos
560*75f6d617Schristos`LaR'
561*75f6d617Schristos     Add the lines in range R of the second file after line L of the
562*75f6d617Schristos     first file.  For example, `8a12,15' means append lines 12-15 of
563*75f6d617Schristos     file 2 after line 8 of file 1; or, if changing file 2 into file 1,
564*75f6d617Schristos     delete lines 12-15 of file 2.
565*75f6d617Schristos
566*75f6d617Schristos`FcT'
567*75f6d617Schristos     Replace the lines in range F of the first file with lines in range
568*75f6d617Schristos     T of the second file.  This is like a combined add and delete, but
569*75f6d617Schristos     more compact.  For example, `5,7c8,10' means change lines 5-7 of
570*75f6d617Schristos     file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
571*75f6d617Schristos     file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.
572*75f6d617Schristos
573*75f6d617Schristos`RdL'
574*75f6d617Schristos     Delete the lines in range R from the first file; line L is where
575*75f6d617Schristos     they would have appeared in the second file had they not been
576*75f6d617Schristos     deleted.  For example, `5,7d3' means delete lines 5-7 of file 1;
577*75f6d617Schristos     or, if changing file 2 into file 1, append lines 5-7 of file 1
578*75f6d617Schristos     after line 3 of file 2.
579*75f6d617Schristos
580*75f6d617Schristos
581*75f6d617SchristosFile: diff.info,  Node: Example Normal,  Prev: Detailed Normal,  Up: Normal
582*75f6d617Schristos
583*75f6d617SchristosAn Example of Normal Format
584*75f6d617Schristos---------------------------
585*75f6d617Schristos
586*75f6d617Schristos   Here is the output of the command `diff lao tzu' (*note Sample diff
587*75f6d617SchristosInput::, for the complete contents of the two files).  Notice that it
588*75f6d617Schristosshows only the lines that are different between the two files.
589*75f6d617Schristos
590*75f6d617Schristos     1,2d0
591*75f6d617Schristos     < The Way that can be told of is not the eternal Way;
592*75f6d617Schristos     < The name that can be named is not the eternal name.
593*75f6d617Schristos     4c2,3
594*75f6d617Schristos     < The Named is the mother of all things.
595*75f6d617Schristos     ---
596*75f6d617Schristos     > The named is the mother of all things.
597*75f6d617Schristos     >
598*75f6d617Schristos     11a11,13
599*75f6d617Schristos     > They both may be called deep and profound.
600*75f6d617Schristos     > Deeper and more profound,
601*75f6d617Schristos     > The door of all subtleties!
602*75f6d617Schristos
603*75f6d617Schristos
604*75f6d617SchristosFile: diff.info,  Node: Context,  Next: Side by Side,  Prev: Normal,  Up: Output Formats
605*75f6d617Schristos
606*75f6d617SchristosShowing Differences in Their Context
607*75f6d617Schristos====================================
608*75f6d617Schristos
609*75f6d617Schristos   Usually, when you are looking at the differences between files, you
610*75f6d617Schristoswill also want to see the parts of the files near the lines that
611*75f6d617Schristosdiffer, to help you understand exactly what has changed.  These nearby
612*75f6d617Schristosparts of the files are called the "context".
613*75f6d617Schristos
614*75f6d617Schristos   GNU `diff' provides two output formats that show context around the
615*75f6d617Schristosdiffering lines: "context format" and "unified format".  It can
616*75f6d617Schristosoptionally show in which function or section of the file the differing
617*75f6d617Schristoslines are found.
618*75f6d617Schristos
619*75f6d617Schristos   If you are distributing new versions of files to other people in the
620*75f6d617Schristosform of `diff' output, you should use one of the output formats that
621*75f6d617Schristosshow context so that they can apply the diffs even if they have made
622*75f6d617Schristossmall changes of their own to the files.  `patch' can apply the diffs
623*75f6d617Schristosin this case by searching in the files for the lines of context around
624*75f6d617Schristosthe differing lines; if those lines are actually a few lines away from
625*75f6d617Schristoswhere the diff says they are, `patch' can adjust the line numbers
626*75f6d617Schristosaccordingly and still apply the diff correctly.  *Note Imperfect::, for
627*75f6d617Schristosmore information on using `patch' to apply imperfect diffs.
628*75f6d617Schristos
629*75f6d617Schristos* Menu:
630*75f6d617Schristos
631*75f6d617Schristos* Context Format::  An output format that shows surrounding lines.
632*75f6d617Schristos* Unified Format::  A more compact output format that shows context.
633*75f6d617Schristos* Sections::        Showing which sections of the files differences are in.
634*75f6d617Schristos* Alternate Names:: Showing alternate file names in context headers.
635*75f6d617Schristos
636*75f6d617Schristos
637*75f6d617SchristosFile: diff.info,  Node: Context Format,  Next: Unified Format,  Up: Context
638*75f6d617Schristos
639*75f6d617SchristosContext Format
640*75f6d617Schristos--------------
641*75f6d617Schristos
642*75f6d617Schristos   The context output format shows several lines of context around the
643*75f6d617Schristoslines that differ.  It is the standard format for distributing updates
644*75f6d617Schristosto source code.
645*75f6d617Schristos
646*75f6d617Schristos   To select this output format, use the `-C LINES',
647*75f6d617Schristos`--context[=LINES]', or `-c' option.  The argument LINES that some of
648*75f6d617Schristosthese options take is the number of lines of context to show.  If you
649*75f6d617Schristosdo not specify LINES, it defaults to three.  For proper operation,
650*75f6d617Schristos`patch' typically needs at least two lines of context.
651*75f6d617Schristos
652*75f6d617Schristos* Menu:
653*75f6d617Schristos
654*75f6d617Schristos* Detailed Context:: A detailed description of the context output format.
655*75f6d617Schristos* Example Context::  Sample output in context format.
656*75f6d617Schristos* Less Context::     Another sample with less context.
657*75f6d617Schristos
658*75f6d617Schristos
659*75f6d617SchristosFile: diff.info,  Node: Detailed Context,  Next: Example Context,  Up: Context Format
660*75f6d617Schristos
661*75f6d617SchristosDetailed Description of Context Format
662*75f6d617Schristos......................................
663*75f6d617Schristos
664*75f6d617Schristos   The context output format starts with a two-line header, which looks
665*75f6d617Schristoslike this:
666*75f6d617Schristos
667*75f6d617Schristos     *** FROM-FILE FROM-FILE-MODIFICATION-TIME
668*75f6d617Schristos     --- TO-FILE TO-FILE-MODIFICATION TIME
669*75f6d617Schristos
670*75f6d617SchristosThe time stamp normally looks like `2002-02-21 23:30:39.942229878
671*75f6d617Schristos-0800' to indicate the date, time with fractional seconds, and time
672*75f6d617Schristoszone in Internet RFC 2822 format
673*75f6d617Schristos(ftp://ftp.isi.edu/in-notes/rfc2822.txt).  However, a traditional time
674*75f6d617Schristosstamp like `Thu Feb 21 23:30:39 2002' is used if the `LC_TIME' locale
675*75f6d617Schristoscategory is either `C' or `POSIX'.
676*75f6d617Schristos
677*75f6d617Schristos   You can change the header's content with the `--label=LABEL' option;
678*75f6d617Schristossee *Note Alternate Names::.
679*75f6d617Schristos
680*75f6d617Schristos   Next come one or more hunks of differences; each hunk shows one area
681*75f6d617Schristoswhere the files differ.  Context format hunks look like this:
682*75f6d617Schristos
683*75f6d617Schristos     ***************
684*75f6d617Schristos     *** FROM-FILE-LINE-RANGE ****
685*75f6d617Schristos       FROM-FILE-LINE
686*75f6d617Schristos       FROM-FILE-LINE...
687*75f6d617Schristos     --- TO-FILE-LINE-RANGE ----
688*75f6d617Schristos       TO-FILE-LINE
689*75f6d617Schristos       TO-FILE-LINE...
690*75f6d617Schristos
691*75f6d617Schristos   The lines of context around the lines that differ start with two
692*75f6d617Schristosspace characters.  The lines that differ between the two files start
693*75f6d617Schristoswith one of the following indicator characters, followed by a space
694*75f6d617Schristoscharacter:
695*75f6d617Schristos
696*75f6d617Schristos`!'
697*75f6d617Schristos     A line that is part of a group of one or more lines that changed
698*75f6d617Schristos     between the two files.  There is a corresponding group of lines
699*75f6d617Schristos     marked with `!' in the part of this hunk for the other file.
700*75f6d617Schristos
701*75f6d617Schristos`+'
702*75f6d617Schristos     An "inserted" line in the second file that corresponds to nothing
703*75f6d617Schristos     in the first file.
704*75f6d617Schristos
705*75f6d617Schristos`-'
706*75f6d617Schristos     A "deleted" line in the first file that corresponds to nothing in
707*75f6d617Schristos     the second file.
708*75f6d617Schristos
709*75f6d617Schristos   If all of the changes in a hunk are insertions, the lines of
710*75f6d617SchristosFROM-FILE are omitted.  If all of the changes are deletions, the lines
711*75f6d617Schristosof TO-FILE are omitted.
712*75f6d617Schristos
713*75f6d617Schristos
714*75f6d617SchristosFile: diff.info,  Node: Example Context,  Next: Less Context,  Prev: Detailed Context,  Up: Context Format
715*75f6d617Schristos
716*75f6d617SchristosAn Example of Context Format
717*75f6d617Schristos............................
718*75f6d617Schristos
719*75f6d617Schristos   Here is the output of `diff -c lao tzu' (*note Sample diff Input::,
720*75f6d617Schristosfor the complete contents of the two files).  Notice that up to three
721*75f6d617Schristoslines that are not different are shown around each line that is
722*75f6d617Schristosdifferent; they are the context lines.  Also notice that the first two
723*75f6d617Schristoshunks have run together, because their contents overlap.
724*75f6d617Schristos
725*75f6d617Schristos     *** lao	2002-02-21 23:30:39.942229878 -0800
726*75f6d617Schristos     --- tzu	2002-02-21 23:30:50.442260588 -0800
727*75f6d617Schristos     ***************
728*75f6d617Schristos     *** 1,7 ****
729*75f6d617Schristos     - The Way that can be told of is not the eternal Way;
730*75f6d617Schristos     - The name that can be named is not the eternal name.
731*75f6d617Schristos       The Nameless is the origin of Heaven and Earth;
732*75f6d617Schristos     ! The Named is the mother of all things.
733*75f6d617Schristos       Therefore let there always be non-being,
734*75f6d617Schristos         so we may see their subtlety,
735*75f6d617Schristos       And let there always be being,
736*75f6d617Schristos     --- 1,6 ----
737*75f6d617Schristos       The Nameless is the origin of Heaven and Earth;
738*75f6d617Schristos     ! The named is the mother of all things.
739*75f6d617Schristos     !
740*75f6d617Schristos       Therefore let there always be non-being,
741*75f6d617Schristos         so we may see their subtlety,
742*75f6d617Schristos       And let there always be being,
743*75f6d617Schristos     ***************
744*75f6d617Schristos     *** 9,11 ****
745*75f6d617Schristos     --- 8,13 ----
746*75f6d617Schristos       The two are the same,
747*75f6d617Schristos       But after they are produced,
748*75f6d617Schristos         they have different names.
749*75f6d617Schristos     + They both may be called deep and profound.
750*75f6d617Schristos     + Deeper and more profound,
751*75f6d617Schristos     + The door of all subtleties!
752*75f6d617Schristos
753*75f6d617Schristos
754*75f6d617SchristosFile: diff.info,  Node: Less Context,  Prev: Example Context,  Up: Context Format
755*75f6d617Schristos
756*75f6d617SchristosAn Example of Context Format with Less Context
757*75f6d617Schristos..............................................
758*75f6d617Schristos
759*75f6d617Schristos   Here is the output of `diff -C 1 lao tzu' (*note Sample diff
760*75f6d617SchristosInput::, for the complete contents of the two files).  Notice that at
761*75f6d617Schristosmost one context line is reported here.
762*75f6d617Schristos
763*75f6d617Schristos     *** lao	2002-02-21 23:30:39.942229878 -0800
764*75f6d617Schristos     --- tzu	2002-02-21 23:30:50.442260588 -0800
765*75f6d617Schristos     ***************
766*75f6d617Schristos     *** 1,5 ****
767*75f6d617Schristos     - The Way that can be told of is not the eternal Way;
768*75f6d617Schristos     - The name that can be named is not the eternal name.
769*75f6d617Schristos       The Nameless is the origin of Heaven and Earth;
770*75f6d617Schristos     ! The Named is the mother of all things.
771*75f6d617Schristos       Therefore let there always be non-being,
772*75f6d617Schristos     --- 1,4 ----
773*75f6d617Schristos       The Nameless is the origin of Heaven and Earth;
774*75f6d617Schristos     ! The named is the mother of all things.
775*75f6d617Schristos     !
776*75f6d617Schristos       Therefore let there always be non-being,
777*75f6d617Schristos     ***************
778*75f6d617Schristos     *** 11 ****
779*75f6d617Schristos     --- 10,13 ----
780*75f6d617Schristos         they have different names.
781*75f6d617Schristos     + They both may be called deep and profound.
782*75f6d617Schristos     + Deeper and more profound,
783*75f6d617Schristos     + The door of all subtleties!
784*75f6d617Schristos
785*75f6d617Schristos
786*75f6d617SchristosFile: diff.info,  Node: Unified Format,  Next: Sections,  Prev: Context Format,  Up: Context
787*75f6d617Schristos
788*75f6d617SchristosUnified Format
789*75f6d617Schristos--------------
790*75f6d617Schristos
791*75f6d617Schristos   The unified output format is a variation on the context format that
792*75f6d617Schristosis more compact because it omits redundant context lines.  To select
793*75f6d617Schristosthis output format, use the `-U LINES', `--unified[=LINES]', or `-u'
794*75f6d617Schristosoption.  The argument LINES is the number of lines of context to show.
795*75f6d617SchristosWhen it is not given, it defaults to three.
796*75f6d617Schristos
797*75f6d617Schristos   At present, only GNU `diff' can produce this format and only GNU
798*75f6d617Schristos`patch' can automatically apply diffs in this format.  For proper
799*75f6d617Schristosoperation, `patch' typically needs at least three lines of context.
800*75f6d617Schristos
801*75f6d617Schristos* Menu:
802*75f6d617Schristos
803*75f6d617Schristos* Detailed Unified:: A detailed description of unified format.
804*75f6d617Schristos* Example Unified::  Sample output in unified format.
805*75f6d617Schristos
806*75f6d617Schristos
807*75f6d617SchristosFile: diff.info,  Node: Detailed Unified,  Next: Example Unified,  Up: Unified Format
808*75f6d617Schristos
809*75f6d617SchristosDetailed Description of Unified Format
810*75f6d617Schristos......................................
811*75f6d617Schristos
812*75f6d617Schristos   The unified output format starts with a two-line header, which looks
813*75f6d617Schristoslike this:
814*75f6d617Schristos
815*75f6d617Schristos     --- FROM-FILE FROM-FILE-MODIFICATION-TIME
816*75f6d617Schristos     +++ TO-FILE TO-FILE-MODIFICATION-TIME
817*75f6d617Schristos
818*75f6d617SchristosThe time stamp looks like `2002-02-21 23:30:39.942229878 -0800' to
819*75f6d617Schristosindicate the date, time with fractional seconds, and time zone.
820*75f6d617Schristos
821*75f6d617Schristos   You can change the header's content with the `--label=LABEL' option;
822*75f6d617Schristossee *Note Alternate Names::.
823*75f6d617Schristos
824*75f6d617Schristos   Next come one or more hunks of differences; each hunk shows one area
825*75f6d617Schristoswhere the files differ.  Unified format hunks look like this:
826*75f6d617Schristos
827*75f6d617Schristos     @@ FROM-FILE-RANGE TO-FILE-RANGE @@
828*75f6d617Schristos      LINE-FROM-EITHER-FILE
829*75f6d617Schristos      LINE-FROM-EITHER-FILE...
830*75f6d617Schristos
831*75f6d617Schristos   The lines common to both files begin with a space character.  The
832*75f6d617Schristoslines that actually differ between the two files have one of the
833*75f6d617Schristosfollowing indicator characters in the left print column:
834*75f6d617Schristos
835*75f6d617Schristos`+'
836*75f6d617Schristos     A line was added here to the first file.
837*75f6d617Schristos
838*75f6d617Schristos`-'
839*75f6d617Schristos     A line was removed here from the first file.
840*75f6d617Schristos
841*75f6d617Schristos
842*75f6d617SchristosFile: diff.info,  Node: Example Unified,  Prev: Detailed Unified,  Up: Unified Format
843*75f6d617Schristos
844*75f6d617SchristosAn Example of Unified Format
845*75f6d617Schristos............................
846*75f6d617Schristos
847*75f6d617Schristos   Here is the output of the command `diff -u lao tzu' (*note Sample
848*75f6d617Schristosdiff Input::, for the complete contents of the two files):
849*75f6d617Schristos
850*75f6d617Schristos     --- lao	2002-02-21 23:30:39.942229878 -0800
851*75f6d617Schristos     +++ tzu	2002-02-21 23:30:50.442260588 -0800
852*75f6d617Schristos     @@ -1,7 +1,6 @@
853*75f6d617Schristos     -The Way that can be told of is not the eternal Way;
854*75f6d617Schristos     -The name that can be named is not the eternal name.
855*75f6d617Schristos      The Nameless is the origin of Heaven and Earth;
856*75f6d617Schristos     -The Named is the mother of all things.
857*75f6d617Schristos     +The named is the mother of all things.
858*75f6d617Schristos     +
859*75f6d617Schristos      Therefore let there always be non-being,
860*75f6d617Schristos        so we may see their subtlety,
861*75f6d617Schristos      And let there always be being,
862*75f6d617Schristos     @@ -9,3 +8,6 @@
863*75f6d617Schristos      The two are the same,
864*75f6d617Schristos      But after they are produced,
865*75f6d617Schristos        they have different names.
866*75f6d617Schristos     +They both may be called deep and profound.
867*75f6d617Schristos     +Deeper and more profound,
868*75f6d617Schristos     +The door of all subtleties!
869*75f6d617Schristos
870*75f6d617Schristos
871*75f6d617SchristosFile: diff.info,  Node: Sections,  Next: Alternate Names,  Prev: Unified Format,  Up: Context
872*75f6d617Schristos
873*75f6d617SchristosShowing Which Sections Differences Are in
874*75f6d617Schristos-----------------------------------------
875*75f6d617Schristos
876*75f6d617Schristos   Sometimes you might want to know which part of the files each change
877*75f6d617Schristosfalls in.  If the files are source code, this could mean which function
878*75f6d617Schristoswas changed.  If the files are documents, it could mean which chapter or
879*75f6d617Schristosappendix was changed.  GNU `diff' can show this by displaying the
880*75f6d617Schristosnearest section heading line that precedes the differing lines.  Which
881*75f6d617Schristoslines are "section headings" is determined by a regular expression.
882*75f6d617Schristos
883*75f6d617Schristos* Menu:
884*75f6d617Schristos
885*75f6d617Schristos* Specified Headings::  Showing headings that match regular expressions.
886*75f6d617Schristos* C Function Headings:: Showing headings of C functions.
887*75f6d617Schristos
888*75f6d617Schristos
889*75f6d617SchristosFile: diff.info,  Node: Specified Headings,  Next: C Function Headings,  Up: Sections
890*75f6d617Schristos
891*75f6d617SchristosShowing Lines That Match Regular Expressions
892*75f6d617Schristos............................................
893*75f6d617Schristos
894*75f6d617Schristos   To show in which sections differences occur for files that are not
895*75f6d617Schristossource code for C or similar languages, use the `-F REGEXP' or
896*75f6d617Schristos`--show-function-line=REGEXP' option.  `diff' considers lines that
897*75f6d617Schristosmatch the `grep'-style regular expression REGEXP to be the beginning of
898*75f6d617Schristosa section of the file.  Here are suggested regular expressions for some
899*75f6d617Schristoscommon languages:
900*75f6d617Schristos
901*75f6d617Schristos`^[[:alpha:]$_]'
902*75f6d617Schristos     C, C++, Prolog
903*75f6d617Schristos
904*75f6d617Schristos`^('
905*75f6d617Schristos     Lisp
906*75f6d617Schristos
907*75f6d617Schristos`^@node'
908*75f6d617Schristos     Texinfo
909*75f6d617Schristos
910*75f6d617Schristos   This option does not automatically select an output format; in order
911*75f6d617Schristosto use it, you must select the context format (*note Context Format::)
912*75f6d617Schristosor unified format (*note Unified Format::).  In other output formats it
913*75f6d617Schristoshas no effect.
914*75f6d617Schristos
915*75f6d617Schristos   The `-F' and `--show-function-line' options find the nearest
916*75f6d617Schristosunchanged line that precedes each hunk of differences and matches the
917*75f6d617Schristosgiven regular expression.  Then they add that line to the end of the
918*75f6d617Schristosline of asterisks in the context format, or to the `@@' line in unified
919*75f6d617Schristosformat.  If no matching line exists, they leave the output for that
920*75f6d617Schristoshunk unchanged.  If that line is more than 40 characters long, they
921*75f6d617Schristosoutput only the first 40 characters.  You can specify more than one
922*75f6d617Schristosregular expression for such lines; `diff' tries to match each line
923*75f6d617Schristosagainst each regular expression, starting with the last one given.  This
924*75f6d617Schristosmeans that you can use `-p' and `-F' together, if you wish.
925*75f6d617Schristos
926*75f6d617Schristos
927*75f6d617SchristosFile: diff.info,  Node: C Function Headings,  Prev: Specified Headings,  Up: Sections
928*75f6d617Schristos
929*75f6d617SchristosShowing C Function Headings
930*75f6d617Schristos...........................
931*75f6d617Schristos
932*75f6d617Schristos   To show in which functions differences occur for C and similar
933*75f6d617Schristoslanguages, you can use the `-p' or `--show-c-function' option.  This
934*75f6d617Schristosoption automatically defaults to the context output format (*note
935*75f6d617SchristosContext Format::), with the default number of lines of context.  You
936*75f6d617Schristoscan override that number with `-C LINES' elsewhere in the command line.
937*75f6d617SchristosYou can override both the format and the number with `-U LINES'
938*75f6d617Schristoselsewhere in the command line.
939*75f6d617Schristos
940*75f6d617Schristos   The `-p' and `--show-c-function' options are equivalent to `-F
941*75f6d617Schristos'^[[:alpha:]$_]'' if the unified format is specified, otherwise `-c -F
942*75f6d617Schristos'^[[:alpha:]$_]'' (*note Specified Headings::).  GNU `diff' provides
943*75f6d617Schristosthem for the sake of convenience.
944*75f6d617Schristos
945*75f6d617Schristos
946*75f6d617SchristosFile: diff.info,  Node: Alternate Names,  Prev: Sections,  Up: Context
947*75f6d617Schristos
948*75f6d617SchristosShowing Alternate File Names
949*75f6d617Schristos----------------------------
950*75f6d617Schristos
951*75f6d617Schristos   If you are comparing two files that have meaningless or uninformative
952*75f6d617Schristosnames, you might want `diff' to show alternate names in the header of
953*75f6d617Schristosthe context and unified output formats.  To do this, use the
954*75f6d617Schristos`--label=LABEL' option.  The first time you give this option, its
955*75f6d617Schristosargument replaces the name and date of the first file in the header;
956*75f6d617Schristosthe second time, its argument replaces the name and date of the second
957*75f6d617Schristosfile.  If you give this option more than twice, `diff' reports an
958*75f6d617Schristoserror.  The `--label' option does not affect the file names in the `pr'
959*75f6d617Schristosheader when the `-l' or `--paginate' option is used (*note
960*75f6d617SchristosPagination::).
961*75f6d617Schristos
962*75f6d617Schristos   Here are the first two lines of the output from `diff -C 2
963*75f6d617Schristos--label=original --label=modified lao tzu':
964*75f6d617Schristos
965*75f6d617Schristos     *** original
966*75f6d617Schristos     --- modified
967*75f6d617Schristos
968*75f6d617Schristos
969*75f6d617SchristosFile: diff.info,  Node: Side by Side,  Next: Scripts,  Prev: Context,  Up: Output Formats
970*75f6d617Schristos
971*75f6d617SchristosShowing Differences Side by Side
972*75f6d617Schristos================================
973*75f6d617Schristos
974*75f6d617Schristos   `diff' can produce a side by side difference listing of two files.
975*75f6d617SchristosThe files are listed in two columns with a gutter between them.  The
976*75f6d617Schristosgutter contains one of the following markers:
977*75f6d617Schristos
978*75f6d617Schristoswhite space
979*75f6d617Schristos     The corresponding lines are in common.  That is, either the lines
980*75f6d617Schristos     are identical, or the difference is ignored because of one of the
981*75f6d617Schristos     `--ignore' options (*note White Space::).
982*75f6d617Schristos
983*75f6d617Schristos`|'
984*75f6d617Schristos     The corresponding lines differ, and they are either both complete
985*75f6d617Schristos     or both incomplete.
986*75f6d617Schristos
987*75f6d617Schristos`<'
988*75f6d617Schristos     The files differ and only the first file contains the line.
989*75f6d617Schristos
990*75f6d617Schristos`>'
991*75f6d617Schristos     The files differ and only the second file contains the line.
992*75f6d617Schristos
993*75f6d617Schristos`('
994*75f6d617Schristos     Only the first file contains the line, but the difference is
995*75f6d617Schristos     ignored.
996*75f6d617Schristos
997*75f6d617Schristos`)'
998*75f6d617Schristos     Only the second file contains the line, but the difference is
999*75f6d617Schristos     ignored.
1000*75f6d617Schristos
1001*75f6d617Schristos`\'
1002*75f6d617Schristos     The corresponding lines differ, and only the first line is
1003*75f6d617Schristos     incomplete.
1004*75f6d617Schristos
1005*75f6d617Schristos`/'
1006*75f6d617Schristos     The corresponding lines differ, and only the second line is
1007*75f6d617Schristos     incomplete.
1008*75f6d617Schristos
1009*75f6d617Schristos   Normally, an output line is incomplete if and only if the lines that
1010*75f6d617Schristosit contains are incomplete; *Note Incomplete Lines::.  However, when an
1011*75f6d617Schristosoutput line represents two differing lines, one might be incomplete
1012*75f6d617Schristoswhile the other is not.  In this case, the output line is complete, but
1013*75f6d617Schristosits the gutter is marked `\' if the first line is incomplete, `/' if
1014*75f6d617Schristosthe second line is.
1015*75f6d617Schristos
1016*75f6d617Schristos   Side by side format is sometimes easiest to read, but it has
1017*75f6d617Schristoslimitations.  It generates much wider output than usual, and truncates
1018*75f6d617Schristoslines that are too long to fit.  Also, it relies on lining up output
1019*75f6d617Schristosmore heavily than usual, so its output looks particularly bad if you
1020*75f6d617Schristosuse varying width fonts, nonstandard tab stops, or nonprinting
1021*75f6d617Schristoscharacters.
1022*75f6d617Schristos
1023*75f6d617Schristos   You can use the `sdiff' command to interactively merge side by side
1024*75f6d617Schristosdifferences.  *Note Interactive Merging::, for more information on
1025*75f6d617Schristosmerging files.
1026*75f6d617Schristos
1027*75f6d617Schristos* Menu:
1028*75f6d617Schristos
1029*75f6d617Schristos* Side by Side Format::  Controlling side by side output format.
1030*75f6d617Schristos* Example Side by Side:: Sample side by side output.
1031*75f6d617Schristos
1032*75f6d617Schristos
1033*75f6d617SchristosFile: diff.info,  Node: Side by Side Format,  Next: Example Side by Side,  Up: Side by Side
1034*75f6d617Schristos
1035*75f6d617SchristosControlling Side by Side Format
1036*75f6d617Schristos-------------------------------
1037*75f6d617Schristos
1038*75f6d617Schristos   The `-y' or `--side-by-side' option selects side by side format.
1039*75f6d617SchristosBecause side by side output lines contain two input lines, the output
1040*75f6d617Schristosis wider than usual: normally 130 print columns, which can fit onto a
1041*75f6d617Schristostraditional printer line.  You can set the width of the output with the
1042*75f6d617Schristos`-W COLUMNS' or `--width=COLUMNS' option.  The output is split into two
1043*75f6d617Schristoshalves of equal width, separated by a small gutter to mark differences;
1044*75f6d617Schristosthe right half is aligned to a tab stop so that tabs line up.  Input
1045*75f6d617Schristoslines that are too long to fit in half of an output line are truncated
1046*75f6d617Schristosfor output.
1047*75f6d617Schristos
1048*75f6d617Schristos   The `--left-column' option prints only the left column of two common
1049*75f6d617Schristoslines.  The `--suppress-common-lines' option suppresses common lines
1050*75f6d617Schristosentirely.
1051*75f6d617Schristos
1052*75f6d617Schristos
1053*75f6d617SchristosFile: diff.info,  Node: Example Side by Side,  Prev: Side by Side Format,  Up: Side by Side
1054*75f6d617Schristos
1055*75f6d617SchristosAn Example of Side by Side Format
1056*75f6d617Schristos---------------------------------
1057*75f6d617Schristos
1058*75f6d617Schristos   Here is the output of the command `diff -y -W 72 lao tzu' (*note
1059*75f6d617SchristosSample diff Input::, for the complete contents of the two files).
1060*75f6d617Schristos
1061*75f6d617Schristos     The Way that can be told of is n   <
1062*75f6d617Schristos     The name that can be named is no   <
1063*75f6d617Schristos     The Nameless is the origin of He        The Nameless is the origin of He
1064*75f6d617Schristos     The Named is the mother of all t   |    The named is the mother of all t
1065*75f6d617Schristos                                        >
1066*75f6d617Schristos     Therefore let there always be no        Therefore let there always be no
1067*75f6d617Schristos       so we may see their subtlety,           so we may see their subtlety,
1068*75f6d617Schristos     And let there always be being,          And let there always be being,
1069*75f6d617Schristos       so we may see their outcome.            so we may see their outcome.
1070*75f6d617Schristos     The two are the same,                   The two are the same,
1071*75f6d617Schristos     But after they are produced,            But after they are produced,
1072*75f6d617Schristos       they have different names.              they have different names.
1073*75f6d617Schristos                                        >    They both may be called deep and
1074*75f6d617Schristos                                        >    Deeper and more profound,
1075*75f6d617Schristos                                        >    The door of all subtleties!
1076*75f6d617Schristos
1077*75f6d617Schristos
1078*75f6d617SchristosFile: diff.info,  Node: Scripts,  Next: If-then-else,  Prev: Side by Side,  Up: Output Formats
1079*75f6d617Schristos
1080*75f6d617SchristosMaking Edit Scripts
1081*75f6d617Schristos===================
1082*75f6d617Schristos
1083*75f6d617Schristos   Several output modes produce command scripts for editing FROM-FILE
1084*75f6d617Schristosto produce TO-FILE.
1085*75f6d617Schristos
1086*75f6d617Schristos* Menu:
1087*75f6d617Schristos
1088*75f6d617Schristos* ed Scripts:: Using `diff' to produce commands for `ed'.
1089*75f6d617Schristos* Forward ed:: Making forward `ed' scripts.
1090*75f6d617Schristos* RCS::        A special `diff' output format used by RCS.
1091*75f6d617Schristos
1092*75f6d617Schristos
1093*75f6d617SchristosFile: diff.info,  Node: ed Scripts,  Next: Forward ed,  Up: Scripts
1094*75f6d617Schristos
1095*75f6d617Schristos`ed' Scripts
1096*75f6d617Schristos------------
1097*75f6d617Schristos
1098*75f6d617Schristos   `diff' can produce commands that direct the `ed' text editor to
1099*75f6d617Schristoschange the first file into the second file.  Long ago, this was the
1100*75f6d617Schristosonly output mode that was suitable for editing one file into another
1101*75f6d617Schristosautomatically; today, with `patch', it is almost obsolete.  Use the
1102*75f6d617Schristos`-e' or `--ed' option to select this output format.
1103*75f6d617Schristos
1104*75f6d617Schristos   Like the normal format (*note Normal::), this output format does not
1105*75f6d617Schristosshow any context; unlike the normal format, it does not include the
1106*75f6d617Schristosinformation necessary to apply the diff in reverse (to produce the first
1107*75f6d617Schristosfile if all you have is the second file and the diff).
1108*75f6d617Schristos
1109*75f6d617Schristos   If the file `d' contains the output of `diff -e old new', then the
1110*75f6d617Schristoscommand `(cat d && echo w) | ed - old' edits `old' to make it a copy of
1111*75f6d617Schristos`new'.  More generally, if `d1', `d2', ..., `dN' contain the outputs of
1112*75f6d617Schristos`diff -e old new1', `diff -e new1 new2', ..., `diff -e newN-1 newN',
1113*75f6d617Schristosrespectively, then the command `(cat d1 d2 ... dN && echo w) | ed -
1114*75f6d617Schristosold' edits `old' to make it a copy of `newN'.
1115*75f6d617Schristos
1116*75f6d617Schristos* Menu:
1117*75f6d617Schristos
1118*75f6d617Schristos* Detailed ed:: A detailed description of `ed' format.
1119*75f6d617Schristos* Example ed::  A sample `ed' script.
1120*75f6d617Schristos
1121*75f6d617Schristos
1122*75f6d617SchristosFile: diff.info,  Node: Detailed ed,  Next: Example ed,  Up: ed Scripts
1123*75f6d617Schristos
1124*75f6d617SchristosDetailed Description of `ed' Format
1125*75f6d617Schristos...................................
1126*75f6d617Schristos
1127*75f6d617Schristos   The `ed' output format consists of one or more hunks of differences.
1128*75f6d617SchristosThe changes closest to the ends of the files come first so that
1129*75f6d617Schristoscommands that change the number of lines do not affect how `ed'
1130*75f6d617Schristosinterprets line numbers in succeeding commands.  `ed' format hunks look
1131*75f6d617Schristoslike this:
1132*75f6d617Schristos
1133*75f6d617Schristos     CHANGE-COMMAND
1134*75f6d617Schristos     TO-FILE-LINE
1135*75f6d617Schristos     TO-FILE-LINE...
1136*75f6d617Schristos     .
1137*75f6d617Schristos
1138*75f6d617Schristos   Because `ed' uses a single period on a line to indicate the end of
1139*75f6d617Schristosinput, GNU `diff' protects lines of changes that contain a single
1140*75f6d617Schristosperiod on a line by writing two periods instead, then writing a
1141*75f6d617Schristossubsequent `ed' command to change the two periods into one.  The `ed'
1142*75f6d617Schristosformat cannot represent an incomplete line, so if the second file ends
1143*75f6d617Schristosin a changed incomplete line, `diff' reports an error and then pretends
1144*75f6d617Schristosthat a newline was appended.
1145*75f6d617Schristos
1146*75f6d617Schristos   There are three types of change commands.  Each consists of a line
1147*75f6d617Schristosnumber or comma-separated range of lines in the first file and a single
1148*75f6d617Schristoscharacter indicating the kind of change to make.  All line numbers are
1149*75f6d617Schristosthe original line numbers in the file.  The types of change commands
1150*75f6d617Schristosare:
1151*75f6d617Schristos
1152*75f6d617Schristos`La'
1153*75f6d617Schristos     Add text from the second file after line L in the first file.  For
1154*75f6d617Schristos     example, `8a' means to add the following lines after line 8 of file
1155*75f6d617Schristos     1.
1156*75f6d617Schristos
1157*75f6d617Schristos`Rc'
1158*75f6d617Schristos     Replace the lines in range R in the first file with the following
1159*75f6d617Schristos     lines.  Like a combined add and delete, but more compact.  For
1160*75f6d617Schristos     example, `5,7c' means change lines 5-7 of file 1 to read as the
1161*75f6d617Schristos     text file 2.
1162*75f6d617Schristos
1163*75f6d617Schristos`Rd'
1164*75f6d617Schristos     Delete the lines in range R from the first file.  For example,
1165*75f6d617Schristos     `5,7d' means delete lines 5-7 of file 1.
1166*75f6d617Schristos
1167*75f6d617Schristos
1168*75f6d617SchristosFile: diff.info,  Node: Example ed,  Prev: Detailed ed,  Up: ed Scripts
1169*75f6d617Schristos
1170*75f6d617SchristosExample `ed' Script
1171*75f6d617Schristos...................
1172*75f6d617Schristos
1173*75f6d617Schristos   Here is the output of `diff -e lao tzu' (*note Sample diff Input::,
1174*75f6d617Schristosfor the complete contents of the two files):
1175*75f6d617Schristos
1176*75f6d617Schristos     11a
1177*75f6d617Schristos     They both may be called deep and profound.
1178*75f6d617Schristos     Deeper and more profound,
1179*75f6d617Schristos     The door of all subtleties!
1180*75f6d617Schristos     .
1181*75f6d617Schristos     4c
1182*75f6d617Schristos     The named is the mother of all things.
1183*75f6d617Schristos
1184*75f6d617Schristos     .
1185*75f6d617Schristos     1,2d
1186*75f6d617Schristos
1187*75f6d617Schristos
1188*75f6d617SchristosFile: diff.info,  Node: Forward ed,  Next: RCS,  Prev: ed Scripts,  Up: Scripts
1189*75f6d617Schristos
1190*75f6d617SchristosForward `ed' Scripts
1191*75f6d617Schristos--------------------
1192*75f6d617Schristos
1193*75f6d617Schristos   `diff' can produce output that is like an `ed' script, but with
1194*75f6d617Schristoshunks in forward (front to back) order.  The format of the commands is
1195*75f6d617Schristosalso changed slightly: command characters precede the lines they
1196*75f6d617Schristosmodify, spaces separate line numbers in ranges, and no attempt is made
1197*75f6d617Schristosto disambiguate hunk lines consisting of a single period.  Like `ed'
1198*75f6d617Schristosformat, forward `ed' format cannot represent incomplete lines.
1199*75f6d617Schristos
1200*75f6d617Schristos   Forward `ed' format is not very useful, because neither `ed' nor
1201*75f6d617Schristos`patch' can apply diffs in this format.  It exists mainly for
1202*75f6d617Schristoscompatibility with older versions of `diff'.  Use the `-f' or
1203*75f6d617Schristos`--forward-ed' option to select it.
1204*75f6d617Schristos
1205*75f6d617Schristos
1206*75f6d617SchristosFile: diff.info,  Node: RCS,  Prev: Forward ed,  Up: Scripts
1207*75f6d617Schristos
1208*75f6d617SchristosRCS Scripts
1209*75f6d617Schristos-----------
1210*75f6d617Schristos
1211*75f6d617Schristos   The RCS output format is designed specifically for use by the
1212*75f6d617SchristosRevision Control System, which is a set of free programs used for
1213*75f6d617Schristosorganizing different versions and systems of files.  Use the `-n' or
1214*75f6d617Schristos`--rcs' option to select this output format.  It is like the forward
1215*75f6d617Schristos`ed' format (*note Forward ed::), but it can represent arbitrary
1216*75f6d617Schristoschanges to the contents of a file because it avoids the forward `ed'
1217*75f6d617Schristosformat's problems with lines consisting of a single period and with
1218*75f6d617Schristosincomplete lines.  Instead of ending text sections with a line
1219*75f6d617Schristosconsisting of a single period, each command specifies the number of
1220*75f6d617Schristoslines it affects; a combination of the `a' and `d' commands are used
1221*75f6d617Schristosinstead of `c'.  Also, if the second file ends in a changed incomplete
1222*75f6d617Schristosline, then the output also ends in an incomplete line.
1223*75f6d617Schristos
1224*75f6d617Schristos   Here is the output of `diff -n lao tzu' (*note Sample diff Input::,
1225*75f6d617Schristosfor the complete contents of the two files):
1226*75f6d617Schristos
1227*75f6d617Schristos     d1 2
1228*75f6d617Schristos     d4 1
1229*75f6d617Schristos     a4 2
1230*75f6d617Schristos     The named is the mother of all things.
1231*75f6d617Schristos
1232*75f6d617Schristos     a11 3
1233*75f6d617Schristos     They both may be called deep and profound.
1234*75f6d617Schristos     Deeper and more profound,
1235*75f6d617Schristos     The door of all subtleties!
1236*75f6d617Schristos
1237*75f6d617Schristos
1238*75f6d617SchristosFile: diff.info,  Node: If-then-else,  Prev: Scripts,  Up: Output Formats
1239*75f6d617Schristos
1240*75f6d617SchristosMerging Files with If-then-else
1241*75f6d617Schristos===============================
1242*75f6d617Schristos
1243*75f6d617Schristos   You can use `diff' to merge two files of C source code.  The output
1244*75f6d617Schristosof `diff' in this format contains all the lines of both files.  Lines
1245*75f6d617Schristoscommon to both files are output just once; the differing parts are
1246*75f6d617Schristosseparated by the C preprocessor directives `#ifdef NAME' or `#ifndef
1247*75f6d617SchristosNAME', `#else', and `#endif'.  When compiling the output, you select
1248*75f6d617Schristoswhich version to use by either defining or leaving undefined the macro
1249*75f6d617SchristosNAME.
1250*75f6d617Schristos
1251*75f6d617Schristos   To merge two files, use `diff' with the `-D NAME' or `--ifdef=NAME'
1252*75f6d617Schristosoption.  The argument NAME is the C preprocessor identifier to use in
1253*75f6d617Schristosthe `#ifdef' and `#ifndef' directives.
1254*75f6d617Schristos
1255*75f6d617Schristos   For example, if you change an instance of `wait (&s)' to `waitpid
1256*75f6d617Schristos(-1, &s, 0)' and then merge the old and new files with the
1257*75f6d617Schristos`--ifdef=HAVE_WAITPID' option, then the affected part of your code
1258*75f6d617Schristosmight look like this:
1259*75f6d617Schristos
1260*75f6d617Schristos         do {
1261*75f6d617Schristos     #ifndef HAVE_WAITPID
1262*75f6d617Schristos             if ((w = wait (&s)) < 0  &&  errno != EINTR)
1263*75f6d617Schristos     #else /* HAVE_WAITPID */
1264*75f6d617Schristos             if ((w = waitpid (-1, &s, 0)) < 0  &&  errno != EINTR)
1265*75f6d617Schristos     #endif /* HAVE_WAITPID */
1266*75f6d617Schristos                 return w;
1267*75f6d617Schristos         } while (w != child);
1268*75f6d617Schristos
1269*75f6d617Schristos   You can specify formats for languages other than C by using line
1270*75f6d617Schristosgroup formats and line formats, as described in the next sections.
1271*75f6d617Schristos
1272*75f6d617Schristos* Menu:
1273*75f6d617Schristos
1274*75f6d617Schristos* Line Group Formats::    Formats for general if-then-else line groups.
1275*75f6d617Schristos* Line Formats::          Formats for each line in a line group.
1276*75f6d617Schristos* Detailed If-then-else:: A detailed description of if-then-else format.
1277*75f6d617Schristos* Example If-then-else::  Sample if-then-else format output.
1278*75f6d617Schristos
1279*75f6d617Schristos
1280*75f6d617SchristosFile: diff.info,  Node: Line Group Formats,  Next: Line Formats,  Up: If-then-else
1281*75f6d617Schristos
1282*75f6d617SchristosLine Group Formats
1283*75f6d617Schristos------------------
1284*75f6d617Schristos
1285*75f6d617Schristos   Line group formats let you specify formats suitable for many
1286*75f6d617Schristosapplications that allow if-then-else input, including programming
1287*75f6d617Schristoslanguages and text formatting languages.  A line group format specifies
1288*75f6d617Schristosthe output format for a contiguous group of similar lines.
1289*75f6d617Schristos
1290*75f6d617Schristos   For example, the following command compares the TeX files `old' and
1291*75f6d617Schristos`new', and outputs a merged file in which old regions are surrounded by
1292*75f6d617Schristos`\begin{em}'-`\end{em}' lines, and new regions are surrounded by
1293*75f6d617Schristos`\begin{bf}'-`\end{bf}' lines.
1294*75f6d617Schristos
1295*75f6d617Schristos     diff \
1296*75f6d617Schristos        --old-group-format='\begin{em}
1297*75f6d617Schristos     %<\end{em}
1298*75f6d617Schristos     ' \
1299*75f6d617Schristos        --new-group-format='\begin{bf}
1300*75f6d617Schristos     %>\end{bf}
1301*75f6d617Schristos     ' \
1302*75f6d617Schristos        old new
1303*75f6d617Schristos
1304*75f6d617Schristos   The following command is equivalent to the above example, but it is a
1305*75f6d617Schristoslittle more verbose, because it spells out the default line group
1306*75f6d617Schristosformats.
1307*75f6d617Schristos
1308*75f6d617Schristos     diff \
1309*75f6d617Schristos        --old-group-format='\begin{em}
1310*75f6d617Schristos     %<\end{em}
1311*75f6d617Schristos     ' \
1312*75f6d617Schristos        --new-group-format='\begin{bf}
1313*75f6d617Schristos     %>\end{bf}
1314*75f6d617Schristos     ' \
1315*75f6d617Schristos        --unchanged-group-format='%=' \
1316*75f6d617Schristos        --changed-group-format='\begin{em}
1317*75f6d617Schristos     %<\end{em}
1318*75f6d617Schristos     \begin{bf}
1319*75f6d617Schristos     %>\end{bf}
1320*75f6d617Schristos     ' \
1321*75f6d617Schristos        old new
1322*75f6d617Schristos
1323*75f6d617Schristos   Here is a more advanced example, which outputs a diff listing with
1324*75f6d617Schristosheaders containing line numbers in a "plain English" style.
1325*75f6d617Schristos
1326*75f6d617Schristos     diff \
1327*75f6d617Schristos        --unchanged-group-format='' \
1328*75f6d617Schristos        --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
1329*75f6d617Schristos     %<' \
1330*75f6d617Schristos        --new-group-format='-------- %dN line%(N=1?:s) added after %de:
1331*75f6d617Schristos     %>' \
1332*75f6d617Schristos        --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
1333*75f6d617Schristos     %<-------- to:
1334*75f6d617Schristos     %>' \
1335*75f6d617Schristos        old new
1336*75f6d617Schristos
1337*75f6d617Schristos   To specify a line group format, use `diff' with one of the options
1338*75f6d617Schristoslisted below.  You can specify up to four line group formats, one for
1339*75f6d617Schristoseach kind of line group.  You should quote FORMAT, because it typically
1340*75f6d617Schristoscontains shell metacharacters.
1341*75f6d617Schristos
1342*75f6d617Schristos`--old-group-format=FORMAT'
1343*75f6d617Schristos     These line groups are hunks containing only lines from the first
1344*75f6d617Schristos     file.  The default old group format is the same as the changed
1345*75f6d617Schristos     group format if it is specified; otherwise it is a format that
1346*75f6d617Schristos     outputs the line group as-is.
1347*75f6d617Schristos
1348*75f6d617Schristos`--new-group-format=FORMAT'
1349*75f6d617Schristos     These line groups are hunks containing only lines from the second
1350*75f6d617Schristos     file.  The default new group format is same as the changed group
1351*75f6d617Schristos     format if it is specified; otherwise it is a format that outputs
1352*75f6d617Schristos     the line group as-is.
1353*75f6d617Schristos
1354*75f6d617Schristos`--changed-group-format=FORMAT'
1355*75f6d617Schristos     These line groups are hunks containing lines from both files.  The
1356*75f6d617Schristos     default changed group format is the concatenation of the old and
1357*75f6d617Schristos     new group formats.
1358*75f6d617Schristos
1359*75f6d617Schristos`--unchanged-group-format=FORMAT'
1360*75f6d617Schristos     These line groups contain lines common to both files.  The default
1361*75f6d617Schristos     unchanged group format is a format that outputs the line group
1362*75f6d617Schristos     as-is.
1363*75f6d617Schristos
1364*75f6d617Schristos   In a line group format, ordinary characters represent themselves;
1365*75f6d617Schristosconversion specifications start with `%' and have one of the following
1366*75f6d617Schristosforms.
1367*75f6d617Schristos
1368*75f6d617Schristos`%<'
1369*75f6d617Schristos     stands for the lines from the first file, including the trailing
1370*75f6d617Schristos     newline.  Each line is formatted according to the old line format
1371*75f6d617Schristos     (*note Line Formats::).
1372*75f6d617Schristos
1373*75f6d617Schristos`%>'
1374*75f6d617Schristos     stands for the lines from the second file, including the trailing
1375*75f6d617Schristos     newline.  Each line is formatted according to the new line format.
1376*75f6d617Schristos
1377*75f6d617Schristos`%='
1378*75f6d617Schristos     stands for the lines common to both files, including the trailing
1379*75f6d617Schristos     newline.  Each line is formatted according to the unchanged line
1380*75f6d617Schristos     format.
1381*75f6d617Schristos
1382*75f6d617Schristos`%%'
1383*75f6d617Schristos     stands for `%'.
1384*75f6d617Schristos
1385*75f6d617Schristos`%c'C''
1386*75f6d617Schristos     where C is a single character, stands for C.  C may not be a
1387*75f6d617Schristos     backslash or an apostrophe.  For example, `%c':'' stands for a
1388*75f6d617Schristos     colon, even inside the then-part of an if-then-else format, which
1389*75f6d617Schristos     a colon would normally terminate.
1390*75f6d617Schristos
1391*75f6d617Schristos`%c'\O''
1392*75f6d617Schristos     where O is a string of 1, 2, or 3 octal digits, stands for the
1393*75f6d617Schristos     character with octal code O.  For example, `%c'\0'' stands for a
1394*75f6d617Schristos     null character.
1395*75f6d617Schristos
1396*75f6d617Schristos`FN'
1397*75f6d617Schristos     where F is a `printf' conversion specification and N is one of the
1398*75f6d617Schristos     following letters, stands for N's value formatted with F.
1399*75f6d617Schristos
1400*75f6d617Schristos    `e'
1401*75f6d617Schristos          The line number of the line just before the group in the old
1402*75f6d617Schristos          file.
1403*75f6d617Schristos
1404*75f6d617Schristos    `f'
1405*75f6d617Schristos          The line number of the first line in the group in the old
1406*75f6d617Schristos          file; equals E + 1.
1407*75f6d617Schristos
1408*75f6d617Schristos    `l'
1409*75f6d617Schristos          The line number of the last line in the group in the old file.
1410*75f6d617Schristos
1411*75f6d617Schristos    `m'
1412*75f6d617Schristos          The line number of the line just after the group in the old
1413*75f6d617Schristos          file; equals L + 1.
1414*75f6d617Schristos
1415*75f6d617Schristos    `n'
1416*75f6d617Schristos          The number of lines in the group in the old file; equals L -
1417*75f6d617Schristos          F + 1.
1418*75f6d617Schristos
1419*75f6d617Schristos    `E, F, L, M, N'
1420*75f6d617Schristos          Likewise, for lines in the new file.
1421*75f6d617Schristos
1422*75f6d617Schristos     The `printf' conversion specification can be `%d', `%o', `%x', or
1423*75f6d617Schristos     `%X', specifying decimal, octal, lower case hexadecimal, or upper
1424*75f6d617Schristos     case hexadecimal output respectively.  After the `%' the following
1425*75f6d617Schristos     options can appear in sequence: a series of zero or more flags; an
1426*75f6d617Schristos     integer specifying the minimum field width; and a period followed
1427*75f6d617Schristos     by an optional integer specifying the minimum number of digits.
1428*75f6d617Schristos     The flags are `-' for left-justification, `'' for separating the
1429*75f6d617Schristos     digit into groups as specified by the `LC_NUMERIC' locale category,
1430*75f6d617Schristos     and `0' for padding with zeros instead of spaces.  For example,
1431*75f6d617Schristos     `%5dN' prints the number of new lines in the group in a field of
1432*75f6d617Schristos     width 5 characters, using the `printf' format `"%5d"'.
1433*75f6d617Schristos
1434*75f6d617Schristos`(A=B?T:E)'
1435*75f6d617Schristos     If A equals B then T else E.  A and B are each either a decimal
1436*75f6d617Schristos     constant or a single letter interpreted as above.  This format
1437*75f6d617Schristos     spec is equivalent to T if A's value equals B's; otherwise it is
1438*75f6d617Schristos     equivalent to E.
1439*75f6d617Schristos
1440*75f6d617Schristos     For example, `%(N=0?no:%dN) line%(N=1?:s)' is equivalent to `no
1441*75f6d617Schristos     lines' if N (the number of lines in the group in the the new file)
1442*75f6d617Schristos     is 0, to `1 line' if N is 1, and to `%dN lines' otherwise.
1443*75f6d617Schristos
1444*75f6d617Schristos
1445*75f6d617SchristosFile: diff.info,  Node: Line Formats,  Next: Detailed If-then-else,  Prev: Line Group Formats,  Up: If-then-else
1446*75f6d617Schristos
1447*75f6d617SchristosLine Formats
1448*75f6d617Schristos------------
1449*75f6d617Schristos
1450*75f6d617Schristos   Line formats control how each line taken from an input file is
1451*75f6d617Schristosoutput as part of a line group in if-then-else format.
1452*75f6d617Schristos
1453*75f6d617Schristos   For example, the following command outputs text with a one-character
1454*75f6d617Schristoschange indicator to the left of the text.  The first character of output
1455*75f6d617Schristosis `-' for deleted lines, `|' for added lines, and a space for
1456*75f6d617Schristosunchanged lines.  The formats contain newline characters where newlines
1457*75f6d617Schristosare desired on output.
1458*75f6d617Schristos
1459*75f6d617Schristos     diff \
1460*75f6d617Schristos        --old-line-format='-%l
1461*75f6d617Schristos     ' \
1462*75f6d617Schristos        --new-line-format='|%l
1463*75f6d617Schristos     ' \
1464*75f6d617Schristos        --unchanged-line-format=' %l
1465*75f6d617Schristos     ' \
1466*75f6d617Schristos        old new
1467*75f6d617Schristos
1468*75f6d617Schristos   To specify a line format, use one of the following options.  You
1469*75f6d617Schristosshould quote FORMAT, since it often contains shell metacharacters.
1470*75f6d617Schristos
1471*75f6d617Schristos`--old-line-format=FORMAT'
1472*75f6d617Schristos     formats lines just from the first file.
1473*75f6d617Schristos
1474*75f6d617Schristos`--new-line-format=FORMAT'
1475*75f6d617Schristos     formats lines just from the second file.
1476*75f6d617Schristos
1477*75f6d617Schristos`--unchanged-line-format=FORMAT'
1478*75f6d617Schristos     formats lines common to both files.
1479*75f6d617Schristos
1480*75f6d617Schristos`--line-format=FORMAT'
1481*75f6d617Schristos     formats all lines; in effect, it sets all three above options
1482*75f6d617Schristos     simultaneously.
1483*75f6d617Schristos
1484*75f6d617Schristos   In a line format, ordinary characters represent themselves;
1485*75f6d617Schristosconversion specifications start with `%' and have one of the following
1486*75f6d617Schristosforms.
1487*75f6d617Schristos
1488*75f6d617Schristos`%l'
1489*75f6d617Schristos     stands for the contents of the line, not counting its trailing
1490*75f6d617Schristos     newline (if any).  This format ignores whether the line is
1491*75f6d617Schristos     incomplete; *Note Incomplete Lines::.
1492*75f6d617Schristos
1493*75f6d617Schristos`%L'
1494*75f6d617Schristos     stands for the contents of the line, including its trailing newline
1495*75f6d617Schristos     (if any).  If a line is incomplete, this format preserves its
1496*75f6d617Schristos     incompleteness.
1497*75f6d617Schristos
1498*75f6d617Schristos`%%'
1499*75f6d617Schristos     stands for `%'.
1500*75f6d617Schristos
1501*75f6d617Schristos`%c'C''
1502*75f6d617Schristos     where C is a single character, stands for C.  C may not be a
1503*75f6d617Schristos     backslash or an apostrophe.  For example, `%c':'' stands for a
1504*75f6d617Schristos     colon.
1505*75f6d617Schristos
1506*75f6d617Schristos`%c'\O''
1507*75f6d617Schristos     where O is a string of 1, 2, or 3 octal digits, stands for the
1508*75f6d617Schristos     character with octal code O.  For example, `%c'\0'' stands for a
1509*75f6d617Schristos     null character.
1510*75f6d617Schristos
1511*75f6d617Schristos`Fn'
1512*75f6d617Schristos     where F is a `printf' conversion specification, stands for the
1513*75f6d617Schristos     line number formatted with F.  For example, `%.5dn' prints the
1514*75f6d617Schristos     line number using the `printf' format `"%.5d"'.  *Note Line Group
1515*75f6d617Schristos     Formats::, for more about printf conversion specifications.
1516*75f6d617Schristos
1517*75f6d617Schristos   The default line format is `%l' followed by a newline character.
1518*75f6d617Schristos
1519*75f6d617Schristos   If the input contains tab characters and it is important that they
1520*75f6d617Schristosline up on output, you should ensure that `%l' or `%L' in a line format
1521*75f6d617Schristosis just after a tab stop (e.g. by preceding `%l' or `%L' with a tab
1522*75f6d617Schristoscharacter), or you should use the `-t' or `--expand-tabs' option.
1523*75f6d617Schristos
1524*75f6d617Schristos   Taken together, the line and line group formats let you specify many
1525*75f6d617Schristosdifferent formats.  For example, the following command uses a format
1526*75f6d617Schristossimilar to normal `diff' format.  You can tailor this command to get
1527*75f6d617Schristosfine control over `diff' output.
1528*75f6d617Schristos
1529*75f6d617Schristos     diff \
1530*75f6d617Schristos        --old-line-format='< %l
1531*75f6d617Schristos     ' \
1532*75f6d617Schristos        --new-line-format='> %l
1533*75f6d617Schristos     ' \
1534*75f6d617Schristos        --old-group-format='%df%(f=l?:,%dl)d%dE
1535*75f6d617Schristos     %<' \
1536*75f6d617Schristos        --new-group-format='%dea%dF%(F=L?:,%dL)
1537*75f6d617Schristos     %>' \
1538*75f6d617Schristos        --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)
1539*75f6d617Schristos     %<---
1540*75f6d617Schristos     %>' \
1541*75f6d617Schristos        --unchanged-group-format='' \
1542*75f6d617Schristos        old new
1543*75f6d617Schristos
1544*75f6d617Schristos
1545*75f6d617SchristosFile: diff.info,  Node: Detailed If-then-else,  Next: Example If-then-else,  Prev: Line Formats,  Up: If-then-else
1546*75f6d617Schristos
1547*75f6d617SchristosDetailed Description of If-then-else Format
1548*75f6d617Schristos-------------------------------------------
1549*75f6d617Schristos
1550*75f6d617Schristos   For lines common to both files, `diff' uses the unchanged line group
1551*75f6d617Schristosformat.  For each hunk of differences in the merged output format, if
1552*75f6d617Schristosthe hunk contains only lines from the first file, `diff' uses the old
1553*75f6d617Schristosline group format; if the hunk contains only lines from the second
1554*75f6d617Schristosfile, `diff' uses the new group format; otherwise, `diff' uses the
1555*75f6d617Schristoschanged group format.
1556*75f6d617Schristos
1557*75f6d617Schristos   The old, new, and unchanged line formats specify the output format of
1558*75f6d617Schristoslines from the first file, lines from the second file, and lines common
1559*75f6d617Schristosto both files, respectively.
1560*75f6d617Schristos
1561*75f6d617Schristos   The option `--ifdef=NAME' is equivalent to the following sequence of
1562*75f6d617Schristosoptions using shell syntax:
1563*75f6d617Schristos
1564*75f6d617Schristos     --old-group-format='#ifndef NAME
1565*75f6d617Schristos     %<#endif /* ! NAME */
1566*75f6d617Schristos     ' \
1567*75f6d617Schristos     --new-group-format='#ifdef NAME
1568*75f6d617Schristos     %>#endif /* NAME */
1569*75f6d617Schristos     ' \
1570*75f6d617Schristos     --unchanged-group-format='%=' \
1571*75f6d617Schristos     --changed-group-format='#ifndef NAME
1572*75f6d617Schristos     %<#else /* NAME */
1573*75f6d617Schristos     %>#endif /* NAME */
1574*75f6d617Schristos     '
1575*75f6d617Schristos
1576*75f6d617Schristos   You should carefully check the `diff' output for proper nesting.
1577*75f6d617SchristosFor example, when using the `-D NAME' or `--ifdef=NAME' option, you
1578*75f6d617Schristosshould check that if the differing lines contain any of the C
1579*75f6d617Schristospreprocessor directives `#ifdef', `#ifndef', `#else', `#elif', or
1580*75f6d617Schristos`#endif', they are nested properly and match.  If they don't, you must
1581*75f6d617Schristosmake corrections manually.  It is a good idea to carefully check the
1582*75f6d617Schristosresulting code anyway to make sure that it really does what you want it
1583*75f6d617Schristosto; depending on how the input files were produced, the output might
1584*75f6d617Schristoscontain duplicate or otherwise incorrect code.
1585*75f6d617Schristos
1586*75f6d617Schristos   The `patch' `-D NAME' option behaves like the `diff' `-D NAME'
1587*75f6d617Schristosoption, except it operates on a file and a diff to produce a merged
1588*75f6d617Schristosfile; *Note patch Options::.
1589*75f6d617Schristos
1590*75f6d617Schristos
1591*75f6d617SchristosFile: diff.info,  Node: Example If-then-else,  Prev: Detailed If-then-else,  Up: If-then-else
1592*75f6d617Schristos
1593*75f6d617SchristosAn Example of If-then-else Format
1594*75f6d617Schristos---------------------------------
1595*75f6d617Schristos
1596*75f6d617Schristos   Here is the output of `diff -DTWO lao tzu' (*note Sample diff
1597*75f6d617SchristosInput::, for the complete contents of the two files):
1598*75f6d617Schristos
1599*75f6d617Schristos     #ifndef TWO
1600*75f6d617Schristos     The Way that can be told of is not the eternal Way;
1601*75f6d617Schristos     The name that can be named is not the eternal name.
1602*75f6d617Schristos     #endif /* ! TWO */
1603*75f6d617Schristos     The Nameless is the origin of Heaven and Earth;
1604*75f6d617Schristos     #ifndef TWO
1605*75f6d617Schristos     The Named is the mother of all things.
1606*75f6d617Schristos     #else /* TWO */
1607*75f6d617Schristos     The named is the mother of all things.
1608*75f6d617Schristos
1609*75f6d617Schristos     #endif /* TWO */
1610*75f6d617Schristos     Therefore let there always be non-being,
1611*75f6d617Schristos       so we may see their subtlety,
1612*75f6d617Schristos     And let there always be being,
1613*75f6d617Schristos       so we may see their outcome.
1614*75f6d617Schristos     The two are the same,
1615*75f6d617Schristos     But after they are produced,
1616*75f6d617Schristos       they have different names.
1617*75f6d617Schristos     #ifdef TWO
1618*75f6d617Schristos     They both may be called deep and profound.
1619*75f6d617Schristos     Deeper and more profound,
1620*75f6d617Schristos     The door of all subtleties!
1621*75f6d617Schristos     #endif /* TWO */
1622*75f6d617Schristos
1623*75f6d617Schristos
1624*75f6d617SchristosFile: diff.info,  Node: Incomplete Lines,  Next: Comparing Directories,  Prev: Output Formats,  Up: Top
1625*75f6d617Schristos
1626*75f6d617SchristosIncomplete Lines
1627*75f6d617Schristos****************
1628*75f6d617Schristos
1629*75f6d617Schristos   When an input file ends in a non-newline character, its last line is
1630*75f6d617Schristoscalled an "incomplete line" because its last character is not a
1631*75f6d617Schristosnewline.  All other lines are called "full lines" and end in a newline
1632*75f6d617Schristoscharacter.  Incomplete lines do not match full lines unless differences
1633*75f6d617Schristosin white space are ignored (*note White Space::).
1634*75f6d617Schristos
1635*75f6d617Schristos   An incomplete line is normally distinguished on output from a full
1636*75f6d617Schristosline by a following line that starts with `\'.  However, the RCS format
1637*75f6d617Schristos(*note RCS::) outputs the incomplete line as-is, without any trailing
1638*75f6d617Schristosnewline or following line.  The side by side format normally represents
1639*75f6d617Schristosincomplete lines as-is, but in some cases uses a `\' or `/' gutter
1640*75f6d617Schristosmarker; *Note Side by Side::.  The if-then-else line format preserves a
1641*75f6d617Schristosline's incompleteness with `%L', and discards the newline with `%l';
1642*75f6d617Schristos*Note Line Formats::.  Finally, with the `ed' and forward `ed' output
1643*75f6d617Schristosformats (*note Output Formats::) `diff' cannot represent an incomplete
1644*75f6d617Schristosline, so it pretends there was a newline and reports an error.
1645*75f6d617Schristos
1646*75f6d617Schristos   For example, suppose `F' and `G' are one-byte files that contain
1647*75f6d617Schristosjust `f' and `g', respectively.  Then `diff F G' outputs
1648*75f6d617Schristos
1649*75f6d617Schristos     1c1
1650*75f6d617Schristos     < f
1651*75f6d617Schristos     \ No newline at end of file
1652*75f6d617Schristos     ---
1653*75f6d617Schristos     > g
1654*75f6d617Schristos     \ No newline at end of file
1655*75f6d617Schristos
1656*75f6d617Schristos(The exact message may differ in non-English locales.)  `diff -n F G'
1657*75f6d617Schristosoutputs the following without a trailing newline:
1658*75f6d617Schristos
1659*75f6d617Schristos     d1 1
1660*75f6d617Schristos     a1 1
1661*75f6d617Schristos     g
1662*75f6d617Schristos
1663*75f6d617Schristos`diff -e F G' reports two errors and outputs the following:
1664*75f6d617Schristos
1665*75f6d617Schristos     1c
1666*75f6d617Schristos     g
1667*75f6d617Schristos     .
1668*75f6d617Schristos
1669*75f6d617Schristos
1670*75f6d617SchristosFile: diff.info,  Node: Comparing Directories,  Next: Adjusting Output,  Prev: Incomplete Lines,  Up: Top
1671*75f6d617Schristos
1672*75f6d617SchristosComparing Directories
1673*75f6d617Schristos*********************
1674*75f6d617Schristos
1675*75f6d617Schristos   You can use `diff' to compare some or all of the files in two
1676*75f6d617Schristosdirectory trees.  When both file name arguments to `diff' are
1677*75f6d617Schristosdirectories, it compares each file that is contained in both
1678*75f6d617Schristosdirectories, examining file names in alphabetical order as specified by
1679*75f6d617Schristosthe `LC_COLLATE' locale category.  Normally `diff' is silent about
1680*75f6d617Schristospairs of files that contain no differences, but if you use the `-s' or
1681*75f6d617Schristos`--report-identical-files' option, it reports pairs of identical files.
1682*75f6d617SchristosNormally `diff' reports subdirectories common to both directories
1683*75f6d617Schristoswithout comparing subdirectories' files, but if you use the `-r' or
1684*75f6d617Schristos`--recursive' option, it compares every corresponding pair of files in
1685*75f6d617Schristosthe directory trees, as many levels deep as they go.
1686*75f6d617Schristos
1687*75f6d617Schristos   For file names that are in only one of the directories, `diff'
1688*75f6d617Schristosnormally does not show the contents of the file that exists; it reports
1689*75f6d617Schristosonly that the file exists in that directory and not in the other.  You
1690*75f6d617Schristoscan make `diff' act as though the file existed but was empty in the
1691*75f6d617Schristosother directory, so that it outputs the entire contents of the file that
1692*75f6d617Schristosactually exists.  (It is output as either an insertion or a deletion,
1693*75f6d617Schristosdepending on whether it is in the first or the second directory given.)
1694*75f6d617SchristosTo do this, use the `-N' or `--new-file' option.
1695*75f6d617Schristos
1696*75f6d617Schristos   If the older directory contains one or more large files that are not
1697*75f6d617Schristosin the newer directory, you can make the patch smaller by using the
1698*75f6d617Schristos`--unidirectional-new-file' option instead of `-N'.  This option is
1699*75f6d617Schristoslike `-N' except that it only inserts the contents of files that appear
1700*75f6d617Schristosin the second directory but not the first (that is, files that were
1701*75f6d617Schristosadded).  At the top of the patch, write instructions for the user
1702*75f6d617Schristosapplying the patch to remove the files that were deleted before
1703*75f6d617Schristosapplying the patch.  *Note Making Patches::, for more discussion of
1704*75f6d617Schristosmaking patches for distribution.
1705*75f6d617Schristos
1706*75f6d617Schristos   To ignore some files while comparing directories, use the `-x
1707*75f6d617SchristosPATTERN' or `--exclude=PATTERN' option.  This option ignores any files
1708*75f6d617Schristosor subdirectories whose base names match the shell pattern PATTERN.
1709*75f6d617SchristosUnlike in the shell, a period at the start of the base of a file name
1710*75f6d617Schristosmatches a wildcard at the start of a pattern.  You should enclose
1711*75f6d617SchristosPATTERN in quotes so that the shell does not expand it.  For example,
1712*75f6d617Schristosthe option `-x '*.[ao]'' ignores any file whose name ends with `.a' or
1713*75f6d617Schristos`.o'.
1714*75f6d617Schristos
1715*75f6d617Schristos   This option accumulates if you specify it more than once.  For
1716*75f6d617Schristosexample, using the options `-x 'RCS' -x '*,v'' ignores any file or
1717*75f6d617Schristossubdirectory whose base name is `RCS' or ends with `,v'.
1718*75f6d617Schristos
1719*75f6d617Schristos   If you need to give this option many times, you can instead put the
1720*75f6d617Schristospatterns in a file, one pattern per line, and use the `-X FILE' or
1721*75f6d617Schristos`--exclude-from=FILE' option.
1722*75f6d617Schristos
1723*75f6d617Schristos   If you have been comparing two directories and stopped partway
1724*75f6d617Schristosthrough, later you might want to continue where you left off.  You can
1725*75f6d617Schristosdo this by using the `-S FILE' or `--starting-file=FILE' option.  This
1726*75f6d617Schristoscompares only the file FILE and all alphabetically later files in the
1727*75f6d617Schristostopmost directory level.
1728*75f6d617Schristos
1729*75f6d617Schristos   If two directories differ only in that file names are lower case in
1730*75f6d617Schristosone directory and upper case in the upper, `diff' normally reports many
1731*75f6d617Schristosdifferences because it compares file names in a case sensitive way.
1732*75f6d617SchristosWith the `--ignore-file-name-case' option, `diff' ignores case
1733*75f6d617Schristosdifferences in file names, so that for example the contents of the file
1734*75f6d617Schristos`Tao' in one directory are compared to the contents of the file `TAO'
1735*75f6d617Schristosin the other.  The `--no-ignore-file-name-case' option cancels the
1736*75f6d617Schristoseffect of the `--ignore-file-name-case' option, reverting to the default
1737*75f6d617Schristosbehavior.
1738*75f6d617Schristos
1739*75f6d617Schristos   If an `-x PATTERN', `--exclude=PATTERN', `-X FILE', or
1740*75f6d617Schristos`--exclude-from=FILE' option is specified while the
1741*75f6d617Schristos`--ignore-file-name-case' option is in effect, case is ignored when
1742*75f6d617Schristosexcluding file names matching the specified patterns.
1743*75f6d617Schristos
1744*75f6d617Schristos
1745*75f6d617SchristosFile: diff.info,  Node: Adjusting Output,  Next: diff Performance,  Prev: Comparing Directories,  Up: Top
1746*75f6d617Schristos
1747*75f6d617SchristosMaking `diff' Output Prettier
1748*75f6d617Schristos*****************************
1749*75f6d617Schristos
1750*75f6d617Schristos   `diff' provides several ways to adjust the appearance of its output.
1751*75f6d617SchristosThese adjustments can be applied to any output format.
1752*75f6d617Schristos
1753*75f6d617Schristos* Menu:
1754*75f6d617Schristos
1755*75f6d617Schristos* Tabs::       Preserving the alignment of tab stops.
1756*75f6d617Schristos* Pagination:: Page numbering and time-stamping `diff' output.
1757*75f6d617Schristos
1758*75f6d617Schristos
1759*75f6d617SchristosFile: diff.info,  Node: Tabs,  Next: Pagination,  Up: Adjusting Output
1760*75f6d617Schristos
1761*75f6d617SchristosPreserving Tab Stop Alignment
1762*75f6d617Schristos=============================
1763*75f6d617Schristos
1764*75f6d617Schristos   The lines of text in some of the `diff' output formats are preceded
1765*75f6d617Schristosby one or two characters that indicate whether the text is inserted,
1766*75f6d617Schristosdeleted, or changed.  The addition of those characters can cause tabs to
1767*75f6d617Schristosmove to the next tab stop, throwing off the alignment of columns in the
1768*75f6d617Schristosline.  GNU `diff' provides two ways to make tab-aligned columns line up
1769*75f6d617Schristoscorrectly.
1770*75f6d617Schristos
1771*75f6d617Schristos   The first way is to have `diff' convert all tabs into the correct
1772*75f6d617Schristosnumber of spaces before outputting them; select this method with the
1773*75f6d617Schristos`-t' or `--expand-tabs' option.  `diff' assumes that tab stops are set
1774*75f6d617Schristosevery 8 print columns.  To use this form of output with `patch', you
1775*75f6d617Schristosmust give `patch' the `-l' or `--ignore-white-space' option (*note
1776*75f6d617SchristosChanged White Space::, for more information).
1777*75f6d617Schristos
1778*75f6d617Schristos   The other method for making tabs line up correctly is to add a tab
1779*75f6d617Schristoscharacter instead of a space after the indicator character at the
1780*75f6d617Schristosbeginning of the line.  This ensures that all following tab characters
1781*75f6d617Schristosare in the same position relative to tab stops that they were in the
1782*75f6d617Schristosoriginal files, so that the output is aligned correctly.  Its
1783*75f6d617Schristosdisadvantage is that it can make long lines too long to fit on one line
1784*75f6d617Schristosof the screen or the paper.  It also does not work with the unified
1785*75f6d617Schristosoutput format, which does not have a space character after the change
1786*75f6d617Schristostype indicator character.  Select this method with the `-T' or
1787*75f6d617Schristos`--initial-tab' option.
1788*75f6d617Schristos
1789*75f6d617Schristos
1790*75f6d617SchristosFile: diff.info,  Node: Pagination,  Prev: Tabs,  Up: Adjusting Output
1791*75f6d617Schristos
1792*75f6d617SchristosPaginating `diff' Output
1793*75f6d617Schristos========================
1794*75f6d617Schristos
1795*75f6d617Schristos   It can be convenient to have long output page-numbered and
1796*75f6d617Schristostime-stamped.  The `-l' and `--paginate' options do this by sending the
1797*75f6d617Schristos`diff' output through the `pr' program.  Here is what the page header
1798*75f6d617Schristosmight look like for `diff -lc lao tzu':
1799*75f6d617Schristos
1800*75f6d617Schristos     2002-02-22 14:20                 diff -lc lao tzu                 Page 1
1801*75f6d617Schristos
1802*75f6d617Schristos
1803*75f6d617SchristosFile: diff.info,  Node: diff Performance,  Next: Comparing Three Files,  Prev: Adjusting Output,  Up: Top
1804*75f6d617Schristos
1805*75f6d617Schristos`diff' Performance Tradeoffs
1806*75f6d617Schristos****************************
1807*75f6d617Schristos
1808*75f6d617Schristos   GNU `diff' runs quite efficiently; however, in some circumstances
1809*75f6d617Schristosyou can cause it to run faster or produce a more compact set of changes.
1810*75f6d617Schristos
1811*75f6d617Schristos   One way to improve `diff' performance is to use hard or symbolic
1812*75f6d617Schristoslinks to files instead of copies.  This improves performance because
1813*75f6d617Schristos`diff' normally does not need to read two hard or symbolic links to the
1814*75f6d617Schristossame file, since their contents must be identical.  For example,
1815*75f6d617Schristossuppose you copy a large directory hierarchy, make a few changes to the
1816*75f6d617Schristoscopy, and then often use `diff -r' to compare the original to the copy.
1817*75f6d617SchristosIf the original files are read-only, you can greatly improve
1818*75f6d617Schristosperformance by creating the copy using hard or symbolic links (e.g.,
1819*75f6d617Schristoswith GNU `cp -lR' or `cp -sR').  Before editing a file in the copy for
1820*75f6d617Schristosthe first time, you should break the link and replace it with a regular
1821*75f6d617Schristoscopy.
1822*75f6d617Schristos
1823*75f6d617Schristos   You can also affect the performance of GNU `diff' by giving it
1824*75f6d617Schristosoptions that change the way it compares files.  Performance has more
1825*75f6d617Schristosthan one dimension.  These options improve one aspect of performance at
1826*75f6d617Schristosthe cost of another, or they improve performance in some cases while
1827*75f6d617Schristoshurting it in others.
1828*75f6d617Schristos
1829*75f6d617Schristos   The way that GNU `diff' determines which lines have changed always
1830*75f6d617Schristoscomes up with a near-minimal set of differences.  Usually it is good
1831*75f6d617Schristosenough for practical purposes.  If the `diff' output is large, you
1832*75f6d617Schristosmight want `diff' to use a modified algorithm that sometimes produces a
1833*75f6d617Schristossmaller set of differences.  The `-d' or `--minimal' option does this;
1834*75f6d617Schristoshowever, it can also cause `diff' to run more slowly than usual, so it
1835*75f6d617Schristosis not the default behavior.
1836*75f6d617Schristos
1837*75f6d617Schristos   When the files you are comparing are large and have small groups of
1838*75f6d617Schristoschanges scattered throughout them, you can use the
1839*75f6d617Schristos`--speed-large-files' option to make a different modification to the
1840*75f6d617Schristosalgorithm that `diff' uses.  If the input files have a constant small
1841*75f6d617Schristosdensity of changes, this option speeds up the comparisons without
1842*75f6d617Schristoschanging the output.  If not, `diff' might produce a larger set of
1843*75f6d617Schristosdifferences; however, the output will still be correct.
1844*75f6d617Schristos
1845*75f6d617Schristos   Normally `diff' discards the prefix and suffix that is common to
1846*75f6d617Schristosboth files before it attempts to find a minimal set of differences.
1847*75f6d617SchristosThis makes `diff' run faster, but occasionally it may produce
1848*75f6d617Schristosnon-minimal output.  The `--horizon-lines=LINES' option prevents `diff'
1849*75f6d617Schristosfrom discarding the last LINES lines of the prefix and the first LINES
1850*75f6d617Schristoslines of the suffix.  This gives `diff' further opportunities to find a
1851*75f6d617Schristosminimal output.
1852*75f6d617Schristos
1853*75f6d617Schristos   Suppose a run of changed lines includes a sequence of lines at one
1854*75f6d617Schristosend and there is an identical sequence of lines just outside the other
1855*75f6d617Schristosend.  The `diff' command is free to choose which identical sequence is
1856*75f6d617Schristosincluded in the hunk.  In this case, `diff' normally shifts the hunk's
1857*75f6d617Schristosboundaries when this merges adjacent hunks, or shifts a hunk's lines
1858*75f6d617Schristostowards the end of the file.  Merging hunks can make the output look
1859*75f6d617Schristosnicer in some cases.
1860*75f6d617Schristos
1861*75f6d617Schristos
1862*75f6d617SchristosFile: diff.info,  Node: Comparing Three Files,  Next: diff3 Merging,  Prev: diff Performance,  Up: Top
1863*75f6d617Schristos
1864*75f6d617SchristosComparing Three Files
1865*75f6d617Schristos*********************
1866*75f6d617Schristos
1867*75f6d617Schristos   Use the program `diff3' to compare three files and show any
1868*75f6d617Schristosdifferences among them.  (`diff3' can also merge files; see *Note diff3
1869*75f6d617SchristosMerging::).
1870*75f6d617Schristos
1871*75f6d617Schristos   The "normal" `diff3' output format shows each hunk of differences
1872*75f6d617Schristoswithout surrounding context.  Hunks are labeled depending on whether
1873*75f6d617Schristosthey are two-way or three-way, and lines are annotated by their
1874*75f6d617Schristoslocation in the input files.
1875*75f6d617Schristos
1876*75f6d617Schristos   *Note Invoking diff3::, for more information on how to run `diff3'.
1877*75f6d617Schristos
1878*75f6d617Schristos* Menu:
1879*75f6d617Schristos
1880*75f6d617Schristos* Sample diff3 Input::    Sample `diff3' input for examples.
1881*75f6d617Schristos* Detailed diff3 Normal:: A detailed description of normal output format.
1882*75f6d617Schristos* diff3 Hunks::           The format of normal output format.
1883*75f6d617Schristos* Example diff3 Normal::  Sample output in the normal format.
1884*75f6d617Schristos
1885*75f6d617Schristos
1886*75f6d617SchristosFile: diff.info,  Node: Sample diff3 Input,  Next: Detailed diff3 Normal,  Up: Comparing Three Files
1887*75f6d617Schristos
1888*75f6d617SchristosA Third Sample Input File
1889*75f6d617Schristos=========================
1890*75f6d617Schristos
1891*75f6d617Schristos   Here is a third sample file that will be used in examples to
1892*75f6d617Schristosillustrate the output of `diff3' and how various options can change it.
1893*75f6d617SchristosThe first two files are the same that we used for `diff' (*note Sample
1894*75f6d617Schristosdiff Input::).  This is the third sample file, called `tao':
1895*75f6d617Schristos
1896*75f6d617Schristos     The Way that can be told of is not the eternal Way;
1897*75f6d617Schristos     The name that can be named is not the eternal name.
1898*75f6d617Schristos     The Nameless is the origin of Heaven and Earth;
1899*75f6d617Schristos     The named is the mother of all things.
1900*75f6d617Schristos
1901*75f6d617Schristos     Therefore let there always be non-being,
1902*75f6d617Schristos       so we may see their subtlety,
1903*75f6d617Schristos     And let there always be being,
1904*75f6d617Schristos       so we may see their result.
1905*75f6d617Schristos     The two are the same,
1906*75f6d617Schristos     But after they are produced,
1907*75f6d617Schristos       they have different names.
1908*75f6d617Schristos
1909*75f6d617Schristos       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
1910*75f6d617Schristos
1911*75f6d617Schristos
1912*75f6d617SchristosFile: diff.info,  Node: Detailed diff3 Normal,  Next: diff3 Hunks,  Prev: Sample diff3 Input,  Up: Comparing Three Files
1913*75f6d617Schristos
1914*75f6d617SchristosDetailed Description of `diff3' Normal Format
1915*75f6d617Schristos=============================================
1916*75f6d617Schristos
1917*75f6d617Schristos   Each hunk begins with a line marked `===='.  Three-way hunks have
1918*75f6d617Schristosplain `====' lines, and two-way hunks have `1', `2', or `3' appended to
1919*75f6d617Schristosspecify which of the three input files differ in that hunk.  The hunks
1920*75f6d617Schristoscontain copies of two or three sets of input lines each preceded by one
1921*75f6d617Schristosor two commands identifying where the lines came from.
1922*75f6d617Schristos
1923*75f6d617Schristos   Normally, two spaces precede each copy of an input line to
1924*75f6d617Schristosdistinguish it from the commands.  But with the `-T' or `--initial-tab'
1925*75f6d617Schristosoption, `diff3' uses a tab instead of two spaces; this lines up tabs
1926*75f6d617Schristoscorrectly.  *Note Tabs::, for more information.
1927*75f6d617Schristos
1928*75f6d617Schristos   Commands take the following forms:
1929*75f6d617Schristos
1930*75f6d617Schristos`FILE:La'
1931*75f6d617Schristos     This hunk appears after line L of file FILE, and contains no lines
1932*75f6d617Schristos     in that file.  To edit this file to yield the other files, one
1933*75f6d617Schristos     must append hunk lines taken from the other files.  For example,
1934*75f6d617Schristos     `1:11a' means that the hunk follows line 11 in the first file and
1935*75f6d617Schristos     contains no lines from that file.
1936*75f6d617Schristos
1937*75f6d617Schristos`FILE:Rc'
1938*75f6d617Schristos     This hunk contains the lines in the range R of file FILE.  The
1939*75f6d617Schristos     range R is a comma-separated pair of line numbers, or just one
1940*75f6d617Schristos     number if the range is a singleton.  To edit this file to yield the
1941*75f6d617Schristos     other files, one must change the specified lines to be the lines
1942*75f6d617Schristos     taken from the other files.  For example, `2:11,13c' means that
1943*75f6d617Schristos     the hunk contains lines 11 through 13 from the second file.
1944*75f6d617Schristos
1945*75f6d617Schristos   If the last line in a set of input lines is incomplete (*note
1946*75f6d617SchristosIncomplete Lines::), it is distinguished on output from a full line by
1947*75f6d617Schristosa following line that starts with `\'.
1948*75f6d617Schristos
1949*75f6d617Schristos
1950*75f6d617SchristosFile: diff.info,  Node: diff3 Hunks,  Next: Example diff3 Normal,  Prev: Detailed diff3 Normal,  Up: Comparing Three Files
1951*75f6d617Schristos
1952*75f6d617Schristos`diff3' Hunks
1953*75f6d617Schristos=============
1954*75f6d617Schristos
1955*75f6d617Schristos   Groups of lines that differ in two or three of the input files are
1956*75f6d617Schristoscalled "diff3 hunks", by analogy with `diff' hunks (*note Hunks::).  If
1957*75f6d617Schristosall three input files differ in a `diff3' hunk, the hunk is called a
1958*75f6d617Schristos"three-way hunk"; if just two input files differ, it is a "two-way
1959*75f6d617Schristoshunk".
1960*75f6d617Schristos
1961*75f6d617Schristos   As with `diff', several solutions are possible.  When comparing the
1962*75f6d617Schristosfiles `A', `B', and `C', `diff3' normally finds `diff3' hunks by
1963*75f6d617Schristosmerging the two-way hunks output by the two commands `diff A B' and
1964*75f6d617Schristos`diff A C'.  This does not necessarily minimize the size of the output,
1965*75f6d617Schristosbut exceptions should be rare.
1966*75f6d617Schristos
1967*75f6d617Schristos   For example, suppose `F' contains the three lines `a', `b', `f', `G'
1968*75f6d617Schristoscontains the lines `g', `b', `g', and `H' contains the lines `a', `b',
1969*75f6d617Schristos`h'.  `diff3 F G H' might output the following:
1970*75f6d617Schristos
1971*75f6d617Schristos     ====2
1972*75f6d617Schristos     1:1c
1973*75f6d617Schristos     3:1c
1974*75f6d617Schristos       a
1975*75f6d617Schristos     2:1c
1976*75f6d617Schristos       g
1977*75f6d617Schristos     ====
1978*75f6d617Schristos     1:3c
1979*75f6d617Schristos       f
1980*75f6d617Schristos     2:3c
1981*75f6d617Schristos       g
1982*75f6d617Schristos     3:3c
1983*75f6d617Schristos       h
1984*75f6d617Schristos
1985*75f6d617Schristosbecause it found a two-way hunk containing `a' in the first and third
1986*75f6d617Schristosfiles and `g' in the second file, then the single line `b' common to
1987*75f6d617Schristosall three files, then a three-way hunk containing the last line of each
1988*75f6d617Schristosfile.
1989*75f6d617Schristos
1990*75f6d617Schristos
1991*75f6d617SchristosFile: diff.info,  Node: Example diff3 Normal,  Prev: diff3 Hunks,  Up: Comparing Three Files
1992*75f6d617Schristos
1993*75f6d617SchristosAn Example of `diff3' Normal Format
1994*75f6d617Schristos===================================
1995*75f6d617Schristos
1996*75f6d617Schristos   Here is the output of the command `diff3 lao tzu tao' (*note Sample
1997*75f6d617Schristosdiff3 Input::, for the complete contents of the files).  Notice that it
1998*75f6d617Schristosshows only the lines that are different among the three files.
1999*75f6d617Schristos
2000*75f6d617Schristos     ====2
2001*75f6d617Schristos     1:1,2c
2002*75f6d617Schristos     3:1,2c
2003*75f6d617Schristos       The Way that can be told of is not the eternal Way;
2004*75f6d617Schristos       The name that can be named is not the eternal name.
2005*75f6d617Schristos     2:0a
2006*75f6d617Schristos     ====1
2007*75f6d617Schristos     1:4c
2008*75f6d617Schristos       The Named is the mother of all things.
2009*75f6d617Schristos     2:2,3c
2010*75f6d617Schristos     3:4,5c
2011*75f6d617Schristos       The named is the mother of all things.
2012*75f6d617Schristos
2013*75f6d617Schristos     ====3
2014*75f6d617Schristos     1:8c
2015*75f6d617Schristos     2:7c
2016*75f6d617Schristos         so we may see their outcome.
2017*75f6d617Schristos     3:9c
2018*75f6d617Schristos         so we may see their result.
2019*75f6d617Schristos     ====
2020*75f6d617Schristos     1:11a
2021*75f6d617Schristos     2:11,13c
2022*75f6d617Schristos       They both may be called deep and profound.
2023*75f6d617Schristos       Deeper and more profound,
2024*75f6d617Schristos       The door of all subtleties!
2025*75f6d617Schristos     3:13,14c
2026*75f6d617Schristos
2027*75f6d617Schristos         -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2028*75f6d617Schristos
2029*75f6d617Schristos
2030*75f6d617SchristosFile: diff.info,  Node: diff3 Merging,  Next: Interactive Merging,  Prev: Comparing Three Files,  Up: Top
2031*75f6d617Schristos
2032*75f6d617SchristosMerging From a Common Ancestor
2033*75f6d617Schristos******************************
2034*75f6d617Schristos
2035*75f6d617Schristos   When two people have made changes to copies of the same file,
2036*75f6d617Schristos`diff3' can produce a merged output that contains both sets of changes
2037*75f6d617Schristostogether with warnings about conflicts.
2038*75f6d617Schristos
2039*75f6d617Schristos   One might imagine programs with names like `diff4' and `diff5' to
2040*75f6d617Schristoscompare more than three files simultaneously, but in practice the need
2041*75f6d617Schristosrarely arises.  You can use `diff3' to merge three or more sets of
2042*75f6d617Schristoschanges to a file by merging two change sets at a time.
2043*75f6d617Schristos
2044*75f6d617Schristos   `diff3' can incorporate changes from two modified versions into a
2045*75f6d617Schristoscommon preceding version.  This lets you merge the sets of changes
2046*75f6d617Schristosrepresented by the two newer files.  Specify the common ancestor version
2047*75f6d617Schristosas the second argument and the two newer versions as the first and third
2048*75f6d617Schristosarguments, like this:
2049*75f6d617Schristos
2050*75f6d617Schristos     diff3 MINE OLDER YOURS
2051*75f6d617Schristos
2052*75f6d617SchristosYou can remember the order of the arguments by noting that they are in
2053*75f6d617Schristosalphabetical order.
2054*75f6d617Schristos
2055*75f6d617Schristos   You can think of this as subtracting OLDER from YOURS and adding the
2056*75f6d617Schristosresult to MINE, or as merging into MINE the changes that would turn
2057*75f6d617SchristosOLDER into YOURS.  This merging is well-defined as long as MINE and
2058*75f6d617SchristosOLDER match in the neighborhood of each such change.  This fails to be
2059*75f6d617Schristostrue when all three input files differ or when only OLDER differs; we
2060*75f6d617Schristoscall this a "conflict".  When all three input files differ, we call the
2061*75f6d617Schristosconflict an "overlap".
2062*75f6d617Schristos
2063*75f6d617Schristos   `diff3' gives you several ways to handle overlaps and conflicts.
2064*75f6d617SchristosYou can omit overlaps or conflicts, or select only overlaps, or mark
2065*75f6d617Schristosconflicts with special `<<<<<<<' and `>>>>>>>' lines.
2066*75f6d617Schristos
2067*75f6d617Schristos   `diff3' can output the merge results as an `ed' script that that can
2068*75f6d617Schristosbe applied to the first file to yield the merged output.  However, it
2069*75f6d617Schristosis usually better to have `diff3' generate the merged output directly;
2070*75f6d617Schristosthis bypasses some problems with `ed'.
2071*75f6d617Schristos
2072*75f6d617Schristos* Menu:
2073*75f6d617Schristos
2074*75f6d617Schristos* Which Changes::            Selecting changes to incorporate.
2075*75f6d617Schristos* Marking Conflicts::        Marking conflicts.
2076*75f6d617Schristos* Bypassing ed::             Generating merged output directly.
2077*75f6d617Schristos* Merging Incomplete Lines:: How `diff3' merges incomplete lines.
2078*75f6d617Schristos* Saving the Changed File::  Emulating System V behavior.
2079*75f6d617Schristos
2080*75f6d617Schristos
2081*75f6d617SchristosFile: diff.info,  Node: Which Changes,  Next: Marking Conflicts,  Up: diff3 Merging
2082*75f6d617Schristos
2083*75f6d617SchristosSelecting Which Changes to Incorporate
2084*75f6d617Schristos======================================
2085*75f6d617Schristos
2086*75f6d617Schristos   You can select all unmerged changes from OLDER to YOURS for merging
2087*75f6d617Schristosinto MINE with the `-e' or `--ed' option.  You can select only the
2088*75f6d617Schristosnonoverlapping unmerged changes with `-3' or `--easy-only', and you can
2089*75f6d617Schristosselect only the overlapping changes with `-x' or `--overlap-only'.
2090*75f6d617Schristos
2091*75f6d617Schristos   The `-e', `-3' and `-x' options select only "unmerged changes", i.e.
2092*75f6d617Schristoschanges where MINE and YOURS differ; they ignore changes from OLDER to
2093*75f6d617SchristosYOURS where MINE and YOURS are identical, because they assume that such
2094*75f6d617Schristoschanges have already been merged.  If this assumption is not a safe
2095*75f6d617Schristosone, you can use the `-A' or `--show-all' option (*note Marking
2096*75f6d617SchristosConflicts::).
2097*75f6d617Schristos
2098*75f6d617Schristos   Here is the output of the command `diff3' with each of these three
2099*75f6d617Schristosoptions (*note Sample diff3 Input::, for the complete contents of the
2100*75f6d617Schristosfiles).  Notice that `-e' outputs the union of the disjoint sets of
2101*75f6d617Schristoschanges output by `-3' and `-x'.
2102*75f6d617Schristos
2103*75f6d617Schristos   Output of `diff3 -e lao tzu tao':
2104*75f6d617Schristos     11a
2105*75f6d617Schristos
2106*75f6d617Schristos       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2107*75f6d617Schristos     .
2108*75f6d617Schristos     8c
2109*75f6d617Schristos       so we may see their result.
2110*75f6d617Schristos     .
2111*75f6d617Schristos
2112*75f6d617Schristos   Output of `diff3 -3 lao tzu tao':
2113*75f6d617Schristos     8c
2114*75f6d617Schristos       so we may see their result.
2115*75f6d617Schristos     .
2116*75f6d617Schristos
2117*75f6d617Schristos   Output of `diff3 -x lao tzu tao':
2118*75f6d617Schristos     11a
2119*75f6d617Schristos
2120*75f6d617Schristos       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2121*75f6d617Schristos     .
2122*75f6d617Schristos
2123*75f6d617Schristos
2124*75f6d617SchristosFile: diff.info,  Node: Marking Conflicts,  Next: Bypassing ed,  Prev: Which Changes,  Up: diff3 Merging
2125*75f6d617Schristos
2126*75f6d617SchristosMarking Conflicts
2127*75f6d617Schristos=================
2128*75f6d617Schristos
2129*75f6d617Schristos   `diff3' can mark conflicts in the merged output by bracketing them
2130*75f6d617Schristoswith special marker lines.  A conflict that comes from two files A and
2131*75f6d617SchristosB is marked as follows:
2132*75f6d617Schristos
2133*75f6d617Schristos     <<<<<<< A
2134*75f6d617Schristos     lines from A
2135*75f6d617Schristos     =======
2136*75f6d617Schristos     lines from B
2137*75f6d617Schristos     >>>>>>> B
2138*75f6d617Schristos
2139*75f6d617Schristos   A conflict that comes from three files A, B and C is marked as
2140*75f6d617Schristosfollows:
2141*75f6d617Schristos
2142*75f6d617Schristos     <<<<<<< A
2143*75f6d617Schristos     lines from A
2144*75f6d617Schristos     ||||||| B
2145*75f6d617Schristos     lines from B
2146*75f6d617Schristos     =======
2147*75f6d617Schristos     lines from C
2148*75f6d617Schristos     >>>>>>> C
2149*75f6d617Schristos
2150*75f6d617Schristos   The `-A' or `--show-all' option acts like the `-e' option, except
2151*75f6d617Schristosthat it brackets conflicts, and it outputs all changes from OLDER to
2152*75f6d617SchristosYOURS, not just the unmerged changes.  Thus, given the sample input
2153*75f6d617Schristosfiles (*note Sample diff3 Input::), `diff3 -A lao tzu tao' puts
2154*75f6d617Schristosbrackets around the conflict where only `tzu' differs:
2155*75f6d617Schristos
2156*75f6d617Schristos     <<<<<<< tzu
2157*75f6d617Schristos     =======
2158*75f6d617Schristos     The Way that can be told of is not the eternal Way;
2159*75f6d617Schristos     The name that can be named is not the eternal name.
2160*75f6d617Schristos     >>>>>>> tao
2161*75f6d617Schristos
2162*75f6d617Schristos   And it outputs the three-way conflict as follows:
2163*75f6d617Schristos
2164*75f6d617Schristos     <<<<<<< lao
2165*75f6d617Schristos     ||||||| tzu
2166*75f6d617Schristos     They both may be called deep and profound.
2167*75f6d617Schristos     Deeper and more profound,
2168*75f6d617Schristos     The door of all subtleties!
2169*75f6d617Schristos     =======
2170*75f6d617Schristos
2171*75f6d617Schristos       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2172*75f6d617Schristos     >>>>>>> tao
2173*75f6d617Schristos
2174*75f6d617Schristos   The `-E' or `--show-overlap' option outputs less information than
2175*75f6d617Schristosthe `-A' or `--show-all' option, because it outputs only unmerged
2176*75f6d617Schristoschanges, and it never outputs the contents of the second file.  Thus
2177*75f6d617Schristosthe `-E' option acts like the `-e' option, except that it brackets the
2178*75f6d617Schristosfirst and third files from three-way overlapping changes.  Similarly,
2179*75f6d617Schristos`-X' acts like `-x', except it brackets all its (necessarily
2180*75f6d617Schristosoverlapping) changes.  For example, for the three-way overlapping
2181*75f6d617Schristoschange above, the `-E' and `-X' options output the following:
2182*75f6d617Schristos
2183*75f6d617Schristos     <<<<<<< lao
2184*75f6d617Schristos     =======
2185*75f6d617Schristos
2186*75f6d617Schristos       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2187*75f6d617Schristos     >>>>>>> tao
2188*75f6d617Schristos
2189*75f6d617Schristos   If you are comparing files that have meaningless or uninformative
2190*75f6d617Schristosnames, you can use the `-L LABEL' or `--label=LABEL' option to show
2191*75f6d617Schristosalternate names in the `<<<<<<<', `|||||||' and `>>>>>>>' brackets.
2192*75f6d617SchristosThis option can be given up to three times, once for each input file.
2193*75f6d617SchristosThus `diff3 -A -L X -L Y -L Z A B C' acts like `diff3 -A A B C', except
2194*75f6d617Schristosthat the output looks like it came from files named `X', `Y' and `Z'
2195*75f6d617Schristosrather than from files named `A', `B' and `C'.
2196*75f6d617Schristos
2197*75f6d617Schristos
2198*75f6d617SchristosFile: diff.info,  Node: Bypassing ed,  Next: Merging Incomplete Lines,  Prev: Marking Conflicts,  Up: diff3 Merging
2199*75f6d617Schristos
2200*75f6d617SchristosGenerating the Merged Output Directly
2201*75f6d617Schristos=====================================
2202*75f6d617Schristos
2203*75f6d617Schristos   With the `-m' or `--merge' option, `diff3' outputs the merged file
2204*75f6d617Schristosdirectly.  This is more efficient than using `ed' to generate it, and
2205*75f6d617Schristosworks even with non-text files that `ed' would reject.  If you specify
2206*75f6d617Schristos`-m' without an `ed' script option, `-A' (`--show-all') is assumed.
2207*75f6d617Schristos
2208*75f6d617Schristos   For example, the command `diff3 -m lao tzu tao' (*note Sample diff3
2209*75f6d617SchristosInput:: for a copy of the input files) would output the following:
2210*75f6d617Schristos
2211*75f6d617Schristos     <<<<<<< tzu
2212*75f6d617Schristos     =======
2213*75f6d617Schristos     The Way that can be told of is not the eternal Way;
2214*75f6d617Schristos     The name that can be named is not the eternal name.
2215*75f6d617Schristos     >>>>>>> tao
2216*75f6d617Schristos     The Nameless is the origin of Heaven and Earth;
2217*75f6d617Schristos     The Named is the mother of all things.
2218*75f6d617Schristos     Therefore let there always be non-being,
2219*75f6d617Schristos       so we may see their subtlety,
2220*75f6d617Schristos     And let there always be being,
2221*75f6d617Schristos       so we may see their result.
2222*75f6d617Schristos     The two are the same,
2223*75f6d617Schristos     But after they are produced,
2224*75f6d617Schristos       they have different names.
2225*75f6d617Schristos     <<<<<<< lao
2226*75f6d617Schristos     ||||||| tzu
2227*75f6d617Schristos     They both may be called deep and profound.
2228*75f6d617Schristos     Deeper and more profound,
2229*75f6d617Schristos     The door of all subtleties!
2230*75f6d617Schristos     =======
2231*75f6d617Schristos
2232*75f6d617Schristos       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2233*75f6d617Schristos     >>>>>>> tao
2234*75f6d617Schristos
2235*75f6d617Schristos
2236*75f6d617SchristosFile: diff.info,  Node: Merging Incomplete Lines,  Next: Saving the Changed File,  Prev: Bypassing ed,  Up: diff3 Merging
2237*75f6d617Schristos
2238*75f6d617SchristosHow `diff3' Merges Incomplete Lines
2239*75f6d617Schristos===================================
2240*75f6d617Schristos
2241*75f6d617Schristos   With `-m', incomplete lines (*note Incomplete Lines::) are simply
2242*75f6d617Schristoscopied to the output as they are found; if the merged output ends in an
2243*75f6d617Schristosconflict and one of the input files ends in an incomplete line,
2244*75f6d617Schristossucceeding `|||||||', `=======' or `>>>>>>>' brackets appear somewhere
2245*75f6d617Schristosother than the start of a line because they are appended to the
2246*75f6d617Schristosincomplete line.
2247*75f6d617Schristos
2248*75f6d617Schristos   Without `-m', if an `ed' script option is specified and an
2249*75f6d617Schristosincomplete line is found, `diff3' generates a warning and acts as if a
2250*75f6d617Schristosnewline had been present.
2251*75f6d617Schristos
2252*75f6d617Schristos
2253*75f6d617SchristosFile: diff.info,  Node: Saving the Changed File,  Prev: Merging Incomplete Lines,  Up: diff3 Merging
2254*75f6d617Schristos
2255*75f6d617SchristosSaving the Changed File
2256*75f6d617Schristos=======================
2257*75f6d617Schristos
2258*75f6d617Schristos   Traditional Unix `diff3' generates an `ed' script without the
2259*75f6d617Schristostrailing `w' and `q' commands that save the changes.  System V `diff3'
2260*75f6d617Schristosgenerates these extra commands.  GNU `diff3' normally behaves like
2261*75f6d617Schristostraditional Unix `diff3', but with the `-i' option it behaves like
2262*75f6d617SchristosSystem V `diff3' and appends the `w' and `q' commands.
2263*75f6d617Schristos
2264*75f6d617Schristos   The `-i' option requires one of the `ed' script options `-AeExX3',
2265*75f6d617Schristosand is incompatible with the merged output option `-m'.
2266*75f6d617Schristos
2267*75f6d617Schristos
2268*75f6d617SchristosFile: diff.info,  Node: Interactive Merging,  Next: Merging with patch,  Prev: diff3 Merging,  Up: Top
2269*75f6d617Schristos
2270*75f6d617SchristosInteractive Merging with `sdiff'
2271*75f6d617Schristos********************************
2272*75f6d617Schristos
2273*75f6d617Schristos   With `sdiff', you can merge two files interactively based on a
2274*75f6d617Schristosside-by-side `-y' format comparison (*note Side by Side::).  Use `-o
2275*75f6d617SchristosFILE' or `--output=FILE' to specify where to put the merged text.
2276*75f6d617Schristos*Note Invoking sdiff::, for more details on the options to `sdiff'.
2277*75f6d617Schristos
2278*75f6d617Schristos   Another way to merge files interactively is to use the Emacs Lisp
2279*75f6d617Schristospackage `emerge'.  *Note emerge: (emacs)emerge, for more information.
2280*75f6d617Schristos
2281*75f6d617Schristos* Menu:
2282*75f6d617Schristos
2283*75f6d617Schristos* sdiff Option Summary:: Summary of `sdiff' options.
2284*75f6d617Schristos* Merge Commands::       Merging two files interactively.
2285*75f6d617Schristos
2286*75f6d617Schristos
2287*75f6d617SchristosFile: diff.info,  Node: sdiff Option Summary,  Next: Merge Commands,  Up: Interactive Merging
2288*75f6d617Schristos
2289*75f6d617SchristosSpecifying `diff' Options to `sdiff'
2290*75f6d617Schristos====================================
2291*75f6d617Schristos
2292*75f6d617Schristos   The following `sdiff' options have the same meaning as for `diff'.
2293*75f6d617Schristos*Note diff Options::, for the use of these options.
2294*75f6d617Schristos
2295*75f6d617Schristos     -a -b -d -i -t -v
2296*75f6d617Schristos     -B -E -I REGEXP
2297*75f6d617Schristos
2298*75f6d617Schristos     --ignore-blank-lines  --ignore-case
2299*75f6d617Schristos     --ignore-matching-lines=REGEXP  --ignore-space-change
2300*75f6d617Schristos     --ignore-tab-expansion
2301*75f6d617Schristos     --left-column  --minimal  --speed-large-files
2302*75f6d617Schristos     --strip-trailing-cr  --suppress-common-lines  --expand-tabs
2303*75f6d617Schristos     --text  --version  --width=COLUMNS
2304*75f6d617Schristos
2305*75f6d617Schristos   For historical reasons, `sdiff' has alternate names for some
2306*75f6d617Schristosoptions.  The `-l' option is equivalent to the `--left-column' option,
2307*75f6d617Schristosand similarly `-s' is equivalent to `--suppress-common-lines'.  The
2308*75f6d617Schristosmeaning of the `sdiff' `-w' and `-W' options is interchanged from that
2309*75f6d617Schristosof `diff': with `sdiff', `-w COLUMNS' is equivalent to
2310*75f6d617Schristos`--width=COLUMNS', and `-W' is equivalent to `--ignore-all-space'.
2311*75f6d617Schristos`sdiff' without the `-o' option is equivalent to `diff' with the `-y'
2312*75f6d617Schristosor `--side-by-side' option (*note Side by Side::).
2313*75f6d617Schristos
2314*75f6d617Schristos
2315*75f6d617SchristosFile: diff.info,  Node: Merge Commands,  Prev: sdiff Option Summary,  Up: Interactive Merging
2316*75f6d617Schristos
2317*75f6d617SchristosMerge Commands
2318*75f6d617Schristos==============
2319*75f6d617Schristos
2320*75f6d617Schristos   Groups of common lines, with a blank gutter, are copied from the
2321*75f6d617Schristosfirst file to the output.  After each group of differing lines, `sdiff'
2322*75f6d617Schristosprompts with `%' and pauses, waiting for one of the following commands.
2323*75f6d617SchristosFollow each command with <RET>.
2324*75f6d617Schristos
2325*75f6d617Schristos`e'
2326*75f6d617Schristos     Discard both versions.  Invoke a text editor on an empty temporary
2327*75f6d617Schristos     file, then copy the resulting file to the output.
2328*75f6d617Schristos
2329*75f6d617Schristos`eb'
2330*75f6d617Schristos     Concatenate the two versions, edit the result in a temporary file,
2331*75f6d617Schristos     then copy the edited result to the output.
2332*75f6d617Schristos
2333*75f6d617Schristos`ed'
2334*75f6d617Schristos     Like `eb', except precede each version with a header that shows
2335*75f6d617Schristos     what file and lines the version came from.
2336*75f6d617Schristos
2337*75f6d617Schristos`el'
2338*75f6d617Schristos     Edit a copy of the left version, then copy the result to the
2339*75f6d617Schristos     output.
2340*75f6d617Schristos
2341*75f6d617Schristos`er'
2342*75f6d617Schristos     Edit a copy of the right version, then copy the result to the
2343*75f6d617Schristos     output.
2344*75f6d617Schristos
2345*75f6d617Schristos`l'
2346*75f6d617Schristos     Copy the left version to the output.
2347*75f6d617Schristos
2348*75f6d617Schristos`q'
2349*75f6d617Schristos     Quit.
2350*75f6d617Schristos
2351*75f6d617Schristos`r'
2352*75f6d617Schristos     Copy the right version to the output.
2353*75f6d617Schristos
2354*75f6d617Schristos`s'
2355*75f6d617Schristos     Silently copy common lines.
2356*75f6d617Schristos
2357*75f6d617Schristos`v'
2358*75f6d617Schristos     Verbosely copy common lines.  This is the default.
2359*75f6d617Schristos
2360*75f6d617Schristos   The text editor invoked is specified by the `EDITOR' environment
2361*75f6d617Schristosvariable if it is set.  The default is system-dependent.
2362*75f6d617Schristos
2363*75f6d617Schristos
2364*75f6d617SchristosFile: diff.info,  Node: Merging with patch,  Next: Making Patches,  Prev: Interactive Merging,  Up: Top
2365*75f6d617Schristos
2366*75f6d617SchristosMerging with `patch'
2367*75f6d617Schristos********************
2368*75f6d617Schristos
2369*75f6d617Schristos   `patch' takes comparison output produced by `diff' and applies the
2370*75f6d617Schristosdifferences to a copy of the original file, producing a patched
2371*75f6d617Schristosversion.  With `patch', you can distribute just the changes to a set of
2372*75f6d617Schristosfiles instead of distributing the entire file set; your correspondents
2373*75f6d617Schristoscan apply `patch' to update their copy of the files with your changes.
2374*75f6d617Schristos`patch' automatically determines the diff format, skips any leading or
2375*75f6d617Schristostrailing headers, and uses the headers to determine which file to
2376*75f6d617Schristospatch.  This lets your correspondents feed a mail message containing a
2377*75f6d617Schristosdifference listing directly to `patch'.
2378*75f6d617Schristos
2379*75f6d617Schristos   `patch' detects and warns about common problems like forward
2380*75f6d617Schristospatches.  It saves any patches that it could not apply.  It can also
2381*75f6d617Schristosmaintain a `patchlevel.h' file to ensure that your correspondents apply
2382*75f6d617Schristosdiffs in the proper order.
2383*75f6d617Schristos
2384*75f6d617Schristos   `patch' accepts a series of diffs in its standard input, usually
2385*75f6d617Schristosseparated by headers that specify which file to patch.  It applies
2386*75f6d617Schristos`diff' hunks (*note Hunks::) one by one.  If a hunk does not exactly
2387*75f6d617Schristosmatch the original file, `patch' uses heuristics to try to patch the
2388*75f6d617Schristosfile as well as it can.  If no approximate match can be found, `patch'
2389*75f6d617Schristosrejects the hunk and skips to the next hunk.  `patch' normally replaces
2390*75f6d617Schristoseach file F with its new version, putting reject hunks (if any) into
2391*75f6d617Schristos`F.rej'.
2392*75f6d617Schristos
2393*75f6d617Schristos   *Note Invoking patch::, for detailed information on the options to
2394*75f6d617Schristos`patch'.
2395*75f6d617Schristos
2396*75f6d617Schristos* Menu:
2397*75f6d617Schristos
2398*75f6d617Schristos* patch Input::            Selecting the type of `patch' input.
2399*75f6d617Schristos* Revision Control::       Getting files from RCS, SCCS, etc.
2400*75f6d617Schristos* Imperfect::              Dealing with imperfect patches.
2401*75f6d617Schristos* Creating and Removing::  Creating and removing files with a patch.
2402*75f6d617Schristos* Patching Time Stamps::   Updating time stamps on patched files.
2403*75f6d617Schristos* Multiple Patches::       Handling multiple patches in a file.
2404*75f6d617Schristos* patch Directories::      Changing directory and stripping directories.
2405*75f6d617Schristos* Backups::                Whether backup files are made.
2406*75f6d617Schristos* Backup Names::           Backup file names.
2407*75f6d617Schristos* Reject Names::           Reject file names.
2408*75f6d617Schristos* patch Messages::         Messages and questions `patch' can produce.
2409*75f6d617Schristos* patch and POSIX::        Conformance to the POSIX standard.
2410*75f6d617Schristos* patch and Tradition::    GNU versus traditional `patch'.
2411*75f6d617Schristos
2412*75f6d617Schristos
2413*75f6d617SchristosFile: diff.info,  Node: patch Input,  Next: Revision Control,  Up: Merging with patch
2414*75f6d617Schristos
2415*75f6d617SchristosSelecting the `patch' Input Format
2416*75f6d617Schristos==================================
2417*75f6d617Schristos
2418*75f6d617Schristos   `patch' normally determines which `diff' format the patch file uses
2419*75f6d617Schristosby examining its contents.  For patch files that contain particularly
2420*75f6d617Schristosconfusing leading text, you might need to use one of the following
2421*75f6d617Schristosoptions to force `patch' to interpret the patch file as a certain
2422*75f6d617Schristosformat of diff.  The output formats listed here are the only ones that
2423*75f6d617Schristos`patch' can understand.
2424*75f6d617Schristos
2425*75f6d617Schristos`-c'
2426*75f6d617Schristos`--context'
2427*75f6d617Schristos     context diff.
2428*75f6d617Schristos
2429*75f6d617Schristos`-e'
2430*75f6d617Schristos`--ed'
2431*75f6d617Schristos     `ed' script.
2432*75f6d617Schristos
2433*75f6d617Schristos`-n'
2434*75f6d617Schristos`--normal'
2435*75f6d617Schristos     normal diff.
2436*75f6d617Schristos
2437*75f6d617Schristos`-u'
2438*75f6d617Schristos`--unified'
2439*75f6d617Schristos     unified diff.
2440*75f6d617Schristos
2441*75f6d617Schristos
2442*75f6d617SchristosFile: diff.info,  Node: Revision Control,  Next: Imperfect,  Prev: patch Input,  Up: Merging with patch
2443*75f6d617Schristos
2444*75f6d617SchristosRevision Control
2445*75f6d617Schristos================
2446*75f6d617Schristos
2447*75f6d617Schristos   If a nonexistent input file is under a revision control system
2448*75f6d617Schristossupported by `patch', `patch' normally asks the user whether to get (or
2449*75f6d617Schristoscheck out) the file from the revision control system.  Patch currently
2450*75f6d617Schristossupports RCS, ClearCase and SCCS.  Under RCS and SCCS, `patch' also
2451*75f6d617Schristosasks when the input file is read-only and matches the default version
2452*75f6d617Schristosin the revision control system.
2453*75f6d617Schristos
2454*75f6d617Schristos   The `-g NUM' or `--get=NUM' affects access to files under supported
2455*75f6d617Schristosrevision control systems.  If NUM is positive, `patch' gets the file
2456*75f6d617Schristoswithout asking the user; if zero, `patch' neither asks the user nor
2457*75f6d617Schristosgets the file; and if negative, `patch' asks the user before getting
2458*75f6d617Schristosthe file.  The default value of NUM is given by the value of the
2459*75f6d617Schristos`PATCH_GET' environment variable if it is set; if not, the default
2460*75f6d617Schristosvalue is zero if `patch' is conforming to POSIX, negative otherwise.
2461*75f6d617Schristos*Note patch and POSIX::.
2462*75f6d617Schristos
2463*75f6d617Schristos   The choice of revision control system is unaffected by the
2464*75f6d617Schristos`VERSION_CONTROL' environment variable (*note Backup Names::).
2465*75f6d617Schristos
2466*75f6d617Schristos
2467*75f6d617SchristosFile: diff.info,  Node: Imperfect,  Next: Creating and Removing,  Prev: Revision Control,  Up: Merging with patch
2468*75f6d617Schristos
2469*75f6d617SchristosApplying Imperfect Patches
2470*75f6d617Schristos==========================
2471*75f6d617Schristos
2472*75f6d617Schristos   `patch' tries to skip any leading text in the patch file, apply the
2473*75f6d617Schristosdiff, and then skip any trailing text.  Thus you can feed a mail
2474*75f6d617Schristosmessage directly to `patch', and it should work.  If the entire diff is
2475*75f6d617Schristosindented by a constant amount of white space, `patch' automatically
2476*75f6d617Schristosignores the indentation.  If a context diff contains trailing carriage
2477*75f6d617Schristosreturn on each line, `patch' automatically ignores the carriage return.
2478*75f6d617SchristosIf a context diff has been encapsulated by prepending `- ' to lines
2479*75f6d617Schristosbeginning with `-' as per Internet RFC 934
2480*75f6d617Schristos(ftp://ftp.isi.edu/in-notes/rfc934.txt), `patch' automatically
2481*75f6d617Schristosunencapsulates the input.
2482*75f6d617Schristos
2483*75f6d617Schristos   However, certain other types of imperfect input require user
2484*75f6d617Schristosintervention or testing.
2485*75f6d617Schristos
2486*75f6d617Schristos* Menu:
2487*75f6d617Schristos
2488*75f6d617Schristos* Changed White Space:: When tabs and spaces don't match exactly.
2489*75f6d617Schristos* Reversed Patches::    Applying reversed patches correctly.
2490*75f6d617Schristos* Inexact::             Helping `patch' find close matches.
2491*75f6d617Schristos* Dry Runs::            Predicting what `patch' will do.
2492*75f6d617Schristos
2493*75f6d617Schristos
2494*75f6d617SchristosFile: diff.info,  Node: Changed White Space,  Next: Reversed Patches,  Up: Imperfect
2495*75f6d617Schristos
2496*75f6d617SchristosApplying Patches with Changed White Space
2497*75f6d617Schristos-----------------------------------------
2498*75f6d617Schristos
2499*75f6d617Schristos   Sometimes mailers, editors, or other programs change spaces into
2500*75f6d617Schristostabs, or vice versa.  If this happens to a patch file or an input file,
2501*75f6d617Schristosthe files might look the same, but `patch' will not be able to match
2502*75f6d617Schristosthem properly.  If this problem occurs, use the `-l' or
2503*75f6d617Schristos`--ignore-white-space' option, which makes `patch' compare blank
2504*75f6d617Schristoscharacters (i.e. spaces and tabs) loosely so that any nonempty sequence
2505*75f6d617Schristosof blanks in the patch file matches any nonempty sequence of blanks in
2506*75f6d617Schristosthe input files.  Non-blank characters must still match exactly.  Each
2507*75f6d617Schristosline of the context must still match a line in the input file.
2508*75f6d617Schristos
2509*75f6d617Schristos
2510*75f6d617SchristosFile: diff.info,  Node: Reversed Patches,  Next: Inexact,  Prev: Changed White Space,  Up: Imperfect
2511*75f6d617Schristos
2512*75f6d617SchristosApplying Reversed Patches
2513*75f6d617Schristos-------------------------
2514*75f6d617Schristos
2515*75f6d617Schristos   Sometimes people run `diff' with the new file first instead of
2516*75f6d617Schristossecond.  This creates a diff that is "reversed".  To apply such
2517*75f6d617Schristospatches, give `patch' the `-R' or `--reverse' option.  `patch' then
2518*75f6d617Schristosattempts to swap each hunk around before applying it.  Rejects come out
2519*75f6d617Schristosin the swapped format.
2520*75f6d617Schristos
2521*75f6d617Schristos   Often `patch' can guess that the patch is reversed.  If the first
2522*75f6d617Schristoshunk of a patch fails, `patch' reverses the hunk to see if it can apply
2523*75f6d617Schristosit that way.  If it can, `patch' asks you if you want to have the `-R'
2524*75f6d617Schristosoption set; if it can't, `patch' continues to apply the patch normally.
2525*75f6d617SchristosThis method cannot detect a reversed patch if it is a normal diff and
2526*75f6d617Schristosthe first command is an append (which should have been a delete) since
2527*75f6d617Schristosappends always succeed, because a null context matches anywhere.  But
2528*75f6d617Schristosmost patches add or change lines rather than delete them, so most
2529*75f6d617Schristosreversed normal diffs begin with a delete, which fails, and `patch'
2530*75f6d617Schristosnotices.
2531*75f6d617Schristos
2532*75f6d617Schristos   If you apply a patch that you have already applied, `patch' thinks
2533*75f6d617Schristosit is a reversed patch and offers to un-apply the patch.  This could be
2534*75f6d617Schristosconstrued as a feature.  If you did this inadvertently and you don't
2535*75f6d617Schristoswant to un-apply the patch, just answer `n' to this offer and to the
2536*75f6d617Schristossubsequent "apply anyway" question--or type `C-c' to kill the `patch'
2537*75f6d617Schristosprocess.
2538*75f6d617Schristos
2539*75f6d617Schristos
2540*75f6d617SchristosFile: diff.info,  Node: Inexact,  Next: Dry Runs,  Prev: Reversed Patches,  Up: Imperfect
2541*75f6d617Schristos
2542*75f6d617SchristosHelping `patch' Find Inexact Matches
2543*75f6d617Schristos------------------------------------
2544*75f6d617Schristos
2545*75f6d617Schristos   For context diffs, and to a lesser extent normal diffs, `patch' can
2546*75f6d617Schristosdetect when the line numbers mentioned in the patch are incorrect, and
2547*75f6d617Schristosit attempts to find the correct place to apply each hunk of the patch.
2548*75f6d617SchristosAs a first guess, it takes the line number mentioned in the hunk, plus
2549*75f6d617Schristosor minus any offset used in applying the previous hunk.  If that is not
2550*75f6d617Schristosthe correct place, `patch' scans both forward and backward for a set of
2551*75f6d617Schristoslines matching the context given in the hunk.
2552*75f6d617Schristos
2553*75f6d617Schristos   First `patch' looks for a place where all lines of the context
2554*75f6d617Schristosmatch.  If it cannot find such a place, and it is reading a context or
2555*75f6d617Schristosunified diff, and the maximum fuzz factor is set to 1 or more, then
2556*75f6d617Schristos`patch' makes another scan, ignoring the first and last line of
2557*75f6d617Schristoscontext.  If that fails, and the maximum fuzz factor is set to 2 or
2558*75f6d617Schristosmore, it makes another scan, ignoring the first two and last two lines
2559*75f6d617Schristosof context are ignored.  It continues similarly if the maximum fuzz
2560*75f6d617Schristosfactor is larger.
2561*75f6d617Schristos
2562*75f6d617Schristos   The `-F LINES' or `--fuzz=LINES' option sets the maximum fuzz factor
2563*75f6d617Schristosto LINES.  This option only applies to context and unified diffs; it
2564*75f6d617Schristosignores up to LINES lines while looking for the place to install a
2565*75f6d617Schristoshunk.  Note that a larger fuzz factor increases the odds of making a
2566*75f6d617Schristosfaulty patch.  The default fuzz factor is 2; there is no point to
2567*75f6d617Schristossetting it to more than the number of lines of context in the diff,
2568*75f6d617Schristosordinarily 3.
2569*75f6d617Schristos
2570*75f6d617Schristos   If `patch' cannot find a place to install a hunk of the patch, it
2571*75f6d617Schristoswrites the hunk out to a reject file (*note Reject Names::, for
2572*75f6d617Schristosinformation on how reject files are named).  It writes out rejected
2573*75f6d617Schristoshunks in context format no matter what form the input patch is in.  If
2574*75f6d617Schristosthe input is a normal or `ed' diff, many of the contexts are simply
2575*75f6d617Schristosnull.  The line numbers on the hunks in the reject file may be
2576*75f6d617Schristosdifferent from those in the patch file: they show the approximate
2577*75f6d617Schristoslocation where `patch' thinks the failed hunks belong in the new file
2578*75f6d617Schristosrather than in the old one.
2579*75f6d617Schristos
2580*75f6d617Schristos   If the `--verbose' option is given, then as it completes each hunk
2581*75f6d617Schristos`patch' tells you whether the hunk succeeded or failed, and if it
2582*75f6d617Schristosfailed, on which line (in the new file) `patch' thinks the hunk should
2583*75f6d617Schristosgo.  If this is different from the line number specified in the diff,
2584*75f6d617Schristosit tells you the offset.  A single large offset _may_ indicate that
2585*75f6d617Schristos`patch' installed a hunk in the wrong place.  `patch' also tells you if
2586*75f6d617Schristosit used a fuzz factor to make the match, in which case you should also
2587*75f6d617Schristosbe slightly suspicious.
2588*75f6d617Schristos
2589*75f6d617Schristos   `patch' cannot tell if the line numbers are off in an `ed' script,
2590*75f6d617Schristosand can only detect wrong line numbers in a normal diff when it finds a
2591*75f6d617Schristoschange or delete command.  It may have the same problem with a context
2592*75f6d617Schristosdiff using a fuzz factor equal to or greater than the number of lines
2593*75f6d617Schristosof context shown in the diff (typically 3).  In these cases, you should
2594*75f6d617Schristosprobably look at a context diff between your original and patched input
2595*75f6d617Schristosfiles to see if the changes make sense.  Compiling without errors is a
2596*75f6d617Schristospretty good indication that the patch worked, but not a guarantee.
2597*75f6d617Schristos
2598*75f6d617Schristos   A patch against an empty file applies to a nonexistent file, and vice
2599*75f6d617Schristosversa.  *Note Creating and Removing::.
2600*75f6d617Schristos
2601*75f6d617Schristos   `patch' usually produces the correct results, even when it must make
2602*75f6d617Schristosmany guesses.  However, the results are guaranteed only when the patch
2603*75f6d617Schristosis applied to an exact copy of the file that the patch was generated
2604*75f6d617Schristosfrom.
2605*75f6d617Schristos
2606*75f6d617Schristos
2607*75f6d617SchristosFile: diff.info,  Node: Dry Runs,  Prev: Inexact,  Up: Imperfect
2608*75f6d617Schristos
2609*75f6d617SchristosPredicting what `patch' will do
2610*75f6d617Schristos-------------------------------
2611*75f6d617Schristos
2612*75f6d617Schristos   It may not be obvious in advance what `patch' will do with a
2613*75f6d617Schristoscomplicated or poorly formatted patch.  If you are concerned that the
2614*75f6d617Schristosinput might cause `patch' to modify the wrong files, you can use the
2615*75f6d617Schristos`--dry-run' option, which causes `patch' to print the results of
2616*75f6d617Schristosapplying patches without actually changing any files.  You can then
2617*75f6d617Schristosinspect the diagnostics generated by the dry run to see whether `patch'
2618*75f6d617Schristoswill modify the files that you expect.  If the patch does not do what
2619*75f6d617Schristosyou want, you can modify the patch (or the other options to `patch')
2620*75f6d617Schristosand try another dry run.  Once you are satisfied with the proposed
2621*75f6d617Schristospatch you can apply it by invoking `patch' as before, but this time
2622*75f6d617Schristoswithout the `--dry-run' option.
2623*75f6d617Schristos
2624*75f6d617Schristos
2625*75f6d617SchristosFile: diff.info,  Node: Creating and Removing,  Next: Patching Time Stamps,  Prev: Imperfect,  Up: Merging with patch
2626*75f6d617Schristos
2627*75f6d617SchristosCreating and Removing Files
2628*75f6d617Schristos===========================
2629*75f6d617Schristos
2630*75f6d617Schristos   Sometimes when comparing two directories, a file may exist in one
2631*75f6d617Schristosdirectory but not the other.  If you give `diff' the `-N' or
2632*75f6d617Schristos`--new-file' option, or if you supply an old or new file that is named
2633*75f6d617Schristos`/dev/null' or is empty and is dated the Epoch (1970-01-01 00:00:00
2634*75f6d617SchristosUTC), `diff' outputs a patch that adds or deletes the contents of this
2635*75f6d617Schristosfile.  When given such a patch, `patch' normally creates a new file or
2636*75f6d617Schristosremoves the old file.  However, when conforming to POSIX (*note patch
2637*75f6d617Schristosand POSIX::), `patch' does not remove the old file, but leaves it empty.
2638*75f6d617SchristosThe `-E' or `--remove-empty-files' option causes `patch' to remove
2639*75f6d617Schristosoutput files that are empty after applying a patch, even if the patch
2640*75f6d617Schristosdoes not appear to be one that removed the file.
2641*75f6d617Schristos
2642*75f6d617Schristos   If the patch appears to create a file that already exists, `patch'
2643*75f6d617Schristosasks for confirmation before applying the patch.
2644*75f6d617Schristos
2645*75f6d617Schristos
2646*75f6d617SchristosFile: diff.info,  Node: Patching Time Stamps,  Next: Multiple Patches,  Prev: Creating and Removing,  Up: Merging with patch
2647*75f6d617Schristos
2648*75f6d617SchristosUpdating Time Stamps on Patched Files
2649*75f6d617Schristos=====================================
2650*75f6d617Schristos
2651*75f6d617Schristos   When `patch' updates a file, it normally sets the file's
2652*75f6d617Schristoslast-modified time stamp to the current time of day.  If you are using
2653*75f6d617Schristos`patch' to track a software distribution, this can cause `make' to
2654*75f6d617Schristosincorrectly conclude that a patched file is out of date.  For example,
2655*75f6d617Schristosif `syntax.c' depends on `syntax.y', and `patch' updates `syntax.c' and
2656*75f6d617Schristosthen `syntax.y', then `syntax.c' will normally appear to be out of date
2657*75f6d617Schristoswith respect to `syntax.y' even though its contents are actually up to
2658*75f6d617Schristosdate.
2659*75f6d617Schristos
2660*75f6d617Schristos   The `-Z' or `--set-utc' option causes `patch' to set a patched
2661*75f6d617Schristosfile's modification and access times to the time stamps given in
2662*75f6d617Schristoscontext diff headers.  If the context diff headers do not specify a
2663*75f6d617Schristostime zone, they are assumed to use Coordinated Universal Time (UTC,
2664*75f6d617Schristosoften known as GMT).
2665*75f6d617Schristos
2666*75f6d617Schristos   The `-T' or `--set-time' option acts like `-Z' or `--set-utc',
2667*75f6d617Schristosexcept that it assumes that the context diff headers' time stamps use
2668*75f6d617Schristoslocal time instead of UTC.  This option is not recommended, because
2669*75f6d617Schristospatches using local time cannot easily be used by people in other time
2670*75f6d617Schristoszones, and because local time stamps are ambiguous when local clocks
2671*75f6d617Schristosmove backwards during daylight-saving time adjustments.  If the context
2672*75f6d617Schristosdiff headers specify a time zone, this option is equivalent to `-Z' or
2673*75f6d617Schristos`--set-utc'.
2674*75f6d617Schristos
2675*75f6d617Schristos   `patch' normally refrains from setting a file's time stamps if the
2676*75f6d617Schristosfile's original last-modified time stamp does not match the time given
2677*75f6d617Schristosin the diff header, of if the file's contents do not exactly match the
2678*75f6d617Schristospatch.  However, if the `-f' or `--force' option is given, the file's
2679*75f6d617Schristostime stamps are set regardless.
2680*75f6d617Schristos
2681*75f6d617Schristos   Due to the limitations of the current `diff' format, `patch' cannot
2682*75f6d617Schristosupdate the times of files whose contents have not changed.  Also, if
2683*75f6d617Schristosyou set file time stamps to values other than the current time of day,
2684*75f6d617Schristosyou should also remove (e.g., with `make clean') all files that depend
2685*75f6d617Schristoson the patched files, so that later invocations of `make' do not get
2686*75f6d617Schristosconfused by the patched files' times.
2687*75f6d617Schristos
2688*75f6d617Schristos
2689*75f6d617SchristosFile: diff.info,  Node: Multiple Patches,  Next: patch Directories,  Prev: Patching Time Stamps,  Up: Merging with patch
2690*75f6d617Schristos
2691*75f6d617SchristosMultiple Patches in a File
2692*75f6d617Schristos==========================
2693*75f6d617Schristos
2694*75f6d617Schristos   If the patch file contains more than one patch, and if you do not
2695*75f6d617Schristosspecify an input file on the command line, `patch' tries to apply each
2696*75f6d617Schristospatch as if they came from separate patch files.  This means that it
2697*75f6d617Schristosdetermines the name of the file to patch for each patch, and that it
2698*75f6d617Schristosexamines the leading text before each patch for file names and
2699*75f6d617Schristosprerequisite revision level (*note Making Patches::, for more on that
2700*75f6d617Schristostopic).
2701*75f6d617Schristos
2702*75f6d617Schristos   `patch' uses the following rules to intuit a file name from the
2703*75f6d617Schristosleading text before a patch.  First, `patch' takes an ordered list of
2704*75f6d617Schristoscandidate file names as follows:
2705*75f6d617Schristos
2706*75f6d617Schristos   * If the header is that of a context diff, `patch' takes the old and
2707*75f6d617Schristos     new file names in the header.  A name is ignored if it does not
2708*75f6d617Schristos     have enough slashes to satisfy the `-pNUM' or `--strip=NUM'
2709*75f6d617Schristos     option.  The name `/dev/null' is also ignored.
2710*75f6d617Schristos
2711*75f6d617Schristos   * If there is an `Index:' line in the leading garbage and if either
2712*75f6d617Schristos     the old and new names are both absent or if `patch' is conforming
2713*75f6d617Schristos     to POSIX, `patch' takes the name in the `Index:' line.
2714*75f6d617Schristos
2715*75f6d617Schristos   * For the purpose of the following rules, the candidate file names
2716*75f6d617Schristos     are considered to be in the order (old, new, index), regardless of
2717*75f6d617Schristos     the order that they appear in the header.
2718*75f6d617Schristos
2719*75f6d617SchristosThen `patch' selects a file name from the candidate list as follows:
2720*75f6d617Schristos
2721*75f6d617Schristos   * If some of the named files exist, `patch' selects the first name
2722*75f6d617Schristos     if conforming to POSIX, and the best name otherwise.
2723*75f6d617Schristos
2724*75f6d617Schristos   * If `patch' is not ignoring RCS, ClearCase, and SCCS (*note
2725*75f6d617Schristos     Revision Control::), and no named files exist but an RCS,
2726*75f6d617Schristos     ClearCase, or SCCS master is found, `patch' selects the first
2727*75f6d617Schristos     named file with an RCS, ClearCase, or SCCS master.
2728*75f6d617Schristos
2729*75f6d617Schristos   * If no named files exist, no RCS, ClearCase, or SCCS master was
2730*75f6d617Schristos     found, some names are given, `patch' is not conforming to POSIX,
2731*75f6d617Schristos     and the patch appears to create a file, `patch' selects the best
2732*75f6d617Schristos     name requiring the creation of the fewest directories.
2733*75f6d617Schristos
2734*75f6d617Schristos   * If no file name results from the above heuristics, you are asked
2735*75f6d617Schristos     for the name of the file to patch, and `patch' selects that name.
2736*75f6d617Schristos
2737*75f6d617Schristos   To determine the "best" of a nonempty list of file names, `patch'
2738*75f6d617Schristosfirst takes all the names with the fewest path name components; of
2739*75f6d617Schristosthose, it then takes all the names with the shortest basename; of
2740*75f6d617Schristosthose, it then takes all the shortest names; finally, it takes the
2741*75f6d617Schristosfirst remaining name.
2742*75f6d617Schristos
2743*75f6d617Schristos   *Note patch and POSIX::, to see whether `patch' is conforming to
2744*75f6d617SchristosPOSIX.
2745*75f6d617Schristos
2746*75f6d617Schristos
2747*75f6d617SchristosFile: diff.info,  Node: patch Directories,  Next: Backups,  Prev: Multiple Patches,  Up: Merging with patch
2748*75f6d617Schristos
2749*75f6d617SchristosApplying Patches in Other Directories
2750*75f6d617Schristos=====================================
2751*75f6d617Schristos
2752*75f6d617Schristos   The `-d DIRECTORY' or `--directory=DIRECTORY' option to `patch'
2753*75f6d617Schristosmakes directory DIRECTORY the current directory for interpreting both
2754*75f6d617Schristosfile names in the patch file, and file names given as arguments to
2755*75f6d617Schristosother options (such as `-B' and `-o').  For example, while in a mail
2756*75f6d617Schristosreading program, you can patch a file in the `/usr/src/emacs' directory
2757*75f6d617Schristosdirectly from a message containing the patch like this:
2758*75f6d617Schristos
2759*75f6d617Schristos     | patch -d /usr/src/emacs
2760*75f6d617Schristos
2761*75f6d617Schristos   Sometimes the file names given in a patch contain leading
2762*75f6d617Schristosdirectories, but you keep your files in a directory different from the
2763*75f6d617Schristosone given in the patch.  In those cases, you can use the `-pNUMBER' or
2764*75f6d617Schristos`--strip=NUMBER' option to set the file name strip count to NUMBER.
2765*75f6d617SchristosThe strip count tells `patch' how many slashes, along with the directory
2766*75f6d617Schristosnames between them, to strip from the front of file names.  A sequence
2767*75f6d617Schristosof one or more adjacent slashes is counted as a single slash.  By
2768*75f6d617Schristosdefault, `patch' strips off all leading directories, leaving just the
2769*75f6d617Schristosbase file names.
2770*75f6d617Schristos
2771*75f6d617Schristos   For example, suppose the file name in the patch file is
2772*75f6d617Schristos`/gnu/src/emacs/etc/NEWS'.  Using `-p0' gives the entire file name
2773*75f6d617Schristosunmodified, `-p1' gives `gnu/src/emacs/etc/NEWS' (no leading slash),
2774*75f6d617Schristos`-p4' gives `etc/NEWS', and not specifying `-p' at all gives `NEWS'.
2775*75f6d617Schristos
2776*75f6d617Schristos   `patch' looks for each file (after any slashes have been stripped)
2777*75f6d617Schristosin the current directory, or if you used the `-d DIRECTORY' option, in
2778*75f6d617Schristosthat directory.
2779*75f6d617Schristos
2780*75f6d617Schristos
2781*75f6d617SchristosFile: diff.info,  Node: Backups,  Next: Backup Names,  Prev: patch Directories,  Up: Merging with patch
2782*75f6d617Schristos
2783*75f6d617SchristosBackup Files
2784*75f6d617Schristos============
2785*75f6d617Schristos
2786*75f6d617Schristos   Normally, `patch' creates a backup file if the patch does not
2787*75f6d617Schristosexactly match the original input file, because in that case the
2788*75f6d617Schristosoriginal data might not be recovered if you undo the patch with `patch
2789*75f6d617Schristos-R' (*note Reversed Patches::).  However, when conforming to POSIX,
2790*75f6d617Schristos`patch' does not create backup files by default.  *Note patch and
2791*75f6d617SchristosPOSIX::.
2792*75f6d617Schristos
2793*75f6d617Schristos   The `-b' or `--backup' option causes `patch' to make a backup file
2794*75f6d617Schristosregardless of whether the patch matches the original input.  The
2795*75f6d617Schristos`--backup-if-mismatch' option causes `patch' to create backup files for
2796*75f6d617Schristosmismatches files; this is the default when not conforming to POSIX.  The
2797*75f6d617Schristos`--no-backup-if-mismatch' option causes `patch' to not create backup
2798*75f6d617Schristosfiles, even for mismatched patches; this is the default when conforming
2799*75f6d617Schristosto POSIX.
2800*75f6d617Schristos
2801*75f6d617Schristos   When backing up a file that does not exist, an empty, unreadable
2802*75f6d617Schristosbackup file is created as a placeholder to represent the nonexistent
2803*75f6d617Schristosfile.
2804*75f6d617Schristos
2805*75f6d617Schristos
2806*75f6d617SchristosFile: diff.info,  Node: Backup Names,  Next: Reject Names,  Prev: Backups,  Up: Merging with patch
2807*75f6d617Schristos
2808*75f6d617SchristosBackup File Names
2809*75f6d617Schristos=================
2810*75f6d617Schristos
2811*75f6d617Schristos   Normally, `patch' renames an original input file into a backup file
2812*75f6d617Schristosby appending to its name the extension `.orig', or `~' if using `.orig'
2813*75f6d617Schristoswould make the backup file name too long.(1)  The `-z BACKUP-SUFFIX' or
2814*75f6d617Schristos`--suffix=BACKUP-SUFFIX' option causes `patch' to use BACKUP-SUFFIX as
2815*75f6d617Schristosthe backup extension instead.
2816*75f6d617Schristos
2817*75f6d617Schristos   Alternately, you can specify the extension for backup files with the
2818*75f6d617Schristos`SIMPLE_BACKUP_SUFFIX' environment variable, which the options override.
2819*75f6d617Schristos
2820*75f6d617Schristos   `patch' can also create numbered backup files the way GNU Emacs
2821*75f6d617Schristosdoes.  With this method, instead of having a single backup of each file,
2822*75f6d617Schristos`patch' makes a new backup file name each time it patches a file.  For
2823*75f6d617Schristosexample, the backups of a file named `sink' would be called,
2824*75f6d617Schristossuccessively, `sink.~1~', `sink.~2~', `sink.~3~', etc.
2825*75f6d617Schristos
2826*75f6d617Schristos   The `-V BACKUP-STYLE' or `--version-control=BACKUP-STYLE' option
2827*75f6d617Schristostakes as an argument a method for creating backup file names.  You can
2828*75f6d617Schristosalternately control the type of backups that `patch' makes with the
2829*75f6d617Schristos`PATCH_VERSION_CONTROL' environment variable, which the `-V' option
2830*75f6d617Schristosoverrides.  If `PATCH_VERSION_CONTROL' is not set, the
2831*75f6d617Schristos`VERSION_CONTROL' environment variable is used instead.  Please note
2832*75f6d617Schristosthat these options and variables control backup file names; they do not
2833*75f6d617Schristosaffect the choice of revision control system (*note Revision Control::).
2834*75f6d617Schristos
2835*75f6d617Schristos   The values of these environment variables and the argument to the
2836*75f6d617Schristos`-V' option are like the GNU Emacs `version-control' variable (*note
2837*75f6d617SchristosBackup Names: (emacs)Backup Names., for more information on backup
2838*75f6d617Schristosversions in Emacs).  They also recognize synonyms that are more
2839*75f6d617Schristosdescriptive.  The valid values are listed below; unique abbreviations
2840*75f6d617Schristosare acceptable.
2841*75f6d617Schristos
2842*75f6d617Schristos`t'
2843*75f6d617Schristos`numbered'
2844*75f6d617Schristos     Always make numbered backups.
2845*75f6d617Schristos
2846*75f6d617Schristos`nil'
2847*75f6d617Schristos`existing'
2848*75f6d617Schristos     Make numbered backups of files that already have them, simple
2849*75f6d617Schristos     backups of the others.  This is the default.
2850*75f6d617Schristos
2851*75f6d617Schristos`never'
2852*75f6d617Schristos`simple'
2853*75f6d617Schristos     Always make simple backups.
2854*75f6d617Schristos
2855*75f6d617Schristos   You can also tell `patch' to prepend a prefix, such as a directory
2856*75f6d617Schristosname, to produce backup file names.  The `-B PREFIX' or
2857*75f6d617Schristos`--prefix=PREFIX' option makes backup files by prepending PREFIX to
2858*75f6d617Schristosthem.  The `-Y PREFIX' or `--basename-prefix=PREFIX' prepends PREFIX to
2859*75f6d617Schristosthe last file name component of backup file names instead; for example,
2860*75f6d617Schristos`-Y ~' causes the backup name for `dir/file.c' to be `dir/~file.c'.  If
2861*75f6d617Schristosyou use either of these prefix options, the suffix-based options are
2862*75f6d617Schristosignored.
2863*75f6d617Schristos
2864*75f6d617Schristos   If you specify the output file with the `-o' option, that file is
2865*75f6d617Schristosthe one that is backed up, not the input file.
2866*75f6d617Schristos
2867*75f6d617Schristos   Options that affect the names of backup files do not affect whether
2868*75f6d617Schristosbackups are made.  For example, if you specify the
2869*75f6d617Schristos`--no-backup-if-mismatch' option, none of the options described in this
2870*75f6d617Schristossection have any affect, because no backups are made.
2871*75f6d617Schristos
2872*75f6d617Schristos   ---------- Footnotes ----------
2873*75f6d617Schristos
2874*75f6d617Schristos   (1) A coding error in GNU `patch' version 2.5.4 causes it to always
2875*75f6d617Schristosuse `~', but this should be fixed in the next release.
2876*75f6d617Schristos
2877*75f6d617Schristos
2878*75f6d617SchristosFile: diff.info,  Node: Reject Names,  Next: patch Messages,  Prev: Backup Names,  Up: Merging with patch
2879*75f6d617Schristos
2880*75f6d617SchristosReject File Names
2881*75f6d617Schristos=================
2882*75f6d617Schristos
2883*75f6d617Schristos   The names for reject files (files containing patches that `patch'
2884*75f6d617Schristoscould not find a place to apply) are normally the name of the output
2885*75f6d617Schristosfile with `.rej' appended (or `#' if if using `.rej' would make the
2886*75f6d617Schristosbackup file name too long).
2887*75f6d617Schristos
2888*75f6d617Schristos   Alternatively, you can tell `patch' to place all of the rejected
2889*75f6d617Schristospatches in a single file.  The `-r REJECT-FILE' or
2890*75f6d617Schristos`--reject-file=REJECT-FILE' option uses REJECT-FILE as the reject file
2891*75f6d617Schristosname.
2892*75f6d617Schristos
2893*75f6d617Schristos
2894*75f6d617SchristosFile: diff.info,  Node: patch Messages,  Next: patch and POSIX,  Prev: Reject Names,  Up: Merging with patch
2895*75f6d617Schristos
2896*75f6d617SchristosMessages and Questions from `patch'
2897*75f6d617Schristos===================================
2898*75f6d617Schristos
2899*75f6d617Schristos   `patch' can produce a variety of messages, especially if it has
2900*75f6d617Schristostrouble decoding its input.  In a few situations where it's not sure
2901*75f6d617Schristoshow to proceed, `patch' normally prompts you for more information from
2902*75f6d617Schristosthe keyboard.  There are options to produce more or fewer messages, to
2903*75f6d617Schristoshave it not ask for keyboard input, and to affect the way that file
2904*75f6d617Schristosnames are quoted in messages.
2905*75f6d617Schristos
2906*75f6d617Schristos* Menu:
2907*75f6d617Schristos
2908*75f6d617Schristos* More or Fewer Messages::    Controlling the verbosity of `patch'.
2909*75f6d617Schristos* patch and Keyboard Input::  Inhibiting keyboard input.
2910*75f6d617Schristos* patch Quoting Style::       Quoting file names in diagnostics.
2911*75f6d617Schristos
2912*75f6d617Schristos   `patch' exits with status 0 if all hunks are applied successfully, 1
2913*75f6d617Schristosif some hunks cannot be applied, and 2 if there is more serious trouble.
2914*75f6d617SchristosWhen applying a set of patches in a loop, you should check the exit
2915*75f6d617Schristosstatus, so you don't apply a later patch to a partially patched file.
2916*75f6d617Schristos
2917*75f6d617Schristos
2918*75f6d617SchristosFile: diff.info,  Node: More or Fewer Messages,  Next: patch and Keyboard Input,  Up: patch Messages
2919*75f6d617Schristos
2920*75f6d617SchristosControlling the Verbosity of `patch'
2921*75f6d617Schristos------------------------------------
2922*75f6d617Schristos
2923*75f6d617Schristos   You can cause `patch' to produce more messages by using the
2924*75f6d617Schristos`--verbose' option.  For example, when you give this option, the
2925*75f6d617Schristosmessage `Hmm...' indicates that `patch' is reading text in the patch
2926*75f6d617Schristosfile, attempting to determine whether there is a patch in that text,
2927*75f6d617Schristosand if so, what kind of patch it is.
2928*75f6d617Schristos
2929*75f6d617Schristos   You can inhibit all terminal output from `patch', unless an error
2930*75f6d617Schristosoccurs, by using the `-s', `--quiet', or `--silent' option.
2931*75f6d617Schristos
2932*75f6d617Schristos
2933*75f6d617SchristosFile: diff.info,  Node: patch and Keyboard Input,  Next: patch Quoting Style,  Prev: More or Fewer Messages,  Up: patch Messages
2934*75f6d617Schristos
2935*75f6d617SchristosInhibiting Keyboard Input
2936*75f6d617Schristos-------------------------
2937*75f6d617Schristos
2938*75f6d617Schristos   There are two ways you can prevent `patch' from asking you any
2939*75f6d617Schristosquestions.  The `-f' or `--force' option assumes that you know what you
2940*75f6d617Schristosare doing.  It causes `patch' to do the following:
2941*75f6d617Schristos
2942*75f6d617Schristos   * Skip patches that do not contain file names in their headers.
2943*75f6d617Schristos
2944*75f6d617Schristos   * Patch files even though they have the wrong version for the
2945*75f6d617Schristos     `Prereq:' line in the patch;
2946*75f6d617Schristos
2947*75f6d617Schristos   * Assume that patches are not reversed even if they look like they
2948*75f6d617Schristos     are.
2949*75f6d617Schristos
2950*75f6d617SchristosThe `-t' or `--batch' option is similar to `-f', in that it suppresses
2951*75f6d617Schristosquestions, but it makes somewhat different assumptions:
2952*75f6d617Schristos
2953*75f6d617Schristos   * Skip patches that do not contain file names in their headers (the
2954*75f6d617Schristos     same as `-f').
2955*75f6d617Schristos
2956*75f6d617Schristos   * Skip patches for which the file has the wrong version for the
2957*75f6d617Schristos     `Prereq:' line in the patch;
2958*75f6d617Schristos
2959*75f6d617Schristos   * Assume that patches are reversed if they look like they are.
2960*75f6d617Schristos
2961*75f6d617Schristos
2962*75f6d617SchristosFile: diff.info,  Node: patch Quoting Style,  Prev: patch and Keyboard Input,  Up: patch Messages
2963*75f6d617Schristos
2964*75f6d617Schristos`patch' Quoting Style
2965*75f6d617Schristos---------------------
2966*75f6d617Schristos
2967*75f6d617Schristos   When `patch' outputs a file name in a diagnostic message, it can
2968*75f6d617Schristosformat the name in any of several ways.  This can be useful to output
2969*75f6d617Schristosfile names unambiguously, even if they contain punctuation or special
2970*75f6d617Schristoscharacters like newlines.  The `--quoting-style=WORD' option controls
2971*75f6d617Schristoshow names are output.  The WORD should be one of the following:
2972*75f6d617Schristos
2973*75f6d617Schristos`literal'
2974*75f6d617Schristos     Output names as-is.
2975*75f6d617Schristos
2976*75f6d617Schristos`shell'
2977*75f6d617Schristos     Quote names for the shell if they contain shell metacharacters or
2978*75f6d617Schristos     would cause ambiguous output.
2979*75f6d617Schristos
2980*75f6d617Schristos`shell-always'
2981*75f6d617Schristos     Quote names for the shell, even if they would normally not require
2982*75f6d617Schristos     quoting.
2983*75f6d617Schristos
2984*75f6d617Schristos`c'
2985*75f6d617Schristos     Quote names as for a C language string.
2986*75f6d617Schristos
2987*75f6d617Schristos`escape'
2988*75f6d617Schristos     Quote as with `c' except omit the surrounding double-quote
2989*75f6d617Schristos     characters.
2990*75f6d617Schristos
2991*75f6d617Schristos   You can specify the default value of the `--quoting-style' option
2992*75f6d617Schristoswith the environment variable `QUOTING_STYLE'.  If that environment
2993*75f6d617Schristosvariable is not set, the default value is `shell', but this default may
2994*75f6d617Schristoschange in a future version of `patch'.
2995*75f6d617Schristos
2996*75f6d617Schristos
2997*75f6d617SchristosFile: diff.info,  Node: patch and POSIX,  Next: patch and Tradition,  Prev: patch Messages,  Up: Merging with patch
2998*75f6d617Schristos
2999*75f6d617Schristos`patch' and the POSIX Standard
3000*75f6d617Schristos==============================
3001*75f6d617Schristos
3002*75f6d617Schristos   If you specify the `--posix' option, or set the `POSIXLY_CORRECT'
3003*75f6d617Schristosenvironment variable, `patch' conforms more strictly to the POSIX
3004*75f6d617Schristosstandard, as follows:
3005*75f6d617Schristos
3006*75f6d617Schristos   * Take the first existing file from the list (old, new, index) when
3007*75f6d617Schristos     intuiting file names from diff headers.  *Note Multiple Patches::.
3008*75f6d617Schristos
3009*75f6d617Schristos   * Do not remove files that are removed by a diff.  *Note Creating
3010*75f6d617Schristos     and Removing::.
3011*75f6d617Schristos
3012*75f6d617Schristos   * Do not ask whether to get files from RCS, ClearCase, or SCCS.
3013*75f6d617Schristos     *Note Revision Control::.
3014*75f6d617Schristos
3015*75f6d617Schristos   * Require that all options precede the files in the command line.
3016*75f6d617Schristos
3017*75f6d617Schristos   * Do not backup files, even when there is a mismatch.  *Note
3018*75f6d617Schristos     Backups::.
3019*75f6d617Schristos
3020*75f6d617Schristos
3021*75f6d617Schristos
3022*75f6d617SchristosFile: diff.info,  Node: patch and Tradition,  Prev: patch and POSIX,  Up: Merging with patch
3023*75f6d617Schristos
3024*75f6d617SchristosGNU `patch' and Traditional `patch'
3025*75f6d617Schristos===================================
3026*75f6d617Schristos
3027*75f6d617Schristos   The current version of GNU `patch' normally follows the POSIX
3028*75f6d617Schristosstandard.  *Note patch and POSIX::, for the few exceptions to this
3029*75f6d617Schristosgeneral rule.
3030*75f6d617Schristos
3031*75f6d617Schristos   Unfortunately, POSIX redefined the behavior of `patch' in several
3032*75f6d617Schristosimportant ways.  You should be aware of the following differences if
3033*75f6d617Schristosyou must interoperate with traditional `patch', or with GNU `patch'
3034*75f6d617Schristosversion 2.1 and earlier.
3035*75f6d617Schristos
3036*75f6d617Schristos   * In traditional `patch', the `-p' option's operand was optional,
3037*75f6d617Schristos     and a bare `-p' was equivalent to `-p0'.  The `-p' option now
3038*75f6d617Schristos     requires an operand, and `-p 0' is now equivalent to `-p0'.  For
3039*75f6d617Schristos     maximum compatibility, use options like `-p0' and `-p1'.
3040*75f6d617Schristos
3041*75f6d617Schristos     Also, traditional `patch' simply counted slashes when stripping
3042*75f6d617Schristos     path prefixes; `patch' now counts pathname components.  That is, a
3043*75f6d617Schristos     sequence of one or more adjacent slashes now counts as a single
3044*75f6d617Schristos     slash.  For maximum portability, avoid sending patches containing
3045*75f6d617Schristos     `//' in file names.
3046*75f6d617Schristos
3047*75f6d617Schristos   * In traditional `patch', backups were enabled by default.  This
3048*75f6d617Schristos     behavior is now enabled with the `-b' or `--backup' option.
3049*75f6d617Schristos
3050*75f6d617Schristos     Conversely, in POSIX `patch', backups are never made, even when
3051*75f6d617Schristos     there is a mismatch.  In GNU `patch', this behavior is enabled
3052*75f6d617Schristos     with the `--no-backup-if-mismatch' option, or by conforming to
3053*75f6d617Schristos     POSIX.
3054*75f6d617Schristos
3055*75f6d617Schristos     The `-b SUFFIX' option of traditional `patch' is equivalent to the
3056*75f6d617Schristos     `-b -z SUFFIX' options of GNU `patch'.
3057*75f6d617Schristos
3058*75f6d617Schristos   * Traditional `patch' used a complicated (and incompletely
3059*75f6d617Schristos     documented) method to intuit the name of the file to be patched
3060*75f6d617Schristos     from the patch header.  This method did not conform to POSIX, and
3061*75f6d617Schristos     had a few gotchas.  Now `patch' uses a different, equally
3062*75f6d617Schristos     complicated (but better documented) method that is optionally
3063*75f6d617Schristos     POSIX-conforming; we hope it has fewer gotchas.  The two methods
3064*75f6d617Schristos     are compatible if the file names in the context diff header and the
3065*75f6d617Schristos     `Index:' line are all identical after prefix-stripping.  Your
3066*75f6d617Schristos     patch is normally compatible if each header's file names all
3067*75f6d617Schristos     contain the same number of slashes.
3068*75f6d617Schristos
3069*75f6d617Schristos   * When traditional `patch' asked the user a question, it sent the
3070*75f6d617Schristos     question to standard error and looked for an answer from the first
3071*75f6d617Schristos     file in the following list that was a terminal: standard error,
3072*75f6d617Schristos     standard output, `/dev/tty', and standard input.  Now `patch'
3073*75f6d617Schristos     sends questions to standard output and gets answers from
3074*75f6d617Schristos     `/dev/tty'.  Defaults for some answers have been changed so that
3075*75f6d617Schristos     `patch' never goes into an infinite loop when using default
3076*75f6d617Schristos     answers.
3077*75f6d617Schristos
3078*75f6d617Schristos   * Traditional `patch' exited with a status value that counted the
3079*75f6d617Schristos     number of bad hunks, or with status 1 if there was real trouble.
3080*75f6d617Schristos     Now `patch' exits with status 1 if some hunks failed, or with 2 if
3081*75f6d617Schristos     there was real trouble.
3082*75f6d617Schristos
3083*75f6d617Schristos   * Limit yourself to the following options when sending instructions
3084*75f6d617Schristos     meant to be executed by anyone running GNU `patch', traditional
3085*75f6d617Schristos     `patch', or a `patch' that conforms to POSIX.  Spaces are
3086*75f6d617Schristos     significant in the following list, and operands are required.
3087*75f6d617Schristos
3088*75f6d617Schristos          `-c'
3089*75f6d617Schristos          `-d DIR'
3090*75f6d617Schristos          `-D DEFINE'
3091*75f6d617Schristos          `-e'
3092*75f6d617Schristos          `-l'
3093*75f6d617Schristos          `-n'
3094*75f6d617Schristos          `-N'
3095*75f6d617Schristos          `-o OUTFILE'
3096*75f6d617Schristos          `-pNUM'
3097*75f6d617Schristos          `-R'
3098*75f6d617Schristos          `-r REJECTFILE'
3099*75f6d617Schristos
3100*75f6d617Schristos
3101*75f6d617Schristos
3102*75f6d617SchristosFile: diff.info,  Node: Making Patches,  Next: Invoking cmp,  Prev: Merging with patch,  Up: Top
3103*75f6d617Schristos
3104*75f6d617SchristosTips for Making and Using Patches
3105*75f6d617Schristos*********************************
3106*75f6d617Schristos
3107*75f6d617Schristos   Use some common sense when making and using patches.  For example,
3108*75f6d617Schristoswhen sending bug fixes to a program's maintainer, send several small
3109*75f6d617Schristospatches, one per independent subject, instead of one large,
3110*75f6d617Schristosharder-to-digest patch that covers all the subjects.
3111*75f6d617Schristos
3112*75f6d617Schristos   Here are some other things you should keep in mind if you are going
3113*75f6d617Schristosto distribute patches for updating a software package.
3114*75f6d617Schristos
3115*75f6d617Schristos* Menu:
3116*75f6d617Schristos
3117*75f6d617Schristos* Tips for Patch Producers::    Advice for making patches.
3118*75f6d617Schristos* Tips for Patch Consumers::    Advice for using patches.
3119*75f6d617Schristos* Avoiding Common Mistakes::    Avoiding common mistakes when using `patch'.
3120*75f6d617Schristos* Generating Smaller Patches::  How to generate smaller patches.
3121*75f6d617Schristos
3122*75f6d617Schristos
3123*75f6d617SchristosFile: diff.info,  Node: Tips for Patch Producers,  Next: Tips for Patch Consumers,  Up: Making Patches
3124*75f6d617Schristos
3125*75f6d617SchristosTips for Patch Producers
3126*75f6d617Schristos========================
3127*75f6d617Schristos
3128*75f6d617Schristos   To create a patch that changes an older version of a package into a
3129*75f6d617Schristosnewer version, first make a copy of the older and newer versions in
3130*75f6d617Schristosadjacent subdirectories.  It is common to do that by unpacking `tar'
3131*75f6d617Schristosarchives of the two versions.
3132*75f6d617Schristos
3133*75f6d617Schristos   To generate the patch, use the command `diff -Naur OLD NEW' where
3134*75f6d617SchristosOLD and NEW identify the old and new directories.  The names OLD and
3135*75f6d617SchristosNEW should not contain any slashes.  The `-N' option lets the patch
3136*75f6d617Schristoscreate and remove files; `-a' lets the patch update non-text files; `-u'
3137*75f6d617Schristosgenerates useful time stamps and enough context; and `-r' lets the
3138*75f6d617Schristospatch update subdirectories.  Here is an example command, using Bourne
3139*75f6d617Schristosshell syntax:
3140*75f6d617Schristos
3141*75f6d617Schristos     diff -Naur gcc-3.0.3 gcc-3.0.4
3142*75f6d617Schristos
3143*75f6d617Schristos   Tell your recipients how to apply the patches.  This should include
3144*75f6d617Schristoswhich working directory to use, and which `patch' options to use; the
3145*75f6d617Schristosoption `-p1' is recommended.  Test your procedure by pretending to be a
3146*75f6d617Schristosrecipient and applying your patches to a copy of the original files.
3147*75f6d617Schristos
3148*75f6d617Schristos   *Note Avoiding Common Mistakes::, for how to avoid common mistakes
3149*75f6d617Schristoswhen generating a patch.
3150*75f6d617Schristos
3151*75f6d617Schristos
3152*75f6d617SchristosFile: diff.info,  Node: Tips for Patch Consumers,  Next: Avoiding Common Mistakes,  Prev: Tips for Patch Producers,  Up: Making Patches
3153*75f6d617Schristos
3154*75f6d617SchristosTips for Patch Consumers
3155*75f6d617Schristos========================
3156*75f6d617Schristos
3157*75f6d617Schristos   A patch producer should tell recipients how to apply the patches, so
3158*75f6d617Schristosthe first rule of thumb for a patch consumer is to follow the
3159*75f6d617Schristosinstructions supplied with the patch.
3160*75f6d617Schristos
3161*75f6d617Schristos   GNU `diff' can analyze files with arbitrarily long lines and files
3162*75f6d617Schristosthat end in incomplete lines.  However, older versions of `patch'
3163*75f6d617Schristoscannot patch such files.  If you are having trouble applying such
3164*75f6d617Schristospatches, try upgrading to a recent version of GNU `patch'.
3165*75f6d617Schristos
3166*75f6d617Schristos
3167*75f6d617SchristosFile: diff.info,  Node: Avoiding Common Mistakes,  Next: Generating Smaller Patches,  Prev: Tips for Patch Consumers,  Up: Making Patches
3168*75f6d617Schristos
3169*75f6d617SchristosAvoiding Common Mistakes
3170*75f6d617Schristos========================
3171*75f6d617Schristos
3172*75f6d617Schristos   When producing a patch for multiple files, apply `diff' to
3173*75f6d617Schristosdirectories whose names do not have slashes.  This reduces confusion
3174*75f6d617Schristoswhen the patch consumer specifies the `-pNUMBER' option, since this
3175*75f6d617Schristosoption can have surprising results when the old and new file names have
3176*75f6d617Schristosdifferent numbers of slashes.  For example, do not send a patch with a
3177*75f6d617Schristosheader that looks like this:
3178*75f6d617Schristos
3179*75f6d617Schristos     diff -Naur v2.0.29/prog/README prog/README
3180*75f6d617Schristos     --- v2.0.29/prog/README	2002-03-10 23:30:39.942229878 -0800
3181*75f6d617Schristos     +++ prog/README	2002-03-17 20:49:32.442260588 -0800
3182*75f6d617Schristos
3183*75f6d617Schristosbecause the two file names have different numbers of slashes, and
3184*75f6d617Schristosdifferent versions of `patch' interpret the file names differently.  To
3185*75f6d617Schristosavoid confusion, send output that looks like this instead:
3186*75f6d617Schristos
3187*75f6d617Schristos     diff -Naur v2.0.29/prog/README v2.0.30/prog/README
3188*75f6d617Schristos     --- v2.0.29/prog/README	2002-03-10 23:30:39.942229878 -0800
3189*75f6d617Schristos     +++ v2.0.30/prog/README	2002-03-17 20:49:32.442260588 -0800
3190*75f6d617Schristos
3191*75f6d617Schristos   Make sure you have specified the file names correctly, either in a
3192*75f6d617Schristoscontext diff header or with an `Index:' line.  Take care to not send out
3193*75f6d617Schristosreversed patches, since these make people wonder whether they have
3194*75f6d617Schristosalready applied the patch.
3195*75f6d617Schristos
3196*75f6d617Schristos   Avoid sending patches that compare backup file names like
3197*75f6d617Schristos`README.orig' or `README~', since this might confuse `patch' into
3198*75f6d617Schristospatching a backup file instead of the real file.  Instead, send patches
3199*75f6d617Schristosthat compare the same base file names in different directories, e.g.
3200*75f6d617Schristos`old/README' and `new/README'.
3201*75f6d617Schristos
3202*75f6d617Schristos   To save people from partially applying a patch before other patches
3203*75f6d617Schristosthat should have gone before it, you can make the first patch in the
3204*75f6d617Schristospatch file update a file with a name like `patchlevel.h' or
3205*75f6d617Schristos`version.c', which contains a patch level or version number.  If the
3206*75f6d617Schristosinput file contains the wrong version number, `patch' will complain
3207*75f6d617Schristosimmediately.
3208*75f6d617Schristos
3209*75f6d617Schristos   An even clearer way to prevent this problem is to put a `Prereq:'
3210*75f6d617Schristosline before the patch.  If the leading text in the patch file contains a
3211*75f6d617Schristosline that starts with `Prereq:', `patch' takes the next word from that
3212*75f6d617Schristosline (normally a version number) and checks whether the next input file
3213*75f6d617Schristoscontains that word, preceded and followed by either white space or a
3214*75f6d617Schristosnewline.  If not, `patch' prompts you for confirmation before
3215*75f6d617Schristosproceeding.  This makes it difficult to accidentally apply patches in
3216*75f6d617Schristosthe wrong order.
3217*75f6d617Schristos
3218*75f6d617Schristos
3219*75f6d617SchristosFile: diff.info,  Node: Generating Smaller Patches,  Prev: Avoiding Common Mistakes,  Up: Making Patches
3220*75f6d617Schristos
3221*75f6d617SchristosGenerating Smaller Patches
3222*75f6d617Schristos==========================
3223*75f6d617Schristos
3224*75f6d617Schristos   The simplest way to generate a patch is to use `diff -Naur' (*note
3225*75f6d617SchristosTips for Patch Producers::), but you might be able to reduce the size
3226*75f6d617Schristosof the patch by renaming or removing some files before making the
3227*75f6d617Schristospatch.  If the older version of the package contains any files that the
3228*75f6d617Schristosnewer version does not, or if any files have been renamed between the
3229*75f6d617Schristostwo versions, make a list of `rm' and `mv' commands for the user to
3230*75f6d617Schristosexecute in the old version directory before applying the patch.  Then
3231*75f6d617Schristosrun those commands yourself in the scratch directory.
3232*75f6d617Schristos
3233*75f6d617Schristos   If there are any files that you don't need to include in the patch
3234*75f6d617Schristosbecause they can easily be rebuilt from other files (for example,
3235*75f6d617Schristos`TAGS' and output from `yacc' and `makeinfo'), exclude them from the
3236*75f6d617Schristospatch by giving `diff' the `-x PATTERN' option (*note Comparing
3237*75f6d617SchristosDirectories::).  If you want your patch to modify a derived file
3238*75f6d617Schristosbecause your recipients lack tools to build it, make sure that the
3239*75f6d617Schristospatch for the derived file follows any patches for files that it
3240*75f6d617Schristosdepends on, so that the recipients' time stamps will not confuse `make'.
3241*75f6d617Schristos
3242*75f6d617Schristos   Now you can create the patch using `diff -Naur'.  Make sure to
3243*75f6d617Schristosspecify the scratch directory first and the newer directory second.
3244*75f6d617Schristos
3245*75f6d617Schristos   Add to the top of the patch a note telling the user any `rm' and
3246*75f6d617Schristos`mv' commands to run before applying the patch.  Then you can remove
3247*75f6d617Schristosthe scratch directory.
3248*75f6d617Schristos
3249*75f6d617Schristos   You can also shrink the patch size by using fewer lines of context,
3250*75f6d617Schristosbut bear in mind that `patch' typically needs at least two lines for
3251*75f6d617Schristosproper operation when patches do not exactly match the input files.
3252*75f6d617Schristos
3253*75f6d617Schristos
3254*75f6d617SchristosFile: diff.info,  Node: Invoking cmp,  Next: Invoking diff,  Prev: Making Patches,  Up: Top
3255*75f6d617Schristos
3256*75f6d617SchristosInvoking `cmp'
3257*75f6d617Schristos**************
3258*75f6d617Schristos
3259*75f6d617Schristos   The `cmp' command compares two files, and if they differ, tells the
3260*75f6d617Schristosfirst byte and line number where they differ.  Bytes and lines are
3261*75f6d617Schristosnumbered starting with 1.  The arguments of `cmp' are as follows:
3262*75f6d617Schristos
3263*75f6d617Schristos     cmp OPTIONS... FROM-FILE [TO-FILE [FROM-SKIP [TO-SKIP]]]
3264*75f6d617Schristos
3265*75f6d617Schristos   The file name `-' is always the standard input.  `cmp' also uses the
3266*75f6d617Schristosstandard input if one file name is omitted.  The FROM-SKIP and TO-SKIP
3267*75f6d617Schristosoperands specify how many bytes to ignore at the start of each file;
3268*75f6d617Schristosthey are equivalent to the `--ignore-initial=FROM-SKIP:TO-SKIP' option.
3269*75f6d617Schristos
3270*75f6d617Schristos   An exit status of 0 means no differences were found, 1 means some
3271*75f6d617Schristosdifferences were found, and 2 means trouble.
3272*75f6d617Schristos
3273*75f6d617Schristos* Menu:
3274*75f6d617Schristos
3275*75f6d617Schristos* cmp Options:: Summary of options to `cmp'.
3276*75f6d617Schristos
3277*75f6d617Schristos
3278*75f6d617SchristosFile: diff.info,  Node: cmp Options,  Up: Invoking cmp
3279*75f6d617Schristos
3280*75f6d617SchristosOptions to `cmp'
3281*75f6d617Schristos================
3282*75f6d617Schristos
3283*75f6d617Schristos   Below is a summary of all of the options that GNU `cmp' accepts.
3284*75f6d617SchristosMost options have two equivalent names, one of which is a single letter
3285*75f6d617Schristospreceded by `-', and the other of which is a long name preceded by
3286*75f6d617Schristos`--'.  Multiple single letter options (unless they take an argument)
3287*75f6d617Schristoscan be combined into a single command line word: `-bl' is equivalent to
3288*75f6d617Schristos`-b -l'.
3289*75f6d617Schristos
3290*75f6d617Schristos`-b'
3291*75f6d617Schristos`--print-bytes'
3292*75f6d617Schristos     Print the differing bytes.  Display control bytes as a `^'
3293*75f6d617Schristos     followed by a letter of the alphabet and precede bytes that have
3294*75f6d617Schristos     the high bit set with `M-' (which stands for "meta").
3295*75f6d617Schristos
3296*75f6d617Schristos`--help'
3297*75f6d617Schristos     Output a summary of usage and then exit.
3298*75f6d617Schristos
3299*75f6d617Schristos`-i SKIP'
3300*75f6d617Schristos`--ignore-initial=SKIP'
3301*75f6d617Schristos     Ignore any differences in the first SKIP bytes of the input files.
3302*75f6d617Schristos     Treat files with fewer than SKIP bytes as if they are empty.  If
3303*75f6d617Schristos     SKIP is of the form `FROM-SKIP:TO-SKIP', skip the first FROM-SKIP
3304*75f6d617Schristos     bytes of the first input file and the first TO-SKIP bytes of the
3305*75f6d617Schristos     second.
3306*75f6d617Schristos
3307*75f6d617Schristos`-l'
3308*75f6d617Schristos`--verbose'
3309*75f6d617Schristos     Print the (decimal) byte numbers and (octal) values of all
3310*75f6d617Schristos     differing bytes.
3311*75f6d617Schristos
3312*75f6d617Schristos`-n COUNT'
3313*75f6d617Schristos`--bytes=COUNT'
3314*75f6d617Schristos     Compare at most COUNT input bytes.
3315*75f6d617Schristos
3316*75f6d617Schristos`-s'
3317*75f6d617Schristos`--quiet'
3318*75f6d617Schristos`--silent'
3319*75f6d617Schristos     Do not print anything; only return an exit status indicating
3320*75f6d617Schristos     whether the files differ.
3321*75f6d617Schristos
3322*75f6d617Schristos`-v'
3323*75f6d617Schristos`--version'
3324*75f6d617Schristos     Output version information and then exit.
3325*75f6d617Schristos
3326*75f6d617Schristos   In the above table, operands that are byte counts are normally
3327*75f6d617Schristosdecimal, but may be preceded by `0' for octal and `0x' for hexadecimal.
3328*75f6d617Schristos
3329*75f6d617Schristos   A byte count can be followed by a suffix to specify a multiple of
3330*75f6d617Schristosthat count; in this case an omitted integer is understood to be 1.  A
3331*75f6d617Schristosbare size letter, or one followed by `iB', specifies a multiple using
3332*75f6d617Schristospowers of 1024.  A size letter followed by `B' specifies powers of 1000
3333*75f6d617Schristosinstead.  For example, `-n 4M' and `-n 4MiB' are equivalent to `-n
3334*75f6d617Schristos4194304', whereas `-n 4MB' is equivalent to `-n 4000000'.  This
3335*75f6d617Schristosnotation is upward compatible with the SI prefixes
3336*75f6d617Schristos(http://www.bipm.fr/enus/3_SI/si-prefixes.html) for decimal multiples
3337*75f6d617Schristosand with the IEC 60027-2 prefixes for binary multiples
3338*75f6d617Schristos(http://physics.nist.gov/cuu/Units/binary.html).
3339*75f6d617Schristos
3340*75f6d617Schristos   The following suffixes are defined.  Large sizes like `1Y' may be
3341*75f6d617Schristosrejected by your computer due to limitations of its arithmetic.
3342*75f6d617Schristos
3343*75f6d617Schristos`kB'
3344*75f6d617Schristos     kilobyte: 10^3 = 1000.
3345*75f6d617Schristos
3346*75f6d617Schristos`k'
3347*75f6d617Schristos`K'
3348*75f6d617Schristos`KiB'
3349*75f6d617Schristos     kibibyte: 2^10 = 1024.  `K' is special: the SI prefix is `k' and
3350*75f6d617Schristos     the IEC 60027-2 prefix is `Ki', but tradition and POSIX use `k' to
3351*75f6d617Schristos     mean `KiB'.
3352*75f6d617Schristos
3353*75f6d617Schristos`MB'
3354*75f6d617Schristos     megabyte: 10^6 = 1,000,000.
3355*75f6d617Schristos
3356*75f6d617Schristos`M'
3357*75f6d617Schristos`MiB'
3358*75f6d617Schristos     mebibyte: 2^20 = 1,048,576.
3359*75f6d617Schristos
3360*75f6d617Schristos`GB'
3361*75f6d617Schristos     gigabyte: 10^9 = 1,000,000,000.
3362*75f6d617Schristos
3363*75f6d617Schristos`G'
3364*75f6d617Schristos`GiB'
3365*75f6d617Schristos     gibibyte: 2^30 = 1,073,741,824.
3366*75f6d617Schristos
3367*75f6d617Schristos`TB'
3368*75f6d617Schristos     terabyte:  10^12 = 1,000,000,000,000.
3369*75f6d617Schristos
3370*75f6d617Schristos`T'
3371*75f6d617Schristos`TiB'
3372*75f6d617Schristos     tebibyte: 2^40 = 1,099,511,627,776.
3373*75f6d617Schristos
3374*75f6d617Schristos`PB'
3375*75f6d617Schristos     petabyte: 10^15 = 1,000,000,000,000,000.
3376*75f6d617Schristos
3377*75f6d617Schristos`P'
3378*75f6d617Schristos`PiB'
3379*75f6d617Schristos     pebibyte: 2^50 = 1,125,899,906,842,624.
3380*75f6d617Schristos
3381*75f6d617Schristos`EB'
3382*75f6d617Schristos     exabyte: 10^18 = 1,000,000,000,000,000,000.
3383*75f6d617Schristos
3384*75f6d617Schristos`E'
3385*75f6d617Schristos`EiB'
3386*75f6d617Schristos     exbibyte: 2^60 = 1,152,921,504,606,846,976.
3387*75f6d617Schristos
3388*75f6d617Schristos`ZB'
3389*75f6d617Schristos     zettabyte: 10^21 = 1,000,000,000,000,000,000,000
3390*75f6d617Schristos
3391*75f6d617Schristos`Z'
3392*75f6d617Schristos`ZiB'
3393*75f6d617Schristos     2^70 = 1,180,591,620,717,411,303,424.  (`Zi' is a GNU extension to
3394*75f6d617Schristos     IEC 60027-2.)
3395*75f6d617Schristos
3396*75f6d617Schristos`YB'
3397*75f6d617Schristos     yottabyte: 10^24 = 1,000,000,000,000,000,000,000,000.
3398*75f6d617Schristos
3399*75f6d617Schristos`Y'
3400*75f6d617Schristos`YiB'
3401*75f6d617Schristos     2^80 = 1,208,925,819,614,629,174,706,176.  (`Yi' is a GNU
3402*75f6d617Schristos     extension to IEC 60027-2.)
3403*75f6d617Schristos
3404*75f6d617Schristos
3405*75f6d617SchristosFile: diff.info,  Node: Invoking diff,  Next: Invoking diff3,  Prev: Invoking cmp,  Up: Top
3406*75f6d617Schristos
3407*75f6d617SchristosInvoking `diff'
3408*75f6d617Schristos***************
3409*75f6d617Schristos
3410*75f6d617Schristos   The format for running the `diff' command is:
3411*75f6d617Schristos
3412*75f6d617Schristos     diff OPTIONS... FILES...
3413*75f6d617Schristos
3414*75f6d617Schristos   In the simplest case, two file names FROM-FILE and TO-FILE are
3415*75f6d617Schristosgiven, and `diff' compares the contents of FROM-FILE and TO-FILE.  A
3416*75f6d617Schristosfile name of `-' stands for text read from the standard input.  As a
3417*75f6d617Schristosspecial case, `diff - -' compares a copy of standard input to itself.
3418*75f6d617Schristos
3419*75f6d617Schristos   If one file is a directory and the other is not, `diff' compares the
3420*75f6d617Schristosfile in the directory whose name is that of the non-directory.  The
3421*75f6d617Schristosnon-directory file must not be `-'.
3422*75f6d617Schristos
3423*75f6d617Schristos   If two file names are given and both are directories, `diff'
3424*75f6d617Schristoscompares corresponding files in both directories, in alphabetical
3425*75f6d617Schristosorder; this comparison is not recursive unless the `-r' or
3426*75f6d617Schristos`--recursive' option is given.  `diff' never compares the actual
3427*75f6d617Schristoscontents of a directory as if it were a file.  The file that is fully
3428*75f6d617Schristosspecified may not be standard input, because standard input is nameless
3429*75f6d617Schristosand the notion of "file with the same name" does not apply.
3430*75f6d617Schristos
3431*75f6d617Schristos   If the `--from-file=FILE' option is given, the number of file names
3432*75f6d617Schristosis arbitrary, and FILE is compared to each named file.  Similarly, if
3433*75f6d617Schristosthe `--to-file=FILE' option is given, each named file is compared to
3434*75f6d617SchristosFILE.
3435*75f6d617Schristos
3436*75f6d617Schristos   `diff' options begin with `-', so normally file names may not begin
3437*75f6d617Schristoswith `-'.  However, `--' as an argument by itself treats the remaining
3438*75f6d617Schristosarguments as file names even if they begin with `-'.
3439*75f6d617Schristos
3440*75f6d617Schristos   An exit status of 0 means no differences were found, 1 means some
3441*75f6d617Schristosdifferences were found, and 2 means trouble.
3442*75f6d617Schristos
3443*75f6d617Schristos* Menu:
3444*75f6d617Schristos
3445*75f6d617Schristos* diff Options:: Summary of options to `diff'.
3446*75f6d617Schristos
3447*75f6d617Schristos
3448*75f6d617SchristosFile: diff.info,  Node: diff Options,  Up: Invoking diff
3449*75f6d617Schristos
3450*75f6d617SchristosOptions to `diff'
3451*75f6d617Schristos=================
3452*75f6d617Schristos
3453*75f6d617Schristos   Below is a summary of all of the options that GNU `diff' accepts.
3454*75f6d617SchristosMost options have two equivalent names, one of which is a single letter
3455*75f6d617Schristospreceded by `-', and the other of which is a long name preceded by
3456*75f6d617Schristos`--'.  Multiple single letter options (unless they take an argument)
3457*75f6d617Schristoscan be combined into a single command line word: `-ac' is equivalent to
3458*75f6d617Schristos`-a -c'.  Long named options can be abbreviated to any unique prefix of
3459*75f6d617Schristostheir name.  Brackets ([ and ]) indicate that an option takes an
3460*75f6d617Schristosoptional argument.
3461*75f6d617Schristos
3462*75f6d617Schristos`-a'
3463*75f6d617Schristos`--text'
3464*75f6d617Schristos     Treat all files as text and compare them line-by-line, even if they
3465*75f6d617Schristos     do not seem to be text.  *Note Binary::.
3466*75f6d617Schristos
3467*75f6d617Schristos`-b'
3468*75f6d617Schristos`--ignore-space-change'
3469*75f6d617Schristos     Ignore changes in amount of white space.  *Note White Space::.
3470*75f6d617Schristos
3471*75f6d617Schristos`-B'
3472*75f6d617Schristos`--ignore-blank-lines'
3473*75f6d617Schristos     Ignore changes that just insert or delete blank lines.  *Note
3474*75f6d617Schristos     Blank Lines::.
3475*75f6d617Schristos
3476*75f6d617Schristos`--binary'
3477*75f6d617Schristos     Read and write data in binary mode.  *Note Binary::.
3478*75f6d617Schristos
3479*75f6d617Schristos`-c'
3480*75f6d617Schristos     Use the context output format, showing three lines of context.
3481*75f6d617Schristos     *Note Context Format::.
3482*75f6d617Schristos
3483*75f6d617Schristos`-C LINES'
3484*75f6d617Schristos`--context[=LINES]'
3485*75f6d617Schristos     Use the context output format, showing LINES (an integer) lines of
3486*75f6d617Schristos     context, or three if LINES is not given.  *Note Context Format::.
3487*75f6d617Schristos     For proper operation, `patch' typically needs at least two lines of
3488*75f6d617Schristos     context.
3489*75f6d617Schristos
3490*75f6d617Schristos     On older systems, `diff' supports an obsolete option `-LINES' that
3491*75f6d617Schristos     has effect when combined with `-c' or `-p'.  POSIX 1003.1-2001
3492*75f6d617Schristos     (*note Standards conformance::) does not allow this; use `-C LINES'
3493*75f6d617Schristos     instead.
3494*75f6d617Schristos
3495*75f6d617Schristos`--changed-group-format=FORMAT'
3496*75f6d617Schristos     Use FORMAT to output a line group containing differing lines from
3497*75f6d617Schristos     both files in if-then-else format.  *Note Line Group Formats::.
3498*75f6d617Schristos
3499*75f6d617Schristos`-d'
3500*75f6d617Schristos`--minimal'
3501*75f6d617Schristos     Change the algorithm perhaps find a smaller set of changes.  This
3502*75f6d617Schristos     makes `diff' slower (sometimes much slower).  *Note diff
3503*75f6d617Schristos     Performance::.
3504*75f6d617Schristos
3505*75f6d617Schristos`-D NAME'
3506*75f6d617Schristos`--ifdef=NAME'
3507*75f6d617Schristos     Make merged `#ifdef' format output, conditional on the preprocessor
3508*75f6d617Schristos     macro NAME.  *Note If-then-else::.
3509*75f6d617Schristos
3510*75f6d617Schristos`-e'
3511*75f6d617Schristos`--ed'
3512*75f6d617Schristos     Make output that is a valid `ed' script.  *Note ed Scripts::.
3513*75f6d617Schristos
3514*75f6d617Schristos`-E'
3515*75f6d617Schristos`--ignore-tab-expansion'
3516*75f6d617Schristos     Ignore changes due to tab expansion.  *Note White Space::.
3517*75f6d617Schristos
3518*75f6d617Schristos`-f'
3519*75f6d617Schristos`--forward-ed'
3520*75f6d617Schristos     Make output that looks vaguely like an `ed' script but has changes
3521*75f6d617Schristos     in the order they appear in the file.  *Note Forward ed::.
3522*75f6d617Schristos
3523*75f6d617Schristos`-F REGEXP'
3524*75f6d617Schristos`--show-function-line=REGEXP'
3525*75f6d617Schristos     In context and unified format, for each hunk of differences, show
3526*75f6d617Schristos     some of the last preceding line that matches REGEXP.  *Note
3527*75f6d617Schristos     Specified Headings::.
3528*75f6d617Schristos
3529*75f6d617Schristos`--from-file=FILE'
3530*75f6d617Schristos     Compare FILE to each operand; FILE may be a directory.
3531*75f6d617Schristos
3532*75f6d617Schristos`--help'
3533*75f6d617Schristos     Output a summary of usage and then exit.
3534*75f6d617Schristos
3535*75f6d617Schristos`--horizon-lines=LINES'
3536*75f6d617Schristos     Do not discard the last LINES lines of the common prefix and the
3537*75f6d617Schristos     first LINES lines of the common suffix.  *Note diff Performance::.
3538*75f6d617Schristos
3539*75f6d617Schristos`-i'
3540*75f6d617Schristos`--ignore-case'
3541*75f6d617Schristos     Ignore changes in case; consider upper- and lower-case letters
3542*75f6d617Schristos     equivalent.  *Note Case Folding::.
3543*75f6d617Schristos
3544*75f6d617Schristos`-I REGEXP'
3545*75f6d617Schristos`--ignore-matching-lines=REGEXP'
3546*75f6d617Schristos     Ignore changes that just insert or delete lines that match REGEXP.
3547*75f6d617Schristos     *Note Specified Folding::.
3548*75f6d617Schristos
3549*75f6d617Schristos`--ignore-file-name-case'
3550*75f6d617Schristos     Ignore case when comparing file names during recursive comparison.
3551*75f6d617Schristos     *Note Comparing Directories::.
3552*75f6d617Schristos
3553*75f6d617Schristos`-l'
3554*75f6d617Schristos`--paginate'
3555*75f6d617Schristos     Pass the output through `pr' to paginate it.  *Note Pagination::.
3556*75f6d617Schristos
3557*75f6d617Schristos`--label=LABEL'
3558*75f6d617Schristos     Use LABEL instead of the file name in the context format (*note
3559*75f6d617Schristos     Context Format::) and unified format (*note Unified Format::)
3560*75f6d617Schristos     headers.  *Note RCS::.
3561*75f6d617Schristos
3562*75f6d617Schristos`--left-column'
3563*75f6d617Schristos     Print only the left column of two common lines in side by side
3564*75f6d617Schristos     format.  *Note Side by Side Format::.
3565*75f6d617Schristos
3566*75f6d617Schristos`--line-format=FORMAT'
3567*75f6d617Schristos     Use FORMAT to output all input lines in if-then-else format.
3568*75f6d617Schristos     *Note Line Formats::.
3569*75f6d617Schristos
3570*75f6d617Schristos`-n'
3571*75f6d617Schristos`--rcs'
3572*75f6d617Schristos     Output RCS-format diffs; like `-f' except that each command
3573*75f6d617Schristos     specifies the number of lines affected.  *Note RCS::.
3574*75f6d617Schristos
3575*75f6d617Schristos`-N'
3576*75f6d617Schristos`--new-file'
3577*75f6d617Schristos     In directory comparison, if a file is found in only one directory,
3578*75f6d617Schristos     treat it as present but empty in the other directory.  *Note
3579*75f6d617Schristos     Comparing Directories::.
3580*75f6d617Schristos
3581*75f6d617Schristos`--new-group-format=FORMAT'
3582*75f6d617Schristos     Use FORMAT to output a group of lines taken from just the second
3583*75f6d617Schristos     file in if-then-else format.  *Note Line Group Formats::.
3584*75f6d617Schristos
3585*75f6d617Schristos`--new-line-format=FORMAT'
3586*75f6d617Schristos     Use FORMAT to output a line taken from just the second file in
3587*75f6d617Schristos     if-then-else format.  *Note Line Formats::.
3588*75f6d617Schristos
3589*75f6d617Schristos`--old-group-format=FORMAT'
3590*75f6d617Schristos     Use FORMAT to output a group of lines taken from just the first
3591*75f6d617Schristos     file in if-then-else format.  *Note Line Group Formats::.
3592*75f6d617Schristos
3593*75f6d617Schristos`--old-line-format=FORMAT'
3594*75f6d617Schristos     Use FORMAT to output a line taken from just the first file in
3595*75f6d617Schristos     if-then-else format.  *Note Line Formats::.
3596*75f6d617Schristos
3597*75f6d617Schristos`-p'
3598*75f6d617Schristos`--show-c-function'
3599*75f6d617Schristos     Show which C function each change is in.  *Note C Function
3600*75f6d617Schristos     Headings::.
3601*75f6d617Schristos
3602*75f6d617Schristos`-q'
3603*75f6d617Schristos`--brief'
3604*75f6d617Schristos     Report only whether the files differ, not the details of the
3605*75f6d617Schristos     differences.  *Note Brief::.
3606*75f6d617Schristos
3607*75f6d617Schristos`-r'
3608*75f6d617Schristos`--recursive'
3609*75f6d617Schristos     When comparing directories, recursively compare any subdirectories
3610*75f6d617Schristos     found.  *Note Comparing Directories::.
3611*75f6d617Schristos
3612*75f6d617Schristos`-s'
3613*75f6d617Schristos`--report-identical-files'
3614*75f6d617Schristos     Report when two files are the same.  *Note Comparing Directories::.
3615*75f6d617Schristos
3616*75f6d617Schristos`-S FILE'
3617*75f6d617Schristos`--starting-file=FILE'
3618*75f6d617Schristos     When comparing directories, start with the file FILE.  This is
3619*75f6d617Schristos     used for resuming an aborted comparison.  *Note Comparing
3620*75f6d617Schristos     Directories::.
3621*75f6d617Schristos
3622*75f6d617Schristos`--speed-large-files'
3623*75f6d617Schristos     Use heuristics to speed handling of large files that have numerous
3624*75f6d617Schristos     scattered small changes.  *Note diff Performance::.
3625*75f6d617Schristos
3626*75f6d617Schristos`--strip-trailing-cr'
3627*75f6d617Schristos     Strip any trailing carriage return at the end of an input line.
3628*75f6d617Schristos     *Note Binary::.
3629*75f6d617Schristos
3630*75f6d617Schristos`--suppress-common-lines'
3631*75f6d617Schristos     Do not print common lines in side by side format.  *Note Side by
3632*75f6d617Schristos     Side Format::.
3633*75f6d617Schristos
3634*75f6d617Schristos`-t'
3635*75f6d617Schristos`--expand-tabs'
3636*75f6d617Schristos     Expand tabs to spaces in the output, to preserve the alignment of
3637*75f6d617Schristos     tabs in the input files.  *Note Tabs::.
3638*75f6d617Schristos
3639*75f6d617Schristos`-T'
3640*75f6d617Schristos`--initial-tab'
3641*75f6d617Schristos     Output a tab rather than a space before the text of a line in
3642*75f6d617Schristos     normal or context format.  This causes the alignment of tabs in
3643*75f6d617Schristos     the line to look normal.  *Note Tabs::.
3644*75f6d617Schristos
3645*75f6d617Schristos`--to-file=FILE'
3646*75f6d617Schristos     Compare each operand to FILE; FILE may be a directory.
3647*75f6d617Schristos
3648*75f6d617Schristos`-u'
3649*75f6d617Schristos     Use the unified output format, showing three lines of context.
3650*75f6d617Schristos     *Note Unified Format::.
3651*75f6d617Schristos
3652*75f6d617Schristos`--unchanged-group-format=FORMAT'
3653*75f6d617Schristos     Use FORMAT to output a group of common lines taken from both files
3654*75f6d617Schristos     in if-then-else format.  *Note Line Group Formats::.
3655*75f6d617Schristos
3656*75f6d617Schristos`--unchanged-line-format=FORMAT'
3657*75f6d617Schristos     Use FORMAT to output a line common to both files in if-then-else
3658*75f6d617Schristos     format.  *Note Line Formats::.
3659*75f6d617Schristos
3660*75f6d617Schristos`--unidirectional-new-file'
3661*75f6d617Schristos     When comparing directories, if a file appears only in the second
3662*75f6d617Schristos     directory of the two, treat it as present but empty in the other.
3663*75f6d617Schristos     *Note Comparing Directories::.
3664*75f6d617Schristos
3665*75f6d617Schristos`-U LINES'
3666*75f6d617Schristos`--unified[=LINES]'
3667*75f6d617Schristos     Use the unified output format, showing LINES (an integer) lines of
3668*75f6d617Schristos     context, or three if LINES is not given.  *Note Unified Format::.
3669*75f6d617Schristos     For proper operation, `patch' typically needs at least two lines of
3670*75f6d617Schristos     context.
3671*75f6d617Schristos
3672*75f6d617Schristos     On older systems, `diff' supports an obsolete option `-LINES' that
3673*75f6d617Schristos     has effect when combined with `-u'.  POSIX 1003.1-2001 (*note
3674*75f6d617Schristos     Standards conformance::) does not allow this; use `-U LINES'
3675*75f6d617Schristos     instead.
3676*75f6d617Schristos
3677*75f6d617Schristos`-v'
3678*75f6d617Schristos`--version'
3679*75f6d617Schristos     Output version information and then exit.
3680*75f6d617Schristos
3681*75f6d617Schristos`-w'
3682*75f6d617Schristos`--ignore-all-space'
3683*75f6d617Schristos     Ignore white space when comparing lines.  *Note White Space::.
3684*75f6d617Schristos
3685*75f6d617Schristos`-W COLUMNS'
3686*75f6d617Schristos`--width=COLUMNS'
3687*75f6d617Schristos     Output at most COLUMNS (default 130) print columns per line in
3688*75f6d617Schristos     side by side format.  *Note Side by Side Format::.
3689*75f6d617Schristos
3690*75f6d617Schristos`-x PATTERN'
3691*75f6d617Schristos`--exclude=PATTERN'
3692*75f6d617Schristos     When comparing directories, ignore files and subdirectories whose
3693*75f6d617Schristos     basenames match PATTERN.  *Note Comparing Directories::.
3694*75f6d617Schristos
3695*75f6d617Schristos`-X FILE'
3696*75f6d617Schristos`--exclude-from=FILE'
3697*75f6d617Schristos     When comparing directories, ignore files and subdirectories whose
3698*75f6d617Schristos     basenames match any pattern contained in FILE.  *Note Comparing
3699*75f6d617Schristos     Directories::.
3700*75f6d617Schristos
3701*75f6d617Schristos`-y'
3702*75f6d617Schristos`--side-by-side'
3703*75f6d617Schristos     Use the side by side output format.  *Note Side by Side Format::.
3704*75f6d617Schristos
3705*75f6d617Schristos
3706*75f6d617SchristosFile: diff.info,  Node: Invoking diff3,  Next: Invoking patch,  Prev: Invoking diff,  Up: Top
3707*75f6d617Schristos
3708*75f6d617SchristosInvoking `diff3'
3709*75f6d617Schristos****************
3710*75f6d617Schristos
3711*75f6d617Schristos   The `diff3' command compares three files and outputs descriptions of
3712*75f6d617Schristostheir differences.  Its arguments are as follows:
3713*75f6d617Schristos
3714*75f6d617Schristos     diff3 OPTIONS... MINE OLDER YOURS
3715*75f6d617Schristos
3716*75f6d617Schristos   The files to compare are MINE, OLDER, and YOURS.  At most one of
3717*75f6d617Schristosthese three file names may be `-', which tells `diff3' to read the
3718*75f6d617Schristosstandard input for that file.
3719*75f6d617Schristos
3720*75f6d617Schristos   An exit status of 0 means `diff3' was successful, 1 means some
3721*75f6d617Schristosconflicts were found, and 2 means trouble.
3722*75f6d617Schristos
3723*75f6d617Schristos* Menu:
3724*75f6d617Schristos
3725*75f6d617Schristos* diff3 Options:: Summary of options to `diff3'.
3726*75f6d617Schristos
3727*75f6d617Schristos
3728*75f6d617SchristosFile: diff.info,  Node: diff3 Options,  Up: Invoking diff3
3729*75f6d617Schristos
3730*75f6d617SchristosOptions to `diff3'
3731*75f6d617Schristos==================
3732*75f6d617Schristos
3733*75f6d617Schristos   Below is a summary of all of the options that GNU `diff3' accepts.
3734*75f6d617SchristosMultiple single letter options (unless they take an argument) can be
3735*75f6d617Schristoscombined into a single command line argument.
3736*75f6d617Schristos
3737*75f6d617Schristos`-a'
3738*75f6d617Schristos`--text'
3739*75f6d617Schristos     Treat all files as text and compare them line-by-line, even if they
3740*75f6d617Schristos     do not appear to be text.  *Note Binary::.
3741*75f6d617Schristos
3742*75f6d617Schristos`-A'
3743*75f6d617Schristos`--show-all'
3744*75f6d617Schristos     Incorporate all unmerged changes from OLDER to YOURS into MINE,
3745*75f6d617Schristos     surrounding conflicts with bracket lines.  *Note Marking
3746*75f6d617Schristos     Conflicts::.
3747*75f6d617Schristos
3748*75f6d617Schristos`--diff-program=PROGRAM'
3749*75f6d617Schristos     Use the compatible comparison program PROGRAM to compare files
3750*75f6d617Schristos     instead of `diff'.
3751*75f6d617Schristos
3752*75f6d617Schristos`-e'
3753*75f6d617Schristos`--ed'
3754*75f6d617Schristos     Generate an `ed' script that incorporates all the changes from
3755*75f6d617Schristos     OLDER to YOURS into MINE.  *Note Which Changes::.
3756*75f6d617Schristos
3757*75f6d617Schristos`-E'
3758*75f6d617Schristos`--show-overlap'
3759*75f6d617Schristos     Like `-e', except bracket lines from overlapping changes' first
3760*75f6d617Schristos     and third files.  *Note Marking Conflicts::.  With `-E', an
3761*75f6d617Schristos     overlapping change looks like this:
3762*75f6d617Schristos
3763*75f6d617Schristos          <<<<<<< MINE
3764*75f6d617Schristos          lines from MINE
3765*75f6d617Schristos          =======
3766*75f6d617Schristos          lines from YOURS
3767*75f6d617Schristos          >>>>>>> YOURS
3768*75f6d617Schristos
3769*75f6d617Schristos`--help'
3770*75f6d617Schristos     Output a summary of usage and then exit.
3771*75f6d617Schristos
3772*75f6d617Schristos`-i'
3773*75f6d617Schristos     Generate `w' and `q' commands at the end of the `ed' script for
3774*75f6d617Schristos     System V compatibility.  This option must be combined with one of
3775*75f6d617Schristos     the `-AeExX3' options, and may not be combined with `-m'.  *Note
3776*75f6d617Schristos     Saving the Changed File::.
3777*75f6d617Schristos
3778*75f6d617Schristos`-L LABEL'
3779*75f6d617Schristos`--label=LABEL'
3780*75f6d617Schristos     Use the label LABEL for the brackets output by the `-A', `-E' and
3781*75f6d617Schristos     `-X' options.  This option may be given up to three times, one for
3782*75f6d617Schristos     each input file.  The default labels are the names of the input
3783*75f6d617Schristos     files.  Thus `diff3 -L X -L Y -L Z -m A B C' acts like `diff3 -m A
3784*75f6d617Schristos     B C', except that the output looks like it came from files named
3785*75f6d617Schristos     `X', `Y' and `Z' rather than from files named `A', `B' and `C'.
3786*75f6d617Schristos     *Note Marking Conflicts::.
3787*75f6d617Schristos
3788*75f6d617Schristos`-m'
3789*75f6d617Schristos`--merge'
3790*75f6d617Schristos     Apply the edit script to the first file and send the result to
3791*75f6d617Schristos     standard output.  Unlike piping the output from `diff3' to `ed',
3792*75f6d617Schristos     this works even for binary files and incomplete lines.  `-A' is
3793*75f6d617Schristos     assumed if no edit script option is specified.  *Note Bypassing
3794*75f6d617Schristos     ed::.
3795*75f6d617Schristos
3796*75f6d617Schristos`-T'
3797*75f6d617Schristos`--initial-tab'
3798*75f6d617Schristos     Output a tab rather than two spaces before the text of a line in
3799*75f6d617Schristos     normal format.  This causes the alignment of tabs in the line to
3800*75f6d617Schristos     look normal.  *Note Tabs::.
3801*75f6d617Schristos
3802*75f6d617Schristos`-v'
3803*75f6d617Schristos`--version'
3804*75f6d617Schristos     Output version information and then exit.
3805*75f6d617Schristos
3806*75f6d617Schristos`-x'
3807*75f6d617Schristos`--overlap-only'
3808*75f6d617Schristos     Like `-e', except output only the overlapping changes.  *Note
3809*75f6d617Schristos     Which Changes::.
3810*75f6d617Schristos
3811*75f6d617Schristos`-X'
3812*75f6d617Schristos     Like `-E', except output only the overlapping changes.  In other
3813*75f6d617Schristos     words, like `-x', except bracket changes as in `-E'.  *Note
3814*75f6d617Schristos     Marking Conflicts::.
3815*75f6d617Schristos
3816*75f6d617Schristos`-3'
3817*75f6d617Schristos`--easy-only'
3818*75f6d617Schristos     Like `-e', except output only the nonoverlapping changes.  *Note
3819*75f6d617Schristos     Which Changes::.
3820*75f6d617Schristos
3821*75f6d617Schristos
3822*75f6d617SchristosFile: diff.info,  Node: Invoking patch,  Next: Invoking sdiff,  Prev: Invoking diff3,  Up: Top
3823*75f6d617Schristos
3824*75f6d617SchristosInvoking `patch'
3825*75f6d617Schristos****************
3826*75f6d617Schristos
3827*75f6d617Schristos   Normally `patch' is invoked like this:
3828*75f6d617Schristos
3829*75f6d617Schristos     patch <PATCHFILE
3830*75f6d617Schristos
3831*75f6d617Schristos   The full format for invoking `patch' is:
3832*75f6d617Schristos
3833*75f6d617Schristos     patch OPTIONS... [ORIGFILE [PATCHFILE]]
3834*75f6d617Schristos
3835*75f6d617Schristos   You can also specify where to read the patch from with the `-i
3836*75f6d617SchristosPATCHFILE' or `--input=PATCHFILE' option.  If you do not specify
3837*75f6d617SchristosPATCHFILE, or if PATCHFILE is `-', `patch' reads the patch (that is,
3838*75f6d617Schristosthe `diff' output) from the standard input.
3839*75f6d617Schristos
3840*75f6d617Schristos   If you do not specify an input file on the command line, `patch'
3841*75f6d617Schristostries to intuit from the "leading text" (any text in the patch that
3842*75f6d617Schristoscomes before the `diff' output) which file to edit.  *Note Multiple
3843*75f6d617SchristosPatches::.
3844*75f6d617Schristos
3845*75f6d617Schristos   By default, `patch' replaces the original input file with the
3846*75f6d617Schristospatched version, possibly after renaming the original file into a
3847*75f6d617Schristosbackup file (*note Backup Names::, for a description of how `patch'
3848*75f6d617Schristosnames backup files).  You can also specify where to put the output with
3849*75f6d617Schristosthe `-o FILE' or `--output=FILE' option; however, do not use this option
3850*75f6d617Schristosif FILE is one of the input files.
3851*75f6d617Schristos
3852*75f6d617Schristos* Menu:
3853*75f6d617Schristos
3854*75f6d617Schristos* patch Options::     Summary table of options to `patch'.
3855*75f6d617Schristos
3856*75f6d617Schristos
3857*75f6d617SchristosFile: diff.info,  Node: patch Options,  Up: Invoking patch
3858*75f6d617Schristos
3859*75f6d617SchristosOptions to `patch'
3860*75f6d617Schristos==================
3861*75f6d617Schristos
3862*75f6d617Schristos   Here is a summary of all of the options that GNU `patch' accepts.
3863*75f6d617Schristos*Note patch and Tradition::, for which of these options are safe to use
3864*75f6d617Schristosin older versions of `patch'.
3865*75f6d617Schristos
3866*75f6d617Schristos   Multiple single-letter options that do not take an argument can be
3867*75f6d617Schristoscombined into a single command line argument with only one dash.
3868*75f6d617Schristos
3869*75f6d617Schristos`-b'
3870*75f6d617Schristos`--backup'
3871*75f6d617Schristos     Back up the original contents of each file, even if backups would
3872*75f6d617Schristos     normally not be made.  *Note Backups::.
3873*75f6d617Schristos
3874*75f6d617Schristos`-B PREFIX'
3875*75f6d617Schristos`--prefix=PREFIX'
3876*75f6d617Schristos     Prepend PREFIX to backup file names.  *Note Backup Names::.
3877*75f6d617Schristos
3878*75f6d617Schristos`--backup-if-mismatch'
3879*75f6d617Schristos     Back up the original contents of each file if the patch does not
3880*75f6d617Schristos     exactly match the file.  This is the default behavior when not
3881*75f6d617Schristos     conforming to POSIX.  *Note Backups::.
3882*75f6d617Schristos
3883*75f6d617Schristos`--binary'
3884*75f6d617Schristos     Read and write all files in binary mode, except for standard output
3885*75f6d617Schristos     and `/dev/tty'.  This option has no effect on POSIX-conforming
3886*75f6d617Schristos     systems like GNU/Linux.  On systems where this option makes a
3887*75f6d617Schristos     difference, the patch should be generated by `diff -a --binary'.
3888*75f6d617Schristos     *Note Binary::.
3889*75f6d617Schristos
3890*75f6d617Schristos`-c'
3891*75f6d617Schristos`--context'
3892*75f6d617Schristos     Interpret the patch file as a context diff.  *Note patch Input::.
3893*75f6d617Schristos
3894*75f6d617Schristos`-d DIRECTORY'
3895*75f6d617Schristos`--directory=DIRECTORY'
3896*75f6d617Schristos     Make directory DIRECTORY the current directory for interpreting
3897*75f6d617Schristos     both file names in the patch file, and file names given as
3898*75f6d617Schristos     arguments to other options.  *Note patch Directories::.
3899*75f6d617Schristos
3900*75f6d617Schristos`-D NAME'
3901*75f6d617Schristos`--ifdef=NAME'
3902*75f6d617Schristos     Make merged if-then-else output using NAME.  *Note If-then-else::.
3903*75f6d617Schristos
3904*75f6d617Schristos`--dry-run'
3905*75f6d617Schristos     Print the results of applying the patches without actually changing
3906*75f6d617Schristos     any files.  *Note Dry Runs::.
3907*75f6d617Schristos
3908*75f6d617Schristos`-e'
3909*75f6d617Schristos`--ed'
3910*75f6d617Schristos     Interpret the patch file as an `ed' script.  *Note patch Input::.
3911*75f6d617Schristos
3912*75f6d617Schristos`-E'
3913*75f6d617Schristos`--remove-empty-files'
3914*75f6d617Schristos     Remove output files that are empty after the patches have been
3915*75f6d617Schristos     applied.  *Note Creating and Removing::.
3916*75f6d617Schristos
3917*75f6d617Schristos`-f'
3918*75f6d617Schristos`--force'
3919*75f6d617Schristos     Assume that the user knows exactly what he or she is doing, and do
3920*75f6d617Schristos     not ask any questions.  *Note patch Messages::.
3921*75f6d617Schristos
3922*75f6d617Schristos`-F LINES'
3923*75f6d617Schristos`--fuzz=LINES'
3924*75f6d617Schristos     Set the maximum fuzz factor to LINES.  *Note Inexact::.
3925*75f6d617Schristos
3926*75f6d617Schristos`-g NUM'
3927*75f6d617Schristos`--get=NUM'
3928*75f6d617Schristos     If NUM is positive, get input files from a revision control system
3929*75f6d617Schristos     as necessary; if zero, do not get the files; if negative, ask the
3930*75f6d617Schristos     user whether to get the files.  *Note Revision Control::.
3931*75f6d617Schristos
3932*75f6d617Schristos`--help'
3933*75f6d617Schristos     Output a summary of usage and then exit.
3934*75f6d617Schristos
3935*75f6d617Schristos`-i PATCHFILE'
3936*75f6d617Schristos`--input=PATCHFILE'
3937*75f6d617Schristos     Read the patch from PATCHFILE rather than from standard input.
3938*75f6d617Schristos     *Note patch Options::.
3939*75f6d617Schristos
3940*75f6d617Schristos`-l'
3941*75f6d617Schristos`--ignore-white-space'
3942*75f6d617Schristos     Let any sequence of blanks (spaces or tabs) in the patch file match
3943*75f6d617Schristos     any sequence of blanks in the input file.  *Note Changed White
3944*75f6d617Schristos     Space::.
3945*75f6d617Schristos
3946*75f6d617Schristos`-n'
3947*75f6d617Schristos`--normal'
3948*75f6d617Schristos     Interpret the patch file as a normal diff.  *Note patch Input::.
3949*75f6d617Schristos
3950*75f6d617Schristos`-N'
3951*75f6d617Schristos`--forward'
3952*75f6d617Schristos     Ignore patches that `patch' thinks are reversed or already applied.
3953*75f6d617Schristos     See also `-R'.  *Note Reversed Patches::.
3954*75f6d617Schristos
3955*75f6d617Schristos`--no-backup-if-mismatch'
3956*75f6d617Schristos     Do not back up the original contents of files.  This is the default
3957*75f6d617Schristos     behavior when conforming to POSIX.  *Note Backups::.
3958*75f6d617Schristos
3959*75f6d617Schristos`-o FILE'
3960*75f6d617Schristos`--output=FILE'
3961*75f6d617Schristos     Use FILE as the output file name.  *Note patch Options::.
3962*75f6d617Schristos
3963*75f6d617Schristos`-pNUMBER'
3964*75f6d617Schristos`--strip=NUMBER'
3965*75f6d617Schristos     Set the file name strip count to NUMBER.  *Note patch
3966*75f6d617Schristos     Directories::.
3967*75f6d617Schristos
3968*75f6d617Schristos`--posix'
3969*75f6d617Schristos     Conform to POSIX, as if the `POSIXLY_CORRECT' environment variable
3970*75f6d617Schristos     had been set.  *Note patch and POSIX::.
3971*75f6d617Schristos
3972*75f6d617Schristos`--quoting-style=WORD'
3973*75f6d617Schristos     Use style WORD to quote names in diagnostics, as if the
3974*75f6d617Schristos     `QUOTING_STYLE' environment variable had been set to WORD.  *Note
3975*75f6d617Schristos     patch Quoting Style::.
3976*75f6d617Schristos
3977*75f6d617Schristos`-r REJECT-FILE'
3978*75f6d617Schristos`--reject-file=REJECT-FILE'
3979*75f6d617Schristos     Use REJECT-FILE as the reject file name.  *Note Reject Names::.
3980*75f6d617Schristos
3981*75f6d617Schristos`-R'
3982*75f6d617Schristos`--reverse'
3983*75f6d617Schristos     Assume that this patch was created with the old and new files
3984*75f6d617Schristos     swapped.  *Note Reversed Patches::.
3985*75f6d617Schristos
3986*75f6d617Schristos`-s'
3987*75f6d617Schristos`--quiet'
3988*75f6d617Schristos`--silent'
3989*75f6d617Schristos     Work silently unless an error occurs.  *Note patch Messages::.
3990*75f6d617Schristos
3991*75f6d617Schristos`-t'
3992*75f6d617Schristos`--batch'
3993*75f6d617Schristos     Do not ask any questions.  *Note patch Messages::.
3994*75f6d617Schristos
3995*75f6d617Schristos`-T'
3996*75f6d617Schristos`--set-time'
3997*75f6d617Schristos     Set the modification and access times of patched files from time
3998*75f6d617Schristos     stamps given in context diff headers, assuming that the context
3999*75f6d617Schristos     diff headers use local time.  *Note Patching Time Stamps::.
4000*75f6d617Schristos
4001*75f6d617Schristos`-u'
4002*75f6d617Schristos`--unified'
4003*75f6d617Schristos     Interpret the patch file as a unified diff.  *Note patch Input::.
4004*75f6d617Schristos
4005*75f6d617Schristos`-v'
4006*75f6d617Schristos`--version'
4007*75f6d617Schristos     Output version information and then exit.
4008*75f6d617Schristos
4009*75f6d617Schristos`-V BACKUP-STYLE'
4010*75f6d617Schristos`--version=control=BACKUP-STYLE'
4011*75f6d617Schristos     Select the naming convention for backup file names.  *Note Backup
4012*75f6d617Schristos     Names::.
4013*75f6d617Schristos
4014*75f6d617Schristos`--verbose'
4015*75f6d617Schristos     Print more diagnostics than usual.  *Note patch Messages::.
4016*75f6d617Schristos
4017*75f6d617Schristos`-x NUMBER'
4018*75f6d617Schristos`--debug=NUMBER'
4019*75f6d617Schristos     Set internal debugging flags.  Of interest only to `patch'
4020*75f6d617Schristos     patchers.
4021*75f6d617Schristos
4022*75f6d617Schristos`-Y PREFIX'
4023*75f6d617Schristos`--basename-prefix=PREFIX'
4024*75f6d617Schristos     Prepend PREFIX to base names of backup files.  *Note Backup
4025*75f6d617Schristos     Names::.
4026*75f6d617Schristos
4027*75f6d617Schristos`-z SUFFIX'
4028*75f6d617Schristos`--suffix=SUFFIX'
4029*75f6d617Schristos     Use SUFFIX as the backup extension instead of `.orig' or `~'.
4030*75f6d617Schristos     *Note Backup Names::.
4031*75f6d617Schristos
4032*75f6d617Schristos`-Z'
4033*75f6d617Schristos`--set-utc'
4034*75f6d617Schristos     Set the modification and access times of patched files from time
4035*75f6d617Schristos     stamps given in context diff headers, assuming that the context
4036*75f6d617Schristos     diff headers use UTC.  *Note Patching Time Stamps::.
4037*75f6d617Schristos
4038*75f6d617Schristos
4039*75f6d617SchristosFile: diff.info,  Node: Invoking sdiff,  Next: Standards conformance,  Prev: Invoking patch,  Up: Top
4040*75f6d617Schristos
4041*75f6d617SchristosInvoking `sdiff'
4042*75f6d617Schristos****************
4043*75f6d617Schristos
4044*75f6d617Schristos   The `sdiff' command merges two files and interactively outputs the
4045*75f6d617Schristosresults.  Its arguments are as follows:
4046*75f6d617Schristos
4047*75f6d617Schristos     sdiff -o OUTFILE OPTIONS... FROM-FILE TO-FILE
4048*75f6d617Schristos
4049*75f6d617Schristos   This merges FROM-FILE with TO-FILE, with output to OUTFILE.  If
4050*75f6d617SchristosFROM-FILE is a directory and TO-FILE is not, `sdiff' compares the file
4051*75f6d617Schristosin FROM-FILE whose file name is that of TO-FILE, and vice versa.
4052*75f6d617SchristosFROM-FILE and TO-FILE may not both be directories.
4053*75f6d617Schristos
4054*75f6d617Schristos   `sdiff' options begin with `-', so normally FROM-FILE and TO-FILE
4055*75f6d617Schristosmay not begin with `-'.  However, `--' as an argument by itself treats
4056*75f6d617Schristosthe remaining arguments as file names even if they begin with `-'.  You
4057*75f6d617Schristosmay not use `-' as an input file.
4058*75f6d617Schristos
4059*75f6d617Schristos   `sdiff' without `-o' (or `--output') produces a side-by-side
4060*75f6d617Schristosdifference.  This usage is obsolete; use the `-y' or `--side-by-side'
4061*75f6d617Schristosoption of `diff' instead.
4062*75f6d617Schristos
4063*75f6d617Schristos   An exit status of 0 means no differences were found, 1 means some
4064*75f6d617Schristosdifferences were found, and 2 means trouble.
4065*75f6d617Schristos
4066*75f6d617Schristos* Menu:
4067*75f6d617Schristos
4068*75f6d617Schristos* sdiff Options:: Summary of options to `diff'.
4069*75f6d617Schristos
4070*75f6d617Schristos
4071*75f6d617SchristosFile: diff.info,  Node: sdiff Options,  Up: Invoking sdiff
4072*75f6d617Schristos
4073*75f6d617SchristosOptions to `sdiff'
4074*75f6d617Schristos==================
4075*75f6d617Schristos
4076*75f6d617Schristos   Below is a summary of all of the options that GNU `sdiff' accepts.
4077*75f6d617SchristosEach option has two equivalent names, one of which is a single letter
4078*75f6d617Schristospreceded by `-', and the other of which is a long name preceded by
4079*75f6d617Schristos`--'.  Multiple single letter options (unless they take an argument)
4080*75f6d617Schristoscan be combined into a single command line argument.  Long named
4081*75f6d617Schristosoptions can be abbreviated to any unique prefix of their name.
4082*75f6d617Schristos
4083*75f6d617Schristos`-a'
4084*75f6d617Schristos`--text'
4085*75f6d617Schristos     Treat all files as text and compare them line-by-line, even if they
4086*75f6d617Schristos     do not appear to be text.  *Note Binary::.
4087*75f6d617Schristos
4088*75f6d617Schristos`-b'
4089*75f6d617Schristos`--ignore-space-change'
4090*75f6d617Schristos     Ignore changes in amount of white space.  *Note White Space::.
4091*75f6d617Schristos
4092*75f6d617Schristos`-B'
4093*75f6d617Schristos`--ignore-blank-lines'
4094*75f6d617Schristos     Ignore changes that just insert or delete blank lines.  *Note
4095*75f6d617Schristos     Blank Lines::.
4096*75f6d617Schristos
4097*75f6d617Schristos`-d'
4098*75f6d617Schristos`--minimal'
4099*75f6d617Schristos     Change the algorithm to perhaps find a smaller set of changes.
4100*75f6d617Schristos     This makes `sdiff' slower (sometimes much slower).  *Note diff
4101*75f6d617Schristos     Performance::.
4102*75f6d617Schristos
4103*75f6d617Schristos`--diff-program=PROGRAM'
4104*75f6d617Schristos     Use the compatible comparison program PROGRAM to compare files
4105*75f6d617Schristos     instead of `diff'.
4106*75f6d617Schristos
4107*75f6d617Schristos`-E'
4108*75f6d617Schristos`--ignore-tab-expansion'
4109*75f6d617Schristos     Ignore changes due to tab expansion.  *Note White Space::.
4110*75f6d617Schristos
4111*75f6d617Schristos`--help'
4112*75f6d617Schristos     Output a summary of usage and then exit.
4113*75f6d617Schristos
4114*75f6d617Schristos`-i'
4115*75f6d617Schristos`--ignore-case'
4116*75f6d617Schristos     Ignore changes in case; consider upper- and lower-case to be the
4117*75f6d617Schristos     same.  *Note Case Folding::.
4118*75f6d617Schristos
4119*75f6d617Schristos`-I REGEXP'
4120*75f6d617Schristos`--ignore-matching-lines=REGEXP'
4121*75f6d617Schristos     Ignore changes that just insert or delete lines that match REGEXP.
4122*75f6d617Schristos     *Note Specified Folding::.
4123*75f6d617Schristos
4124*75f6d617Schristos`-l'
4125*75f6d617Schristos`--left-column'
4126*75f6d617Schristos     Print only the left column of two common lines.  *Note Side by
4127*75f6d617Schristos     Side Format::.
4128*75f6d617Schristos
4129*75f6d617Schristos`-o FILE'
4130*75f6d617Schristos`--output=FILE'
4131*75f6d617Schristos     Put merged output into FILE.  This option is required for merging.
4132*75f6d617Schristos
4133*75f6d617Schristos`-s'
4134*75f6d617Schristos`--suppress-common-lines'
4135*75f6d617Schristos     Do not print common lines.  *Note Side by Side Format::.
4136*75f6d617Schristos
4137*75f6d617Schristos`--speed-large-files'
4138*75f6d617Schristos     Use heuristics to speed handling of large files that have numerous
4139*75f6d617Schristos     scattered small changes.  *Note diff Performance::.
4140*75f6d617Schristos
4141*75f6d617Schristos`--strip-trailing-cr'
4142*75f6d617Schristos     Strip any trailing carriage return at the end of an input line.
4143*75f6d617Schristos     *Note Binary::.
4144*75f6d617Schristos
4145*75f6d617Schristos`-t'
4146*75f6d617Schristos`--expand-tabs'
4147*75f6d617Schristos     Expand tabs to spaces in the output, to preserve the alignment of
4148*75f6d617Schristos     tabs in the input files.  *Note Tabs::.
4149*75f6d617Schristos
4150*75f6d617Schristos`-v'
4151*75f6d617Schristos`--version'
4152*75f6d617Schristos     Output version information and then exit.
4153*75f6d617Schristos
4154*75f6d617Schristos`-w COLUMNS'
4155*75f6d617Schristos`--width=COLUMNS'
4156*75f6d617Schristos     Output at most COLUMNS (default 130) print columns per line.
4157*75f6d617Schristos     *Note Side by Side Format::.  Note that for historical reasons,
4158*75f6d617Schristos     this option is `-W' in `diff', `-w' in `sdiff'.
4159*75f6d617Schristos
4160*75f6d617Schristos`-W'
4161*75f6d617Schristos`--ignore-all-space'
4162*75f6d617Schristos     Ignore white space when comparing lines.  *Note White Space::.
4163*75f6d617Schristos     Note that for historical reasons, this option is `-w' in `diff',
4164*75f6d617Schristos     `-W' in `sdiff'.
4165*75f6d617Schristos
4166*75f6d617Schristos
4167*75f6d617SchristosFile: diff.info,  Node: Standards conformance,  Next: Projects,  Prev: Invoking sdiff,  Up: Top
4168*75f6d617Schristos
4169*75f6d617SchristosStandards conformance
4170*75f6d617Schristos*********************
4171*75f6d617Schristos
4172*75f6d617Schristos   In a few cases, the GNU utilities' default behavior is incompatible
4173*75f6d617Schristoswith the POSIX standard.  To suppress these incompatibilities, define
4174*75f6d617Schristosthe `POSIXLY_CORRECT' environment variable.  Unless you are checking
4175*75f6d617Schristosfor POSIX conformance, you probably do not need to define
4176*75f6d617Schristos`POSIXLY_CORRECT'.
4177*75f6d617Schristos
4178*75f6d617Schristos   Normally options and operands can appear in any order, and programs
4179*75f6d617Schristosact as if all the options appear before any operands.  For example,
4180*75f6d617Schristos`diff lao tzu -C 2' acts like `diff -C 2 lao tzu', since `2' is an
4181*75f6d617Schristosoption-argument of `-C'.  However, if the `POSIXLY_CORRECT' environment
4182*75f6d617Schristosvariable is set, options must appear before operands, unless otherwise
4183*75f6d617Schristosspecified for a particular command.
4184*75f6d617Schristos
4185*75f6d617Schristos   Newer versions of POSIX are occasionally incompatible with older
4186*75f6d617Schristosversions.  For example, older versions of POSIX allowed the command
4187*75f6d617Schristos`diff -c -10' to have the same meaning as `diff -C 10', but POSIX
4188*75f6d617Schristos1003.1-2001 `diff' no longer allows digit-string options like `-10'.
4189*75f6d617Schristos
4190*75f6d617Schristos   The GNU utilities normally conform to the version of POSIX that is
4191*75f6d617Schristosstandard for your system.  To cause them to conform to a different
4192*75f6d617Schristosversion of POSIX, define the `_POSIX2_VERSION' environment variable to
4193*75f6d617Schristosa value of the form YYYYMM specifying the year and month the standard
4194*75f6d617Schristoswas adopted.  Two values are currently supported for `_POSIX2_VERSION':
4195*75f6d617Schristos`199209' stands for POSIX 1003.2-1992, and `200112' stands for POSIX
4196*75f6d617Schristos1003.1-2001.  For example, if you are running older software that
4197*75f6d617Schristosassumes an older version of POSIX and uses `diff -c -10', you can work
4198*75f6d617Schristosaround the compatibility problems by setting `_POSIX2_VERSION=199209'
4199*75f6d617Schristosin your environment.
4200*75f6d617Schristos
4201*75f6d617Schristos
4202*75f6d617SchristosFile: diff.info,  Node: Projects,  Next: Copying This Manual,  Prev: Standards conformance,  Up: Top
4203*75f6d617Schristos
4204*75f6d617SchristosFuture Projects
4205*75f6d617Schristos***************
4206*75f6d617Schristos
4207*75f6d617Schristos   Here are some ideas for improving GNU `diff' and `patch'.  The GNU
4208*75f6d617Schristosproject has identified some improvements as potential programming
4209*75f6d617Schristosprojects for volunteers.  You can also help by reporting any bugs that
4210*75f6d617Schristosyou find.
4211*75f6d617Schristos
4212*75f6d617Schristos   If you are a programmer and would like to contribute something to the
4213*75f6d617SchristosGNU project, please consider volunteering for one of these projects.
4214*75f6d617SchristosIf you are seriously contemplating work, please write to <gnu@gnu.org>
4215*75f6d617Schristosto coordinate with other volunteers.
4216*75f6d617Schristos
4217*75f6d617Schristos* Menu:
4218*75f6d617Schristos
4219*75f6d617Schristos* Shortcomings:: Suggested projects for improvements.
4220*75f6d617Schristos* Bugs::         Reporting bugs.
4221*75f6d617Schristos
4222*75f6d617Schristos
4223*75f6d617SchristosFile: diff.info,  Node: Shortcomings,  Next: Bugs,  Up: Projects
4224*75f6d617Schristos
4225*75f6d617SchristosSuggested Projects for Improving GNU `diff' and `patch'
4226*75f6d617Schristos=======================================================
4227*75f6d617Schristos
4228*75f6d617Schristos   One should be able to use GNU `diff' to generate a patch from any
4229*75f6d617Schristospair of directory trees, and given the patch and a copy of one such
4230*75f6d617Schristostree, use `patch' to generate a faithful copy of the other.
4231*75f6d617SchristosUnfortunately, some changes to directory trees cannot be expressed using
4232*75f6d617Schristoscurrent patch formats; also, `patch' does not handle some of the
4233*75f6d617Schristosexisting formats.  These shortcomings motivate the following suggested
4234*75f6d617Schristosprojects.
4235*75f6d617Schristos
4236*75f6d617Schristos* Menu:
4237*75f6d617Schristos
4238*75f6d617Schristos* Internationalization:: Handling multibyte and varying-width characters.
4239*75f6d617Schristos* Changing Structure::   Handling changes to the directory structure.
4240*75f6d617Schristos* Special Files::        Handling symbolic links, device special files, etc.
4241*75f6d617Schristos* Unusual File Names::   Handling file names that contain unusual characters.
4242*75f6d617Schristos* Time Stamp Order::     Outputting diffs in time stamp order.
4243*75f6d617Schristos* Ignoring Changes::     Ignoring certain changes while showing others.
4244*75f6d617Schristos* Speedups::             Improving performance.
4245*75f6d617Schristos
4246*75f6d617Schristos
4247*75f6d617SchristosFile: diff.info,  Node: Internationalization,  Next: Changing Structure,  Up: Shortcomings
4248*75f6d617Schristos
4249*75f6d617SchristosHandling Multibyte and Varying-Width Characters
4250*75f6d617Schristos-----------------------------------------------
4251*75f6d617Schristos
4252*75f6d617Schristos   `diff', `diff3' and `sdiff' treat each line of input as a string of
4253*75f6d617Schristosunibyte characters.  This can mishandle multibyte characters in some
4254*75f6d617Schristoscases.  For example, when asked to ignore spaces, `diff' does not
4255*75f6d617Schristosproperly ignore a multibyte space character.
4256*75f6d617Schristos
4257*75f6d617Schristos   Also, `diff' currently assumes that each byte is one column wide,
4258*75f6d617Schristosand this assumption is incorrect in some locales, e.g., locales that
4259*75f6d617Schristosuse UTF-8 encoding.  This causes problems with the `-y' or
4260*75f6d617Schristos`--side-by-side' option of `diff'.
4261*75f6d617Schristos
4262*75f6d617Schristos   These problems need to be fixed without unduly affecting the
4263*75f6d617Schristosperformance of the utilities in unibyte environments.
4264*75f6d617Schristos
4265*75f6d617Schristos   The IBM GNU/Linux Technology Center Internationalization Team has
4266*75f6d617Schristosproposed some patches to support internationalized `diff'
4267*75f6d617Schristos`http://oss.software.ibm.com/developer/opensource/linux/patches/i18n/diffutils-2.7.2-i18n-0.1.patch.gz'.
4268*75f6d617SchristosUnfortunately, these patches are incomplete and are to an older version
4269*75f6d617Schristosof `diff', so more work needs to be done in this area.
4270*75f6d617Schristos
4271*75f6d617Schristos
4272*75f6d617SchristosFile: diff.info,  Node: Changing Structure,  Next: Special Files,  Prev: Internationalization,  Up: Shortcomings
4273*75f6d617Schristos
4274*75f6d617SchristosHandling Changes to the Directory Structure
4275*75f6d617Schristos-------------------------------------------
4276*75f6d617Schristos
4277*75f6d617Schristos   `diff' and `patch' do not handle some changes to directory
4278*75f6d617Schristosstructure.  For example, suppose one directory tree contains a directory
4279*75f6d617Schristosnamed `D' with some subsidiary files, and another contains a file with
4280*75f6d617Schristosthe same name `D'.  `diff -r' does not output enough information for
4281*75f6d617Schristos`patch' to transform the directory subtree into the file.
4282*75f6d617Schristos
4283*75f6d617Schristos   There should be a way to specify that a file has been removed without
4284*75f6d617Schristoshaving to include its entire contents in the patch file.  There should
4285*75f6d617Schristosalso be a way to tell `patch' that a file was renamed, even if there is
4286*75f6d617Schristosno way for `diff' to generate such information.  There should be a way
4287*75f6d617Schristosto tell `patch' that a file's time stamp has changed, even if its
4288*75f6d617Schristoscontents have not changed.
4289*75f6d617Schristos
4290*75f6d617Schristos   These problems can be fixed by extending the `diff' output format to
4291*75f6d617Schristosrepresent changes in directory structure, and extending `patch' to
4292*75f6d617Schristosunderstand these extensions.
4293*75f6d617Schristos
4294*75f6d617Schristos
4295*75f6d617SchristosFile: diff.info,  Node: Special Files,  Next: Unusual File Names,  Prev: Changing Structure,  Up: Shortcomings
4296*75f6d617Schristos
4297*75f6d617SchristosFiles that are Neither Directories Nor Regular Files
4298*75f6d617Schristos----------------------------------------------------
4299*75f6d617Schristos
4300*75f6d617Schristos   Some files are neither directories nor regular files: they are
4301*75f6d617Schristosunusual files like symbolic links, device special files, named pipes,
4302*75f6d617Schristosand sockets.  Currently, `diff' treats symbolic links like regular
4303*75f6d617Schristosfiles; it treats other special files like regular files if they are
4304*75f6d617Schristosspecified at the top level, but simply reports their presence when
4305*75f6d617Schristoscomparing directories.  This means that `patch' cannot represent changes
4306*75f6d617Schristosto such files.  For example, if you change which file a symbolic link
4307*75f6d617Schristospoints to, `diff' outputs the difference between the two files, instead
4308*75f6d617Schristosof the change to the symbolic link.
4309*75f6d617Schristos
4310*75f6d617Schristos   `diff' should optionally report changes to special files specially,
4311*75f6d617Schristosand `patch' should be extended to understand these extensions.
4312*75f6d617Schristos
4313*75f6d617Schristos
4314*75f6d617SchristosFile: diff.info,  Node: Unusual File Names,  Next: Time Stamp Order,  Prev: Special Files,  Up: Shortcomings
4315*75f6d617Schristos
4316*75f6d617SchristosFile Names that Contain Unusual Characters
4317*75f6d617Schristos------------------------------------------
4318*75f6d617Schristos
4319*75f6d617Schristos   When a file name contains an unusual character like a newline or
4320*75f6d617Schristoswhite space, `diff -r' generates a patch that `patch' cannot parse.
4321*75f6d617SchristosThe problem is with format of `diff' output, not just with `patch',
4322*75f6d617Schristosbecause with odd enough file names one can cause `diff' to generate a
4323*75f6d617Schristospatch that is syntactically correct but patches the wrong files.  The
4324*75f6d617Schristosformat of `diff' output should be extended to handle all possible file
4325*75f6d617Schristosnames.
4326*75f6d617Schristos
4327*75f6d617Schristos
4328*75f6d617SchristosFile: diff.info,  Node: Time Stamp Order,  Next: Ignoring Changes,  Prev: Unusual File Names,  Up: Shortcomings
4329*75f6d617Schristos
4330*75f6d617SchristosOutputting Diffs in Time Stamp Order
4331*75f6d617Schristos------------------------------------
4332*75f6d617Schristos
4333*75f6d617Schristos   Applying `patch' to a multiple-file diff can result in files whose
4334*75f6d617Schristostime stamps are out of order.  GNU `patch' has options to restore the
4335*75f6d617Schristostime stamps of the updated files (*note Patching Time Stamps::), but
4336*75f6d617Schristossometimes it is useful to generate a patch that works even if the
4337*75f6d617Schristosrecipient does not have GNU patch, or does not use these options.  One
4338*75f6d617Schristosway to do this would be to implement a `diff' option to output diffs in
4339*75f6d617Schristostime stamp order.
4340*75f6d617Schristos
4341*75f6d617Schristos
4342*75f6d617SchristosFile: diff.info,  Node: Ignoring Changes,  Next: Speedups,  Prev: Time Stamp Order,  Up: Shortcomings
4343*75f6d617Schristos
4344*75f6d617SchristosIgnoring Certain Changes
4345*75f6d617Schristos------------------------
4346*75f6d617Schristos
4347*75f6d617Schristos   It would be nice to have a feature for specifying two strings, one in
4348*75f6d617SchristosFROM-FILE and one in TO-FILE, which should be considered to match.
4349*75f6d617SchristosThus, if the two strings are `foo' and `bar', then if two lines differ
4350*75f6d617Schristosonly in that `foo' in file 1 corresponds to `bar' in file 2, the lines
4351*75f6d617Schristosare treated as identical.
4352*75f6d617Schristos
4353*75f6d617Schristos   It is not clear how general this feature can or should be, or what
4354*75f6d617Schristossyntax should be used for it.
4355*75f6d617Schristos
4356*75f6d617Schristos   A partial substitute is to filter one or both files before comparing,
4357*75f6d617Schristose.g.:
4358*75f6d617Schristos
4359*75f6d617Schristos     sed 's/foo/bar/g' file1 | diff - file2
4360*75f6d617Schristos
4361*75f6d617Schristos   However, this outputs the filtered text, not the original.
4362*75f6d617Schristos
4363*75f6d617Schristos
4364*75f6d617SchristosFile: diff.info,  Node: Speedups,  Prev: Ignoring Changes,  Up: Shortcomings
4365*75f6d617Schristos
4366*75f6d617SchristosImproving Performance
4367*75f6d617Schristos---------------------
4368*75f6d617Schristos
4369*75f6d617Schristos   When comparing two large directory structures, one of which was
4370*75f6d617Schristosoriginally copied from the other with time stamps preserved (e.g., with
4371*75f6d617Schristos`cp -pR'), it would greatly improve performance if an option told
4372*75f6d617Schristos`diff' to assume that two files with the same size and time stamps have
4373*75f6d617Schristosthe same content.  *Note diff Performance::.
4374*75f6d617Schristos
4375*75f6d617Schristos
4376*75f6d617SchristosFile: diff.info,  Node: Bugs,  Prev: Shortcomings,  Up: Projects
4377*75f6d617Schristos
4378*75f6d617SchristosReporting Bugs
4379*75f6d617Schristos==============
4380*75f6d617Schristos
4381*75f6d617Schristos   If you think you have found a bug in GNU `cmp', `diff', `diff3', or
4382*75f6d617Schristos`sdiff', please report it by electronic mail to the GNU utilities bug
4383*75f6d617Schristosreport mailing list
4384*75f6d617Schristos(http://mail.gnu.org/mailman/listinfo/bug-gnu-utils)
4385*75f6d617Schristos<bug-gnu-utils@gnu.org>.  Please send bug reports for GNU `patch' to
4386*75f6d617Schristos<bug-patch@gnu.org>.  Send as precise a description of the problem as
4387*75f6d617Schristosyou can, including the output of the `--version' option and sample
4388*75f6d617Schristosinput files that produce the bug, if applicable.  If you have a
4389*75f6d617Schristosnontrivial fix for the bug, please send it as well.  If you have a
4390*75f6d617Schristospatch, please send it too.  It may simplify the maintainer's job if the
4391*75f6d617Schristospatch is relative to a recent test release, which you can find in the
4392*75f6d617Schristosdirectory `ftp://alpha.gnu.org/gnu/diffutils/'.
4393*75f6d617Schristos
4394*75f6d617Schristos
4395*75f6d617SchristosFile: diff.info,  Node: Copying This Manual,  Next: Index,  Prev: Projects,  Up: Top
4396*75f6d617Schristos
4397*75f6d617SchristosCopying This Manual
4398*75f6d617Schristos*******************
4399*75f6d617Schristos
4400*75f6d617Schristos* Menu:
4401*75f6d617Schristos
4402*75f6d617Schristos* GNU Free Documentation License::  License for copying this manual.
4403*75f6d617Schristos
4404*75f6d617Schristos
4405*75f6d617SchristosFile: diff.info,  Node: GNU Free Documentation License,  Up: Copying This Manual
4406*75f6d617Schristos
4407*75f6d617SchristosGNU Free Documentation License
4408*75f6d617Schristos==============================
4409*75f6d617Schristos
4410*75f6d617Schristos                        Version 1.1, March 2000
4411*75f6d617Schristos     Copyright (C) 2000 Free Software Foundation, Inc.
4412*75f6d617Schristos     59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
4413*75f6d617Schristos
4414*75f6d617Schristos     Everyone is permitted to copy and distribute verbatim copies
4415*75f6d617Schristos     of this license document, but changing it is not allowed.
4416*75f6d617Schristos
4417*75f6d617Schristos  0. PREAMBLE
4418*75f6d617Schristos
4419*75f6d617Schristos     The purpose of this License is to make a manual, textbook, or other
4420*75f6d617Schristos     written document "free" in the sense of freedom: to assure everyone
4421*75f6d617Schristos     the effective freedom to copy and redistribute it, with or without
4422*75f6d617Schristos     modifying it, either commercially or noncommercially.  Secondarily,
4423*75f6d617Schristos     this License preserves for the author and publisher a way to get
4424*75f6d617Schristos     credit for their work, while not being considered responsible for
4425*75f6d617Schristos     modifications made by others.
4426*75f6d617Schristos
4427*75f6d617Schristos     This License is a kind of "copyleft", which means that derivative
4428*75f6d617Schristos     works of the document must themselves be free in the same sense.
4429*75f6d617Schristos     It complements the GNU General Public License, which is a copyleft
4430*75f6d617Schristos     license designed for free software.
4431*75f6d617Schristos
4432*75f6d617Schristos     We have designed this License in order to use it for manuals for
4433*75f6d617Schristos     free software, because free software needs free documentation: a
4434*75f6d617Schristos     free program should come with manuals providing the same freedoms
4435*75f6d617Schristos     that the software does.  But this License is not limited to
4436*75f6d617Schristos     software manuals; it can be used for any textual work, regardless
4437*75f6d617Schristos     of subject matter or whether it is published as a printed book.
4438*75f6d617Schristos     We recommend this License principally for works whose purpose is
4439*75f6d617Schristos     instruction or reference.
4440*75f6d617Schristos
4441*75f6d617Schristos  1. APPLICABILITY AND DEFINITIONS
4442*75f6d617Schristos
4443*75f6d617Schristos     This License applies to any manual or other work that contains a
4444*75f6d617Schristos     notice placed by the copyright holder saying it can be distributed
4445*75f6d617Schristos     under the terms of this License.  The "Document", below, refers to
4446*75f6d617Schristos     any such manual or work.  Any member of the public is a licensee,
4447*75f6d617Schristos     and is addressed as "you".
4448*75f6d617Schristos
4449*75f6d617Schristos     A "Modified Version" of the Document means any work containing the
4450*75f6d617Schristos     Document or a portion of it, either copied verbatim, or with
4451*75f6d617Schristos     modifications and/or translated into another language.
4452*75f6d617Schristos
4453*75f6d617Schristos     A "Secondary Section" is a named appendix or a front-matter
4454*75f6d617Schristos     section of the Document that deals exclusively with the
4455*75f6d617Schristos     relationship of the publishers or authors of the Document to the
4456*75f6d617Schristos     Document's overall subject (or to related matters) and contains
4457*75f6d617Schristos     nothing that could fall directly within that overall subject.
4458*75f6d617Schristos     (For example, if the Document is in part a textbook of
4459*75f6d617Schristos     mathematics, a Secondary Section may not explain any mathematics.)
4460*75f6d617Schristos     The relationship could be a matter of historical connection with
4461*75f6d617Schristos     the subject or with related matters, or of legal, commercial,
4462*75f6d617Schristos     philosophical, ethical or political position regarding them.
4463*75f6d617Schristos
4464*75f6d617Schristos     The "Invariant Sections" are certain Secondary Sections whose
4465*75f6d617Schristos     titles are designated, as being those of Invariant Sections, in
4466*75f6d617Schristos     the notice that says that the Document is released under this
4467*75f6d617Schristos     License.
4468*75f6d617Schristos
4469*75f6d617Schristos     The "Cover Texts" are certain short passages of text that are
4470*75f6d617Schristos     listed, as Front-Cover Texts or Back-Cover Texts, in the notice
4471*75f6d617Schristos     that says that the Document is released under this License.
4472*75f6d617Schristos
4473*75f6d617Schristos     A "Transparent" copy of the Document means a machine-readable copy,
4474*75f6d617Schristos     represented in a format whose specification is available to the
4475*75f6d617Schristos     general public, whose contents can be viewed and edited directly
4476*75f6d617Schristos     and straightforwardly with generic text editors or (for images
4477*75f6d617Schristos     composed of pixels) generic paint programs or (for drawings) some
4478*75f6d617Schristos     widely available drawing editor, and that is suitable for input to
4479*75f6d617Schristos     text formatters or for automatic translation to a variety of
4480*75f6d617Schristos     formats suitable for input to text formatters.  A copy made in an
4481*75f6d617Schristos     otherwise Transparent file format whose markup has been designed
4482*75f6d617Schristos     to thwart or discourage subsequent modification by readers is not
4483*75f6d617Schristos     Transparent.  A copy that is not "Transparent" is called "Opaque".
4484*75f6d617Schristos
4485*75f6d617Schristos     Examples of suitable formats for Transparent copies include plain
4486*75f6d617Schristos     ASCII without markup, Texinfo input format, LaTeX input format,
4487*75f6d617Schristos     SGML or XML using a publicly available DTD, and
4488*75f6d617Schristos     standard-conforming simple HTML designed for human modification.
4489*75f6d617Schristos     Opaque formats include PostScript, PDF, proprietary formats that
4490*75f6d617Schristos     can be read and edited only by proprietary word processors, SGML
4491*75f6d617Schristos     or XML for which the DTD and/or processing tools are not generally
4492*75f6d617Schristos     available, and the machine-generated HTML produced by some word
4493*75f6d617Schristos     processors for output purposes only.
4494*75f6d617Schristos
4495*75f6d617Schristos     The "Title Page" means, for a printed book, the title page itself,
4496*75f6d617Schristos     plus such following pages as are needed to hold, legibly, the
4497*75f6d617Schristos     material this License requires to appear in the title page.  For
4498*75f6d617Schristos     works in formats which do not have any title page as such, "Title
4499*75f6d617Schristos     Page" means the text near the most prominent appearance of the
4500*75f6d617Schristos     work's title, preceding the beginning of the body of the text.
4501*75f6d617Schristos
4502*75f6d617Schristos  2. VERBATIM COPYING
4503*75f6d617Schristos
4504*75f6d617Schristos     You may copy and distribute the Document in any medium, either
4505*75f6d617Schristos     commercially or noncommercially, provided that this License, the
4506*75f6d617Schristos     copyright notices, and the license notice saying this License
4507*75f6d617Schristos     applies to the Document are reproduced in all copies, and that you
4508*75f6d617Schristos     add no other conditions whatsoever to those of this License.  You
4509*75f6d617Schristos     may not use technical measures to obstruct or control the reading
4510*75f6d617Schristos     or further copying of the copies you make or distribute.  However,
4511*75f6d617Schristos     you may accept compensation in exchange for copies.  If you
4512*75f6d617Schristos     distribute a large enough number of copies you must also follow
4513*75f6d617Schristos     the conditions in section 3.
4514*75f6d617Schristos
4515*75f6d617Schristos     You may also lend copies, under the same conditions stated above,
4516*75f6d617Schristos     and you may publicly display copies.
4517*75f6d617Schristos
4518*75f6d617Schristos  3. COPYING IN QUANTITY
4519*75f6d617Schristos
4520*75f6d617Schristos     If you publish printed copies of the Document numbering more than
4521*75f6d617Schristos     100, and the Document's license notice requires Cover Texts, you
4522*75f6d617Schristos     must enclose the copies in covers that carry, clearly and legibly,
4523*75f6d617Schristos     all these Cover Texts: Front-Cover Texts on the front cover, and
4524*75f6d617Schristos     Back-Cover Texts on the back cover.  Both covers must also clearly
4525*75f6d617Schristos     and legibly identify you as the publisher of these copies.  The
4526*75f6d617Schristos     front cover must present the full title with all words of the
4527*75f6d617Schristos     title equally prominent and visible.  You may add other material
4528*75f6d617Schristos     on the covers in addition.  Copying with changes limited to the
4529*75f6d617Schristos     covers, as long as they preserve the title of the Document and
4530*75f6d617Schristos     satisfy these conditions, can be treated as verbatim copying in
4531*75f6d617Schristos     other respects.
4532*75f6d617Schristos
4533*75f6d617Schristos     If the required texts for either cover are too voluminous to fit
4534*75f6d617Schristos     legibly, you should put the first ones listed (as many as fit
4535*75f6d617Schristos     reasonably) on the actual cover, and continue the rest onto
4536*75f6d617Schristos     adjacent pages.
4537*75f6d617Schristos
4538*75f6d617Schristos     If you publish or distribute Opaque copies of the Document
4539*75f6d617Schristos     numbering more than 100, you must either include a
4540*75f6d617Schristos     machine-readable Transparent copy along with each Opaque copy, or
4541*75f6d617Schristos     state in or with each Opaque copy a publicly-accessible
4542*75f6d617Schristos     computer-network location containing a complete Transparent copy
4543*75f6d617Schristos     of the Document, free of added material, which the general
4544*75f6d617Schristos     network-using public has access to download anonymously at no
4545*75f6d617Schristos     charge using public-standard network protocols.  If you use the
4546*75f6d617Schristos     latter option, you must take reasonably prudent steps, when you
4547*75f6d617Schristos     begin distribution of Opaque copies in quantity, to ensure that
4548*75f6d617Schristos     this Transparent copy will remain thus accessible at the stated
4549*75f6d617Schristos     location until at least one year after the last time you
4550*75f6d617Schristos     distribute an Opaque copy (directly or through your agents or
4551*75f6d617Schristos     retailers) of that edition to the public.
4552*75f6d617Schristos
4553*75f6d617Schristos     It is requested, but not required, that you contact the authors of
4554*75f6d617Schristos     the Document well before redistributing any large number of
4555*75f6d617Schristos     copies, to give them a chance to provide you with an updated
4556*75f6d617Schristos     version of the Document.
4557*75f6d617Schristos
4558*75f6d617Schristos  4. MODIFICATIONS
4559*75f6d617Schristos
4560*75f6d617Schristos     You may copy and distribute a Modified Version of the Document
4561*75f6d617Schristos     under the conditions of sections 2 and 3 above, provided that you
4562*75f6d617Schristos     release the Modified Version under precisely this License, with
4563*75f6d617Schristos     the Modified Version filling the role of the Document, thus
4564*75f6d617Schristos     licensing distribution and modification of the Modified Version to
4565*75f6d617Schristos     whoever possesses a copy of it.  In addition, you must do these
4566*75f6d617Schristos     things in the Modified Version:
4567*75f6d617Schristos
4568*75f6d617Schristos       A. Use in the Title Page (and on the covers, if any) a title
4569*75f6d617Schristos          distinct from that of the Document, and from those of
4570*75f6d617Schristos          previous versions (which should, if there were any, be listed
4571*75f6d617Schristos          in the History section of the Document).  You may use the
4572*75f6d617Schristos          same title as a previous version if the original publisher of
4573*75f6d617Schristos          that version gives permission.
4574*75f6d617Schristos
4575*75f6d617Schristos       B. List on the Title Page, as authors, one or more persons or
4576*75f6d617Schristos          entities responsible for authorship of the modifications in
4577*75f6d617Schristos          the Modified Version, together with at least five of the
4578*75f6d617Schristos          principal authors of the Document (all of its principal
4579*75f6d617Schristos          authors, if it has less than five).
4580*75f6d617Schristos
4581*75f6d617Schristos       C. State on the Title page the name of the publisher of the
4582*75f6d617Schristos          Modified Version, as the publisher.
4583*75f6d617Schristos
4584*75f6d617Schristos       D. Preserve all the copyright notices of the Document.
4585*75f6d617Schristos
4586*75f6d617Schristos       E. Add an appropriate copyright notice for your modifications
4587*75f6d617Schristos          adjacent to the other copyright notices.
4588*75f6d617Schristos
4589*75f6d617Schristos       F. Include, immediately after the copyright notices, a license
4590*75f6d617Schristos          notice giving the public permission to use the Modified
4591*75f6d617Schristos          Version under the terms of this License, in the form shown in
4592*75f6d617Schristos          the Addendum below.
4593*75f6d617Schristos
4594*75f6d617Schristos       G. Preserve in that license notice the full lists of Invariant
4595*75f6d617Schristos          Sections and required Cover Texts given in the Document's
4596*75f6d617Schristos          license notice.
4597*75f6d617Schristos
4598*75f6d617Schristos       H. Include an unaltered copy of this License.
4599*75f6d617Schristos
4600*75f6d617Schristos       I. Preserve the section entitled "History", and its title, and
4601*75f6d617Schristos          add to it an item stating at least the title, year, new
4602*75f6d617Schristos          authors, and publisher of the Modified Version as given on
4603*75f6d617Schristos          the Title Page.  If there is no section entitled "History" in
4604*75f6d617Schristos          the Document, create one stating the title, year, authors,
4605*75f6d617Schristos          and publisher of the Document as given on its Title Page,
4606*75f6d617Schristos          then add an item describing the Modified Version as stated in
4607*75f6d617Schristos          the previous sentence.
4608*75f6d617Schristos
4609*75f6d617Schristos       J. Preserve the network location, if any, given in the Document
4610*75f6d617Schristos          for public access to a Transparent copy of the Document, and
4611*75f6d617Schristos          likewise the network locations given in the Document for
4612*75f6d617Schristos          previous versions it was based on.  These may be placed in
4613*75f6d617Schristos          the "History" section.  You may omit a network location for a
4614*75f6d617Schristos          work that was published at least four years before the
4615*75f6d617Schristos          Document itself, or if the original publisher of the version
4616*75f6d617Schristos          it refers to gives permission.
4617*75f6d617Schristos
4618*75f6d617Schristos       K. In any section entitled "Acknowledgments" or "Dedications",
4619*75f6d617Schristos          preserve the section's title, and preserve in the section all
4620*75f6d617Schristos          the substance and tone of each of the contributor
4621*75f6d617Schristos          acknowledgments and/or dedications given therein.
4622*75f6d617Schristos
4623*75f6d617Schristos       L. Preserve all the Invariant Sections of the Document,
4624*75f6d617Schristos          unaltered in their text and in their titles.  Section numbers
4625*75f6d617Schristos          or the equivalent are not considered part of the section
4626*75f6d617Schristos          titles.
4627*75f6d617Schristos
4628*75f6d617Schristos       M. Delete any section entitled "Endorsements".  Such a section
4629*75f6d617Schristos          may not be included in the Modified Version.
4630*75f6d617Schristos
4631*75f6d617Schristos       N. Do not retitle any existing section as "Endorsements" or to
4632*75f6d617Schristos          conflict in title with any Invariant Section.
4633*75f6d617Schristos
4634*75f6d617Schristos     If the Modified Version includes new front-matter sections or
4635*75f6d617Schristos     appendices that qualify as Secondary Sections and contain no
4636*75f6d617Schristos     material copied from the Document, you may at your option
4637*75f6d617Schristos     designate some or all of these sections as invariant.  To do this,
4638*75f6d617Schristos     add their titles to the list of Invariant Sections in the Modified
4639*75f6d617Schristos     Version's license notice.  These titles must be distinct from any
4640*75f6d617Schristos     other section titles.
4641*75f6d617Schristos
4642*75f6d617Schristos     You may add a section entitled "Endorsements", provided it contains
4643*75f6d617Schristos     nothing but endorsements of your Modified Version by various
4644*75f6d617Schristos     parties--for example, statements of peer review or that the text
4645*75f6d617Schristos     has been approved by an organization as the authoritative
4646*75f6d617Schristos     definition of a standard.
4647*75f6d617Schristos
4648*75f6d617Schristos     You may add a passage of up to five words as a Front-Cover Text,
4649*75f6d617Schristos     and a passage of up to 25 words as a Back-Cover Text, to the end
4650*75f6d617Schristos     of the list of Cover Texts in the Modified Version.  Only one
4651*75f6d617Schristos     passage of Front-Cover Text and one of Back-Cover Text may be
4652*75f6d617Schristos     added by (or through arrangements made by) any one entity.  If the
4653*75f6d617Schristos     Document already includes a cover text for the same cover,
4654*75f6d617Schristos     previously added by you or by arrangement made by the same entity
4655*75f6d617Schristos     you are acting on behalf of, you may not add another; but you may
4656*75f6d617Schristos     replace the old one, on explicit permission from the previous
4657*75f6d617Schristos     publisher that added the old one.
4658*75f6d617Schristos
4659*75f6d617Schristos     The author(s) and publisher(s) of the Document do not by this
4660*75f6d617Schristos     License give permission to use their names for publicity for or to
4661*75f6d617Schristos     assert or imply endorsement of any Modified Version.
4662*75f6d617Schristos
4663*75f6d617Schristos  5. COMBINING DOCUMENTS
4664*75f6d617Schristos
4665*75f6d617Schristos     You may combine the Document with other documents released under
4666*75f6d617Schristos     this License, under the terms defined in section 4 above for
4667*75f6d617Schristos     modified versions, provided that you include in the combination
4668*75f6d617Schristos     all of the Invariant Sections of all of the original documents,
4669*75f6d617Schristos     unmodified, and list them all as Invariant Sections of your
4670*75f6d617Schristos     combined work in its license notice.
4671*75f6d617Schristos
4672*75f6d617Schristos     The combined work need only contain one copy of this License, and
4673*75f6d617Schristos     multiple identical Invariant Sections may be replaced with a single
4674*75f6d617Schristos     copy.  If there are multiple Invariant Sections with the same name
4675*75f6d617Schristos     but different contents, make the title of each such section unique
4676*75f6d617Schristos     by adding at the end of it, in parentheses, the name of the
4677*75f6d617Schristos     original author or publisher of that section if known, or else a
4678*75f6d617Schristos     unique number.  Make the same adjustment to the section titles in
4679*75f6d617Schristos     the list of Invariant Sections in the license notice of the
4680*75f6d617Schristos     combined work.
4681*75f6d617Schristos
4682*75f6d617Schristos     In the combination, you must combine any sections entitled
4683*75f6d617Schristos     "History" in the various original documents, forming one section
4684*75f6d617Schristos     entitled "History"; likewise combine any sections entitled
4685*75f6d617Schristos     "Acknowledgments", and any sections entitled "Dedications".  You
4686*75f6d617Schristos     must delete all sections entitled "Endorsements."
4687*75f6d617Schristos
4688*75f6d617Schristos  6. COLLECTIONS OF DOCUMENTS
4689*75f6d617Schristos
4690*75f6d617Schristos     You may make a collection consisting of the Document and other
4691*75f6d617Schristos     documents released under this License, and replace the individual
4692*75f6d617Schristos     copies of this License in the various documents with a single copy
4693*75f6d617Schristos     that is included in the collection, provided that you follow the
4694*75f6d617Schristos     rules of this License for verbatim copying of each of the
4695*75f6d617Schristos     documents in all other respects.
4696*75f6d617Schristos
4697*75f6d617Schristos     You may extract a single document from such a collection, and
4698*75f6d617Schristos     distribute it individually under this License, provided you insert
4699*75f6d617Schristos     a copy of this License into the extracted document, and follow
4700*75f6d617Schristos     this License in all other respects regarding verbatim copying of
4701*75f6d617Schristos     that document.
4702*75f6d617Schristos
4703*75f6d617Schristos  7. AGGREGATION WITH INDEPENDENT WORKS
4704*75f6d617Schristos
4705*75f6d617Schristos     A compilation of the Document or its derivatives with other
4706*75f6d617Schristos     separate and independent documents or works, in or on a volume of
4707*75f6d617Schristos     a storage or distribution medium, does not as a whole count as a
4708*75f6d617Schristos     Modified Version of the Document, provided no compilation
4709*75f6d617Schristos     copyright is claimed for the compilation.  Such a compilation is
4710*75f6d617Schristos     called an "aggregate", and this License does not apply to the
4711*75f6d617Schristos     other self-contained works thus compiled with the Document, on
4712*75f6d617Schristos     account of their being thus compiled, if they are not themselves
4713*75f6d617Schristos     derivative works of the Document.
4714*75f6d617Schristos
4715*75f6d617Schristos     If the Cover Text requirement of section 3 is applicable to these
4716*75f6d617Schristos     copies of the Document, then if the Document is less than one
4717*75f6d617Schristos     quarter of the entire aggregate, the Document's Cover Texts may be
4718*75f6d617Schristos     placed on covers that surround only the Document within the
4719*75f6d617Schristos     aggregate.  Otherwise they must appear on covers around the whole
4720*75f6d617Schristos     aggregate.
4721*75f6d617Schristos
4722*75f6d617Schristos  8. TRANSLATION
4723*75f6d617Schristos
4724*75f6d617Schristos     Translation is considered a kind of modification, so you may
4725*75f6d617Schristos     distribute translations of the Document under the terms of section
4726*75f6d617Schristos     4.  Replacing Invariant Sections with translations requires special
4727*75f6d617Schristos     permission from their copyright holders, but you may include
4728*75f6d617Schristos     translations of some or all Invariant Sections in addition to the
4729*75f6d617Schristos     original versions of these Invariant Sections.  You may include a
4730*75f6d617Schristos     translation of this License provided that you also include the
4731*75f6d617Schristos     original English version of this License.  In case of a
4732*75f6d617Schristos     disagreement between the translation and the original English
4733*75f6d617Schristos     version of this License, the original English version will prevail.
4734*75f6d617Schristos
4735*75f6d617Schristos  9. TERMINATION
4736*75f6d617Schristos
4737*75f6d617Schristos     You may not copy, modify, sublicense, or distribute the Document
4738*75f6d617Schristos     except as expressly provided for under this License.  Any other
4739*75f6d617Schristos     attempt to copy, modify, sublicense or distribute the Document is
4740*75f6d617Schristos     void, and will automatically terminate your rights under this
4741*75f6d617Schristos     License.  However, parties who have received copies, or rights,
4742*75f6d617Schristos     from you under this License will not have their licenses
4743*75f6d617Schristos     terminated so long as such parties remain in full compliance.
4744*75f6d617Schristos
4745*75f6d617Schristos 10. FUTURE REVISIONS OF THIS LICENSE
4746*75f6d617Schristos
4747*75f6d617Schristos     The Free Software Foundation may publish new, revised versions of
4748*75f6d617Schristos     the GNU Free Documentation License from time to time.  Such new
4749*75f6d617Schristos     versions will be similar in spirit to the present version, but may
4750*75f6d617Schristos     differ in detail to address new problems or concerns.  See
4751*75f6d617Schristos     `http://www.gnu.org/copyleft/'.
4752*75f6d617Schristos
4753*75f6d617Schristos     Each version of the License is given a distinguishing version
4754*75f6d617Schristos     number.  If the Document specifies that a particular numbered
4755*75f6d617Schristos     version of this License "or any later version" applies to it, you
4756*75f6d617Schristos     have the option of following the terms and conditions either of
4757*75f6d617Schristos     that specified version or of any later version that has been
4758*75f6d617Schristos     published (not as a draft) by the Free Software Foundation.  If
4759*75f6d617Schristos     the Document does not specify a version number of this License,
4760*75f6d617Schristos     you may choose any version ever published (not as a draft) by the
4761*75f6d617Schristos     Free Software Foundation.
4762*75f6d617Schristos
4763*75f6d617SchristosADDENDUM: How to use this License for your documents
4764*75f6d617Schristos----------------------------------------------------
4765*75f6d617Schristos
4766*75f6d617Schristos   To use this License in a document you have written, include a copy of
4767*75f6d617Schristosthe License in the document and put the following copyright and license
4768*75f6d617Schristosnotices just after the title page:
4769*75f6d617Schristos
4770*75f6d617Schristos       Copyright (C)  YEAR  YOUR NAME.
4771*75f6d617Schristos       Permission is granted to copy, distribute and/or modify this document
4772*75f6d617Schristos       under the terms of the GNU Free Documentation License, Version 1.1
4773*75f6d617Schristos       or any later version published by the Free Software Foundation;
4774*75f6d617Schristos       with the Invariant Sections being LIST THEIR TITLES, with the
4775*75f6d617Schristos       Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
4776*75f6d617Schristos       A copy of the license is included in the section entitled ``GNU
4777*75f6d617Schristos       Free Documentation License''.
4778*75f6d617Schristos
4779*75f6d617Schristos   If you have no Invariant Sections, write "with no Invariant Sections"
4780*75f6d617Schristosinstead of saying which ones are invariant.  If you have no Front-Cover
4781*75f6d617SchristosTexts, write "no Front-Cover Texts" instead of "Front-Cover Texts being
4782*75f6d617SchristosLIST"; likewise for Back-Cover Texts.
4783*75f6d617Schristos
4784*75f6d617Schristos   If your document contains nontrivial examples of program code, we
4785*75f6d617Schristosrecommend releasing these examples in parallel under your choice of
4786*75f6d617Schristosfree software license, such as the GNU General Public License, to
4787*75f6d617Schristospermit their use in free software.
4788*75f6d617Schristos
4789*75f6d617Schristos
4790*75f6d617SchristosFile: diff.info,  Node: Index,  Prev: Copying This Manual,  Up: Top
4791*75f6d617Schristos
4792*75f6d617SchristosIndex
4793*75f6d617Schristos*****
4794*75f6d617Schristos
4795*75f6d617Schristos* Menu:
4796*75f6d617Schristos
4797*75f6d617Schristos* ! output format:                       Context.
4798*75f6d617Schristos* +- output format:                      Unified Format.
4799*75f6d617Schristos* < output format:                       Normal.
4800*75f6d617Schristos* <<<<<<< for marking conflicts:         Marking Conflicts.
4801*75f6d617Schristos* _POSIX2_VERSION:                       Standards conformance.
4802*75f6d617Schristos* aligning tab stops:                    Tabs.
4803*75f6d617Schristos* alternate file names:                  Alternate Names.
4804*75f6d617Schristos* backup file names:                     Backup Names.
4805*75f6d617Schristos* backup file strategy:                  Backups.
4806*75f6d617Schristos* binary file diff:                      Binary.
4807*75f6d617Schristos* blank and tab difference suppression:  White Space.
4808*75f6d617Schristos* blank line difference suppression:     Blank Lines.
4809*75f6d617Schristos* brief difference reports:              Brief.
4810*75f6d617Schristos* bug reports:                           Bugs.
4811*75f6d617Schristos* C function headings:                   C Function Headings.
4812*75f6d617Schristos* C if-then-else output format:          If-then-else.
4813*75f6d617Schristos* case difference suppression:           Case Folding.
4814*75f6d617Schristos* ClearCase:                             Revision Control.
4815*75f6d617Schristos* cmp invocation:                        Invoking cmp.
4816*75f6d617Schristos* cmp options:                           cmp Options.
4817*75f6d617Schristos* columnar output:                       Side by Side.
4818*75f6d617Schristos* common mistakes with patches:          Avoiding Common Mistakes.
4819*75f6d617Schristos* comparing three files:                 Comparing Three Files.
4820*75f6d617Schristos* conflict:                              diff3 Merging.
4821*75f6d617Schristos* conflict marking:                      Marking Conflicts.
4822*75f6d617Schristos* context output format:                 Context.
4823*75f6d617Schristos* creating files:                        Creating and Removing.
4824*75f6d617Schristos* diagnostics from patch:                patch Messages.
4825*75f6d617Schristos* diff invocation:                       Invoking diff.
4826*75f6d617Schristos* diff merging:                          Interactive Merging.
4827*75f6d617Schristos* diff options:                          diff Options.
4828*75f6d617Schristos* diff sample input:                     Sample diff Input.
4829*75f6d617Schristos* diff3 hunks:                           diff3 Hunks.
4830*75f6d617Schristos* diff3 invocation:                      Invoking diff3.
4831*75f6d617Schristos* diff3 options:                         diff3 Options.
4832*75f6d617Schristos* diff3 sample input:                    Sample diff3 Input.
4833*75f6d617Schristos* directories and patch:                 patch Directories.
4834*75f6d617Schristos* directory structure changes:           Changing Structure.
4835*75f6d617Schristos* dry runs for patch:                    Dry Runs.
4836*75f6d617Schristos* ed script output format:               ed Scripts.
4837*75f6d617Schristos* EDITOR:                                Merge Commands.
4838*75f6d617Schristos* empty files, removing:                 Creating and Removing.
4839*75f6d617Schristos* exabyte, definition of:                cmp Options.
4840*75f6d617Schristos* exbibyte, definition of:               cmp Options.
4841*75f6d617Schristos* FDL, GNU Free Documentation License:   GNU Free Documentation License.
4842*75f6d617Schristos* file name alternates:                  Alternate Names.
4843*75f6d617Schristos* file names with unusual characters:    Unusual File Names.
4844*75f6d617Schristos* format of diff output:                 Output Formats.
4845*75f6d617Schristos* format of diff3 output:                Comparing Three Files.
4846*75f6d617Schristos* formats for if-then-else line groups:  Line Group Formats.
4847*75f6d617Schristos* forward ed script output format:       Forward ed.
4848*75f6d617Schristos* full lines:                            Incomplete Lines.
4849*75f6d617Schristos* function headings, C:                  C Function Headings.
4850*75f6d617Schristos* fuzz factor when patching:             Inexact.
4851*75f6d617Schristos* gibibyte, definition of:               cmp Options.
4852*75f6d617Schristos* gigabyte, definition of:               cmp Options.
4853*75f6d617Schristos* headings:                              Sections.
4854*75f6d617Schristos* hunks:                                 Hunks.
4855*75f6d617Schristos* hunks for diff3:                       diff3 Hunks.
4856*75f6d617Schristos* if-then-else output format:            If-then-else.
4857*75f6d617Schristos* ifdef output format:                   If-then-else.
4858*75f6d617Schristos* imperfect patch application:           Imperfect.
4859*75f6d617Schristos* incomplete line merging:               Merging Incomplete Lines.
4860*75f6d617Schristos* incomplete lines:                      Incomplete Lines.
4861*75f6d617Schristos* inexact patches:                       Inexact.
4862*75f6d617Schristos* inhibit messages from patch:           More or Fewer Messages.
4863*75f6d617Schristos* interactive merging:                   Interactive Merging.
4864*75f6d617Schristos* introduction:                          Comparison.
4865*75f6d617Schristos* intuiting file names from patches:     Multiple Patches.
4866*75f6d617Schristos* invoking cmp:                          Invoking cmp.
4867*75f6d617Schristos* invoking diff:                         Invoking diff.
4868*75f6d617Schristos* invoking diff3:                        Invoking diff3.
4869*75f6d617Schristos* invoking patch:                        Invoking patch.
4870*75f6d617Schristos* invoking sdiff:                        Invoking sdiff.
4871*75f6d617Schristos* keyboard input to patch:               patch and Keyboard Input.
4872*75f6d617Schristos* kibibyte, definition of:               cmp Options.
4873*75f6d617Schristos* kilobyte, definition of:               cmp Options.
4874*75f6d617Schristos* LC_COLLATE:                            Comparing Directories.
4875*75f6d617Schristos* LC_NUMERIC:                            Line Group Formats.
4876*75f6d617Schristos* LC_TIME:                               Detailed Context.
4877*75f6d617Schristos* line formats:                          Line Formats.
4878*75f6d617Schristos* line group formats:                    Line Group Formats.
4879*75f6d617Schristos* mebibyte, definition of:               cmp Options.
4880*75f6d617Schristos* megabyte, definition of:               cmp Options.
4881*75f6d617Schristos* merge commands:                        Merge Commands.
4882*75f6d617Schristos* merged diff3 format:                   Bypassing ed.
4883*75f6d617Schristos* merged output format:                  If-then-else.
4884*75f6d617Schristos* merging from a common ancestor:        diff3 Merging.
4885*75f6d617Schristos* merging interactively:                 Merge Commands.
4886*75f6d617Schristos* messages from patch:                   patch Messages.
4887*75f6d617Schristos* multibyte characters:                  Internationalization.
4888*75f6d617Schristos* multiple patches:                      Multiple Patches.
4889*75f6d617Schristos* newline treatment by diff:             Incomplete Lines.
4890*75f6d617Schristos* normal output format:                  Normal.
4891*75f6d617Schristos* options for cmp:                       cmp Options.
4892*75f6d617Schristos* options for diff:                      diff Options.
4893*75f6d617Schristos* options for diff3:                     diff3 Options.
4894*75f6d617Schristos* options for patch:                     patch Options.
4895*75f6d617Schristos* options for sdiff:                     sdiff Options.
4896*75f6d617Schristos* output formats:                        Output Formats.
4897*75f6d617Schristos* overlap:                               diff3 Merging.
4898*75f6d617Schristos* overlapping change, selection of:      Which Changes.
4899*75f6d617Schristos* overview of diff and patch:            Overview.
4900*75f6d617Schristos* paginating diff output:                Pagination.
4901*75f6d617Schristos* patch consumer tips:                   Tips for Patch Consumers.
4902*75f6d617Schristos* patch input format:                    patch Input.
4903*75f6d617Schristos* patch invocation:                      Invoking patch.
4904*75f6d617Schristos* patch messages and questions:          patch Messages.
4905*75f6d617Schristos* patch options:                         patch Options.
4906*75f6d617Schristos* patch producer tips:                   Tips for Patch Producers.
4907*75f6d617Schristos* patch, common mistakes:                Avoiding Common Mistakes.
4908*75f6d617Schristos* PATCH_GET:                             Revision Control.
4909*75f6d617Schristos* PATCH_VERSION_CONTROL:                 Backup Names.
4910*75f6d617Schristos* patches, shrinking:                    Generating Smaller Patches.
4911*75f6d617Schristos* patching directories:                  patch Directories.
4912*75f6d617Schristos* pebibyte, definition of:               cmp Options.
4913*75f6d617Schristos* performance of diff:                   diff Performance.
4914*75f6d617Schristos* petabyte, definition of:               cmp Options.
4915*75f6d617Schristos* POSIX <1>:                             Standards conformance.
4916*75f6d617Schristos* POSIX:                                 patch and POSIX.
4917*75f6d617Schristos* POSIXLY_CORRECT <1>:                   patch and POSIX.
4918*75f6d617Schristos* POSIXLY_CORRECT:                       Standards conformance.
4919*75f6d617Schristos* projects for directories:              Shortcomings.
4920*75f6d617Schristos* quoting style:                         patch Quoting Style.
4921*75f6d617Schristos* QUOTING_STYLE:                         patch Quoting Style.
4922*75f6d617Schristos* RCS:                                   Revision Control.
4923*75f6d617Schristos* RCS script output format:              RCS.
4924*75f6d617Schristos* regular expression matching headings:  Specified Headings.
4925*75f6d617Schristos* regular expression suppression:        Specified Folding.
4926*75f6d617Schristos* reject file names:                     Reject Names.
4927*75f6d617Schristos* removing empty files:                  Creating and Removing.
4928*75f6d617Schristos* reporting bugs:                        Bugs.
4929*75f6d617Schristos* reversed patches:                      Reversed Patches.
4930*75f6d617Schristos* revision control:                      Revision Control.
4931*75f6d617Schristos* sample input for diff:                 Sample diff Input.
4932*75f6d617Schristos* sample input for diff3:                Sample diff3 Input.
4933*75f6d617Schristos* SCCS:                                  Revision Control.
4934*75f6d617Schristos* script output formats:                 Scripts.
4935*75f6d617Schristos* sdiff invocation:                      Invoking sdiff.
4936*75f6d617Schristos* sdiff options:                         sdiff Options.
4937*75f6d617Schristos* sdiff output format:                   sdiff Option Summary.
4938*75f6d617Schristos* section headings:                      Sections.
4939*75f6d617Schristos* side by side:                          Side by Side.
4940*75f6d617Schristos* side by side format:                   Side by Side Format.
4941*75f6d617Schristos* SIMPLE_BACKUP_SUFFIX:                  Backup Names.
4942*75f6d617Schristos* special files:                         Special Files.
4943*75f6d617Schristos* specified headings:                    Specified Headings.
4944*75f6d617Schristos* summarizing which files differ:        Brief.
4945*75f6d617Schristos* System V diff3 compatibility:          Saving the Changed File.
4946*75f6d617Schristos* tab and blank difference suppression:  White Space.
4947*75f6d617Schristos* tab stop alignment:                    Tabs.
4948*75f6d617Schristos* tebibyte, definition of:               cmp Options.
4949*75f6d617Schristos* terabyte, definition of:               cmp Options.
4950*75f6d617Schristos* testing patch:                         Dry Runs.
4951*75f6d617Schristos* text versus binary diff:               Binary.
4952*75f6d617Schristos* time stamp format, context diffs:      Detailed Context.
4953*75f6d617Schristos* time stamp format, unified diffs:      Detailed Unified.
4954*75f6d617Schristos* time stamps on patched files:          Patching Time Stamps.
4955*75f6d617Schristos* traditional patch:                     patch and Tradition.
4956*75f6d617Schristos* two-column output:                     Side by Side.
4957*75f6d617Schristos* unified output format:                 Unified Format.
4958*75f6d617Schristos* unmerged change:                       Which Changes.
4959*75f6d617Schristos* varying-width characters:              Internationalization.
4960*75f6d617Schristos* verbose messages from patch:           More or Fewer Messages.
4961*75f6d617Schristos* version control:                       Revision Control.
4962*75f6d617Schristos* VERSION_CONTROL <1>:                   Backup Names.
4963*75f6d617Schristos* VERSION_CONTROL:                       Revision Control.
4964*75f6d617Schristos* white space in patches:                Changed White Space.
4965*75f6d617Schristos* yottabyte, definition of:              cmp Options.
4966*75f6d617Schristos* zettabyte, definition of:              cmp Options.
4967*75f6d617Schristos
4968*75f6d617Schristos
4969*75f6d617Schristos
4970*75f6d617SchristosTag Table:
4971*75f6d617SchristosNode: Top1653
4972*75f6d617SchristosNode: Overview4045
4973*75f6d617SchristosNode: Comparison7202
4974*75f6d617SchristosNode: Hunks9888
4975*75f6d617SchristosNode: White Space11313
4976*75f6d617SchristosNode: Blank Lines12807
4977*75f6d617SchristosNode: Case Folding13562
4978*75f6d617SchristosNode: Specified Folding13977
4979*75f6d617SchristosNode: Brief15052
4980*75f6d617SchristosNode: Binary16295
4981*75f6d617SchristosNode: Output Formats20358
4982*75f6d617SchristosNode: Sample diff Input21076
4983*75f6d617SchristosNode: Normal22569
4984*75f6d617SchristosNode: Detailed Normal23564
4985*75f6d617SchristosNode: Example Normal25289
4986*75f6d617SchristosNode: Context26011
4987*75f6d617SchristosNode: Context Format27567
4988*75f6d617SchristosNode: Detailed Context28345
4989*75f6d617SchristosNode: Example Context30234
4990*75f6d617SchristosNode: Less Context31748
4991*75f6d617SchristosNode: Unified Format32894
4992*75f6d617SchristosNode: Detailed Unified33676
4993*75f6d617SchristosNode: Example Unified34787
4994*75f6d617SchristosNode: Sections35807
4995*75f6d617SchristosNode: Specified Headings36552
4996*75f6d617SchristosNode: C Function Headings38083
4997*75f6d617SchristosNode: Alternate Names38908
4998*75f6d617SchristosNode: Side by Side39808
4999*75f6d617SchristosNode: Side by Side Format41947
5000*75f6d617SchristosNode: Example Side by Side42836
5001*75f6d617SchristosNode: Scripts44162
5002*75f6d617SchristosNode: ed Scripts44563
5003*75f6d617SchristosNode: Detailed ed45756
5004*75f6d617SchristosNode: Example ed47497
5005*75f6d617SchristosNode: Forward ed47934
5006*75f6d617SchristosNode: RCS48696
5007*75f6d617SchristosNode: If-then-else49904
5008*75f6d617SchristosNode: Line Group Formats51572
5009*75f6d617SchristosNode: Line Formats57437
5010*75f6d617SchristosNode: Detailed If-then-else60693
5011*75f6d617SchristosNode: Example If-then-else62583
5012*75f6d617SchristosNode: Incomplete Lines63632
5013*75f6d617SchristosNode: Comparing Directories65263
5014*75f6d617SchristosNode: Adjusting Output69220
5015*75f6d617SchristosNode: Tabs69645
5016*75f6d617SchristosNode: Pagination71177
5017*75f6d617SchristosNode: diff Performance71626
5018*75f6d617SchristosNode: Comparing Three Files74708
5019*75f6d617SchristosNode: Sample diff3 Input75580
5020*75f6d617SchristosNode: Detailed diff3 Normal76528
5021*75f6d617SchristosNode: diff3 Hunks78307
5022*75f6d617SchristosNode: Example diff3 Normal79593
5023*75f6d617SchristosNode: diff3 Merging80616
5024*75f6d617SchristosNode: Which Changes82854
5025*75f6d617SchristosNode: Marking Conflicts84258
5026*75f6d617SchristosNode: Bypassing ed86714
5027*75f6d617SchristosNode: Merging Incomplete Lines88068
5028*75f6d617SchristosNode: Saving the Changed File88784
5029*75f6d617SchristosNode: Interactive Merging89390
5030*75f6d617SchristosNode: sdiff Option Summary90094
5031*75f6d617SchristosNode: Merge Commands91242
5032*75f6d617SchristosNode: Merging with patch92503
5033*75f6d617SchristosNode: patch Input94867
5034*75f6d617SchristosNode: Revision Control95537
5035*75f6d617SchristosNode: Imperfect96689
5036*75f6d617SchristosNode: Changed White Space97825
5037*75f6d617SchristosNode: Reversed Patches98606
5038*75f6d617SchristosNode: Inexact100056
5039*75f6d617SchristosNode: Dry Runs103599
5040*75f6d617SchristosNode: Creating and Removing104447
5041*75f6d617SchristosNode: Patching Time Stamps105486
5042*75f6d617SchristosNode: Multiple Patches107677
5043*75f6d617SchristosNode: patch Directories110328
5044*75f6d617SchristosNode: Backups111942
5045*75f6d617SchristosNode: Backup Names112996
5046*75f6d617SchristosRef: Backup Names-Footnote-1115955
5047*75f6d617SchristosNode: Reject Names116082
5048*75f6d617SchristosNode: patch Messages116660
5049*75f6d617SchristosNode: More or Fewer Messages117706
5050*75f6d617SchristosNode: patch and Keyboard Input118319
5051*75f6d617SchristosNode: patch Quoting Style119332
5052*75f6d617SchristosNode: patch and POSIX120464
5053*75f6d617SchristosNode: patch and Tradition121290
5054*75f6d617SchristosNode: Making Patches124734
5055*75f6d617SchristosNode: Tips for Patch Producers125552
5056*75f6d617SchristosNode: Tips for Patch Consumers126796
5057*75f6d617SchristosNode: Avoiding Common Mistakes127421
5058*75f6d617SchristosNode: Generating Smaller Patches129934
5059*75f6d617SchristosNode: Invoking cmp131683
5060*75f6d617SchristosNode: cmp Options132532
5061*75f6d617SchristosNode: Invoking diff135896
5062*75f6d617SchristosNode: diff Options137599
5063*75f6d617SchristosNode: Invoking diff3145722
5064*75f6d617SchristosNode: diff3 Options146352
5065*75f6d617SchristosNode: Invoking patch149255
5066*75f6d617SchristosNode: patch Options150455
5067*75f6d617SchristosNode: Invoking sdiff155669
5068*75f6d617SchristosNode: sdiff Options156808
5069*75f6d617SchristosNode: Standards conformance159561
5070*75f6d617SchristosNode: Projects161299
5071*75f6d617SchristosNode: Shortcomings162002
5072*75f6d617SchristosNode: Internationalization163092
5073*75f6d617SchristosNode: Changing Structure164247
5074*75f6d617SchristosNode: Special Files165336
5075*75f6d617SchristosNode: Unusual File Names166282
5076*75f6d617SchristosNode: Time Stamp Order166904
5077*75f6d617SchristosNode: Ignoring Changes167531
5078*75f6d617SchristosNode: Speedups168285
5079*75f6d617SchristosNode: Bugs168733
5080*75f6d617SchristosNode: Copying This Manual169574
5081*75f6d617SchristosNode: GNU Free Documentation License169782
5082*75f6d617SchristosNode: Index189646
5083*75f6d617Schristos
5084*75f6d617SchristosEnd Tag Table
5085