xref: /plan9/sys/src/ape/cmd/diff/diff.texi (revision 0b459c2cb92b7c9d88818e9a2f72e678e5bc4553)
1*0b459c2cSDavid du Colombier\input texinfo @c -*-texinfo-*-
2*0b459c2cSDavid du Colombier@c %**start of header
3*0b459c2cSDavid du Colombier@setfilename diff.info
4*0b459c2cSDavid du Colombier@settitle Comparing and Merging Files
5*0b459c2cSDavid du Colombier@setchapternewpage odd
6*0b459c2cSDavid du Colombier@c %**end of header
7*0b459c2cSDavid du Colombier
8*0b459c2cSDavid du Colombier@ifinfo
9*0b459c2cSDavid du ColombierThis file documents the the GNU @code{diff}, @code{diff3}, @code{sdiff},
10*0b459c2cSDavid du Colombierand @code{cmp} commands for showing the differences between text files
11*0b459c2cSDavid du Colombierand the @code{patch} command for using their output to update files.
12*0b459c2cSDavid du Colombier
13*0b459c2cSDavid du ColombierCopyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
14*0b459c2cSDavid du Colombier
15*0b459c2cSDavid du ColombierPermission is granted to make and distribute verbatim copies of
16*0b459c2cSDavid du Colombierthis manual provided the copyright notice and this permission notice
17*0b459c2cSDavid du Colombierare preserved on all copies.
18*0b459c2cSDavid du Colombier
19*0b459c2cSDavid du Colombier@ignore
20*0b459c2cSDavid du ColombierPermission is granted to process this file through TeX and print the
21*0b459c2cSDavid du Colombierresults, provided the printed document carries copying permission
22*0b459c2cSDavid du Colombiernotice identical to this one except for the removal of this paragraph
23*0b459c2cSDavid du Colombier(this paragraph not being relevant to the printed manual).
24*0b459c2cSDavid du Colombier
25*0b459c2cSDavid du Colombier@end ignore
26*0b459c2cSDavid du ColombierPermission is granted to copy and distribute modified versions of this
27*0b459c2cSDavid du Colombiermanual under the conditions for verbatim copying, provided that the entire
28*0b459c2cSDavid du Colombierresulting derived work is distributed under the terms of a permission
29*0b459c2cSDavid du Colombiernotice identical to this one.
30*0b459c2cSDavid du Colombier
31*0b459c2cSDavid du ColombierPermission is granted to copy and distribute translations of this manual
32*0b459c2cSDavid du Colombierinto another language, under the above conditions for modified versions,
33*0b459c2cSDavid du Colombierexcept that this permission notice may be stated in a translation approved
34*0b459c2cSDavid du Colombierby the Foundation.
35*0b459c2cSDavid du Colombier@end ifinfo
36*0b459c2cSDavid du Colombier
37*0b459c2cSDavid du Colombier@titlepage
38*0b459c2cSDavid du Colombier@title Comparing and Merging Files
39*0b459c2cSDavid du Colombier@subtitle @code{diff}, @code{diff3}, @code{sdiff}, @code{cmp}, and @code{patch}
40*0b459c2cSDavid du Colombier@subtitle Edition 1.3, for @code{diff} 2.5 and @code{patch} 2.1
41*0b459c2cSDavid du Colombier@subtitle September 1993
42*0b459c2cSDavid du Colombier@author by David MacKenzie, Paul Eggert, and Richard Stallman
43*0b459c2cSDavid du Colombier
44*0b459c2cSDavid du Colombier@page
45*0b459c2cSDavid du Colombier@vskip 0pt plus 1filll
46*0b459c2cSDavid du ColombierCopyright @copyright{} 1992, 1993, 1994 Free Software Foundation, Inc.
47*0b459c2cSDavid du Colombier
48*0b459c2cSDavid du ColombierPermission is granted to make and distribute verbatim copies of
49*0b459c2cSDavid du Colombierthis manual provided the copyright notice and this permission notice
50*0b459c2cSDavid du Colombierare preserved on all copies.
51*0b459c2cSDavid du Colombier
52*0b459c2cSDavid du ColombierPermission is granted to copy and distribute modified versions of this
53*0b459c2cSDavid du Colombiermanual under the conditions for verbatim copying, provided that the entire
54*0b459c2cSDavid du Colombierresulting derived work is distributed under the terms of a permission
55*0b459c2cSDavid du Colombiernotice identical to this one.
56*0b459c2cSDavid du Colombier
57*0b459c2cSDavid du ColombierPermission is granted to copy and distribute translations of this manual
58*0b459c2cSDavid du Colombierinto another language, under the above conditions for modified versions,
59*0b459c2cSDavid du Colombierexcept that this permission notice may be stated in a translation approved
60*0b459c2cSDavid du Colombierby the Foundation.
61*0b459c2cSDavid du Colombier@end titlepage
62*0b459c2cSDavid du Colombier
63*0b459c2cSDavid du Colombier@node Top, , , (dir)
64*0b459c2cSDavid du Colombier
65*0b459c2cSDavid du Colombier@ifinfo
66*0b459c2cSDavid du ColombierThis file documents the the GNU @code{diff}, @code{diff3}, @code{sdiff},
67*0b459c2cSDavid du Colombierand @code{cmp} commands for showing the differences between text files
68*0b459c2cSDavid du Colombierand the @code{patch} command for using their output to update files.
69*0b459c2cSDavid du Colombier
70*0b459c2cSDavid du ColombierThis is Edition 1.2, for @code{diff} 2.4 and @code{patch} 2.1.
71*0b459c2cSDavid du Colombier@end ifinfo
72*0b459c2cSDavid du Colombier
73*0b459c2cSDavid du Colombier@menu
74*0b459c2cSDavid du Colombier* Overview::		Preliminary information.
75*0b459c2cSDavid du Colombier
76*0b459c2cSDavid du Colombier* Comparison::		What file comparison means.
77*0b459c2cSDavid du Colombier* Output Formats::	Formats for difference reports.
78*0b459c2cSDavid du Colombier* Comparing Directories::	Comparing files and directories.
79*0b459c2cSDavid du Colombier* Adjusting Output::	Making @code{diff} output prettier.
80*0b459c2cSDavid du Colombier* diff Performance::	Making @code{diff} smarter or faster.
81*0b459c2cSDavid du Colombier* Comparing Three Files:: Formats for three-way difference reports.
82*0b459c2cSDavid du Colombier
83*0b459c2cSDavid du Colombier* diff3 Merging::	Merging from a common ancestor.
84*0b459c2cSDavid du Colombier* Interactive Merging::	Interactive merging with @code{sdiff}.
85*0b459c2cSDavid du Colombier* Merging with patch::	Using @code{patch} to change old files into new ones.
86*0b459c2cSDavid du Colombier* Making Patches::	Tips for making patch distributions.
87*0b459c2cSDavid du Colombier
88*0b459c2cSDavid du Colombier* Invoking cmp::	How to run @code{cmp} and a summary of its options.
89*0b459c2cSDavid du Colombier* Invoking diff::	How to run @code{diff} and a summary of its options.
90*0b459c2cSDavid du Colombier* Invoking diff3::	How to run @code{diff3} and a summary of its options.
91*0b459c2cSDavid du Colombier* Invoking patch::	How to run @code{patch} and a summary of its options.
92*0b459c2cSDavid du Colombier* Invoking sdiff::	How to run @code{sdiff} and a summary of its options.
93*0b459c2cSDavid du Colombier
94*0b459c2cSDavid du Colombier* Incomplete Lines::	Lines that lack trailing newlines.
95*0b459c2cSDavid du Colombier* Projects::		If you think you've found a bug or other shortcoming.
96*0b459c2cSDavid du Colombier
97*0b459c2cSDavid du Colombier* Concept Index::	Index of concepts.
98*0b459c2cSDavid du Colombier@end menu
99*0b459c2cSDavid du Colombier
100*0b459c2cSDavid du Colombier@node Overview, Comparison, , Top
101*0b459c2cSDavid du Colombier@unnumbered Overview
102*0b459c2cSDavid du Colombier@cindex overview of @code{diff} and @code{patch}
103*0b459c2cSDavid du Colombier
104*0b459c2cSDavid du ColombierComputer users often find occasion to ask how two files differ.  Perhaps
105*0b459c2cSDavid du Colombierone file is a newer version of the other file.  Or maybe the two files
106*0b459c2cSDavid du Colombierstarted out as identical copies but were changed by different people.
107*0b459c2cSDavid du Colombier
108*0b459c2cSDavid du ColombierYou can use the @code{diff} command to show differences between two
109*0b459c2cSDavid du Colombierfiles, or each corresponding file in two directories.  @code{diff}
110*0b459c2cSDavid du Colombieroutputs differences between files line by line in any of several
111*0b459c2cSDavid du Colombierformats, selectable by command line options.  This set of differences is
112*0b459c2cSDavid du Colombieroften called a @dfn{diff} or @dfn{patch}.  For files that are identical,
113*0b459c2cSDavid du Colombier@code{diff} normally produces no output; for binary (non-text) files,
114*0b459c2cSDavid du Colombier@code{diff} normally reports only that they are different.
115*0b459c2cSDavid du Colombier
116*0b459c2cSDavid du ColombierYou can use the @code{cmp} command to show the offsets and line numbers
117*0b459c2cSDavid du Colombierwhere two files differ.  @code{cmp} can also show all the characters
118*0b459c2cSDavid du Colombierthat differ between the two files, side by side.  Another way to compare
119*0b459c2cSDavid du Colombiertwo files character by character is the Emacs command @kbd{M-x
120*0b459c2cSDavid du Colombiercompare-windows}.  @xref{Other Window, , Other Window, emacs, The GNU
121*0b459c2cSDavid du ColombierEmacs Manual}, for more information on that command.
122*0b459c2cSDavid du Colombier
123*0b459c2cSDavid du ColombierYou can use the @code{diff3} command to show differences among three
124*0b459c2cSDavid du Colombierfiles.  When two people have made independent changes to a common
125*0b459c2cSDavid du Colombieroriginal, @code{diff3} can report the differences between the original
126*0b459c2cSDavid du Colombierand the two changed versions, and can produce a merged file that
127*0b459c2cSDavid du Colombiercontains both persons' changes together with warnings about conflicts.
128*0b459c2cSDavid du Colombier
129*0b459c2cSDavid du ColombierYou can use the @code{sdiff} command to merge two files interactively.
130*0b459c2cSDavid du Colombier
131*0b459c2cSDavid du ColombierYou can use the set of differences produced by @code{diff} to distribute
132*0b459c2cSDavid du Colombierupdates to text files (such as program source code) to other people.
133*0b459c2cSDavid du ColombierThis method is especially useful when the differences are small compared
134*0b459c2cSDavid du Colombierto the complete files.  Given @code{diff} output, you can use the
135*0b459c2cSDavid du Colombier@code{patch} program to update, or @dfn{patch}, a copy of the file.  If you
136*0b459c2cSDavid du Colombierthink of @code{diff} as subtracting one file from another to produce
137*0b459c2cSDavid du Colombiertheir difference, you can think of @code{patch} as adding the difference
138*0b459c2cSDavid du Colombierto one file to reproduce the other.
139*0b459c2cSDavid du Colombier
140*0b459c2cSDavid du ColombierThis manual first concentrates on making diffs, and later shows how to
141*0b459c2cSDavid du Colombieruse diffs to update files.
142*0b459c2cSDavid du Colombier
143*0b459c2cSDavid du ColombierGNU @code{diff} was written by Mike Haertel, David Hayes, Richard
144*0b459c2cSDavid du ColombierStallman, Len Tower, and Paul Eggert.  Wayne Davison designed and
145*0b459c2cSDavid du Colombierimplemented the unified output format.  The basic algorithm is described
146*0b459c2cSDavid du Colombierin ``An O(ND) Difference Algorithm and its Variations'', Eugene W. Myers,
147*0b459c2cSDavid du Colombier@cite{Algorithmica} Vol.@: 1 No.@: 2, 1986, pp.@: 251--266; and in ``A File
148*0b459c2cSDavid du ColombierComparison Program'', Webb Miller and Eugene W. Myers,
149*0b459c2cSDavid du Colombier@cite{Software---Practice and Experience} Vol.@: 15 No.@: 11, 1985,
150*0b459c2cSDavid du Colombierpp.@: 1025--1040.
151*0b459c2cSDavid du Colombier@c From: "Gene Myers" <gene@cs.arizona.edu>
152*0b459c2cSDavid du Colombier@c They are about the same basic algorithm; the Algorithmica
153*0b459c2cSDavid du Colombier@c paper gives a rigorous treatment and the sub-algorithm for
154*0b459c2cSDavid du Colombier@c delivering scripts and should be the primary reference, but
155*0b459c2cSDavid du Colombier@c both should be mentioned.
156*0b459c2cSDavid du ColombierThe algorithm was independently discovered as described in
157*0b459c2cSDavid du Colombier``Algorithms for Approximate String Matching'',
158*0b459c2cSDavid du ColombierE. Ukkonen, @cite{Information and Control} Vol.@: 64, 1985, pp.@: 100--118.
159*0b459c2cSDavid du Colombier@c From: "Gene Myers" <gene@cs.arizona.edu>
160*0b459c2cSDavid du Colombier@c Date: Wed, 29 Sep 1993 08:27:55 MST
161*0b459c2cSDavid du Colombier@c Ukkonen should be given credit for also discovering the algorithm used
162*0b459c2cSDavid du Colombier@c in GNU diff.
163*0b459c2cSDavid du Colombier
164*0b459c2cSDavid du ColombierGNU @code{diff3} was written by Randy Smith.  GNU @code{sdiff} was
165*0b459c2cSDavid du Colombierwritten by Thomas Lord.  GNU @code{cmp} was written by Torbjorn Granlund
166*0b459c2cSDavid du Colombierand David MacKenzie.
167*0b459c2cSDavid du Colombier
168*0b459c2cSDavid du Colombier@code{patch} was written mainly by Larry Wall; the GNU enhancements were
169*0b459c2cSDavid du Colombierwritten mainly by Wayne Davison and David MacKenzie.  Parts of this
170*0b459c2cSDavid du Colombiermanual are adapted from a manual page written by Larry Wall, with his
171*0b459c2cSDavid du Colombierpermission.
172*0b459c2cSDavid du Colombier
173*0b459c2cSDavid du Colombier@node Comparison, Output Formats, Overview, Top
174*0b459c2cSDavid du Colombier@chapter What Comparison Means
175*0b459c2cSDavid du Colombier@cindex introduction
176*0b459c2cSDavid du Colombier
177*0b459c2cSDavid du ColombierThere are several ways to think about the differences between two files.
178*0b459c2cSDavid du ColombierOne way to think of the differences is as a series of lines that were
179*0b459c2cSDavid du Colombierdeleted from, inserted in, or changed in one file to produce the other
180*0b459c2cSDavid du Colombierfile.  @code{diff} compares two files line by line, finds groups of
181*0b459c2cSDavid du Colombierlines that differ, and reports each group of differing lines.  It can
182*0b459c2cSDavid du Colombierreport the differing lines in several formats, which have different
183*0b459c2cSDavid du Colombierpurposes.
184*0b459c2cSDavid du Colombier
185*0b459c2cSDavid du ColombierGNU @code{diff} can show whether files are different without detailing
186*0b459c2cSDavid du Colombierthe differences.  It also provides ways to suppress certain kinds of
187*0b459c2cSDavid du Colombierdifferences that are not important to you.  Most commonly, such
188*0b459c2cSDavid du Colombierdifferences are changes in the amount of white space between words or
189*0b459c2cSDavid du Colombierlines.  @code{diff} also provides ways to suppress differences in
190*0b459c2cSDavid du Colombieralphabetic case or in lines that match a regular expression that you
191*0b459c2cSDavid du Colombierprovide.  These options can accumulate; for example, you can ignore
192*0b459c2cSDavid du Colombierchanges in both white space and alphabetic case.
193*0b459c2cSDavid du Colombier
194*0b459c2cSDavid du ColombierAnother way to think of the differences between two files is as a
195*0b459c2cSDavid du Colombiersequence of pairs of characters that can be either identical or
196*0b459c2cSDavid du Colombierdifferent.  @code{cmp} reports the differences between two files
197*0b459c2cSDavid du Colombiercharacter by character, instead of line by line.  As a result, it is
198*0b459c2cSDavid du Colombiermore useful than @code{diff} for comparing binary files.  For text
199*0b459c2cSDavid du Colombierfiles, @code{cmp} is useful mainly when you want to know only whether
200*0b459c2cSDavid du Colombiertwo files are identical.
201*0b459c2cSDavid du Colombier
202*0b459c2cSDavid du ColombierTo illustrate the effect that considering changes character by character
203*0b459c2cSDavid du Colombiercan have compared with considering them line by line, think of what
204*0b459c2cSDavid du Colombierhappens if a single newline character is added to the beginning of a
205*0b459c2cSDavid du Colombierfile.  If that file is then compared with an otherwise identical file
206*0b459c2cSDavid du Colombierthat lacks the newline at the beginning, @code{diff} will report that a
207*0b459c2cSDavid du Colombierblank line has been added to the file, while @code{cmp} will report that
208*0b459c2cSDavid du Colombieralmost every character of the two files differs.
209*0b459c2cSDavid du Colombier
210*0b459c2cSDavid du Colombier@code{diff3} normally compares three input files line by line, finds
211*0b459c2cSDavid du Colombiergroups of lines that differ, and reports each group of differing lines.
212*0b459c2cSDavid du ColombierIts output is designed to make it easy to inspect two different sets of
213*0b459c2cSDavid du Colombierchanges to the same file.
214*0b459c2cSDavid du Colombier
215*0b459c2cSDavid du Colombier@menu
216*0b459c2cSDavid du Colombier* Hunks::		Groups of differing lines.
217*0b459c2cSDavid du Colombier* White Space::		Suppressing differences in white space.
218*0b459c2cSDavid du Colombier* Blank Lines::		Suppressing differences in blank lines.
219*0b459c2cSDavid du Colombier* Case Folding::	Suppressing differences in alphabetic case.
220*0b459c2cSDavid du Colombier* Specified Folding::	Suppressing differences that match regular expressions.
221*0b459c2cSDavid du Colombier* Brief::		Summarizing which files are different.
222*0b459c2cSDavid du Colombier* Binary::		Comparing binary files or forcing text comparisons.
223*0b459c2cSDavid du Colombier@end menu
224*0b459c2cSDavid du Colombier
225*0b459c2cSDavid du Colombier@node Hunks, White Space, , Comparison
226*0b459c2cSDavid du Colombier@section Hunks
227*0b459c2cSDavid du Colombier@cindex hunks
228*0b459c2cSDavid du Colombier
229*0b459c2cSDavid du ColombierWhen comparing two files, @code{diff} finds sequences of lines common to
230*0b459c2cSDavid du Colombierboth files, interspersed with groups of differing lines called
231*0b459c2cSDavid du Colombier@dfn{hunks}.  Comparing two identical files yields one sequence of
232*0b459c2cSDavid du Colombiercommon lines and no hunks, because no lines differ.  Comparing two
233*0b459c2cSDavid du Colombierentirely different files yields no common lines and one large hunk that
234*0b459c2cSDavid du Colombiercontains all lines of both files.  In general, there are many ways to
235*0b459c2cSDavid du Colombiermatch up lines between two given files.  @code{diff} tries to minimize
236*0b459c2cSDavid du Colombierthe total hunk size by finding large sequences of common lines
237*0b459c2cSDavid du Colombierinterspersed with small hunks of differing lines.
238*0b459c2cSDavid du Colombier
239*0b459c2cSDavid du ColombierFor example, suppose the file @file{F} contains the three lines
240*0b459c2cSDavid du Colombier@samp{a}, @samp{b}, @samp{c}, and the file @file{G} contains the same
241*0b459c2cSDavid du Colombierthree lines in reverse order @samp{c}, @samp{b}, @samp{a}.  If
242*0b459c2cSDavid du Colombier@code{diff} finds the line @samp{c} as common, then the command
243*0b459c2cSDavid du Colombier@samp{diff F G} produces this output:
244*0b459c2cSDavid du Colombier
245*0b459c2cSDavid du Colombier@example
246*0b459c2cSDavid du Colombier1,2d0
247*0b459c2cSDavid du Colombier< a
248*0b459c2cSDavid du Colombier< b
249*0b459c2cSDavid du Colombier3a2,3
250*0b459c2cSDavid du Colombier> b
251*0b459c2cSDavid du Colombier> a
252*0b459c2cSDavid du Colombier@end example
253*0b459c2cSDavid du Colombier
254*0b459c2cSDavid du Colombier@noindent
255*0b459c2cSDavid du ColombierBut if @code{diff} notices the common line @samp{b} instead, it produces
256*0b459c2cSDavid du Colombierthis output:
257*0b459c2cSDavid du Colombier
258*0b459c2cSDavid du Colombier@example
259*0b459c2cSDavid du Colombier1c1
260*0b459c2cSDavid du Colombier< a
261*0b459c2cSDavid du Colombier---
262*0b459c2cSDavid du Colombier> c
263*0b459c2cSDavid du Colombier3c3
264*0b459c2cSDavid du Colombier< c
265*0b459c2cSDavid du Colombier---
266*0b459c2cSDavid du Colombier> a
267*0b459c2cSDavid du Colombier@end example
268*0b459c2cSDavid du Colombier
269*0b459c2cSDavid du Colombier@noindent
270*0b459c2cSDavid du ColombierIt is also possible to find @samp{a} as the common line.  @code{diff}
271*0b459c2cSDavid du Colombierdoes not always find an optimal matching between the files; it takes
272*0b459c2cSDavid du Colombiershortcuts to run faster.  But its output is usually close to the
273*0b459c2cSDavid du Colombiershortest possible.  You can adjust this tradeoff with the
274*0b459c2cSDavid du Colombier@samp{--minimal} option (@pxref{diff Performance}).
275*0b459c2cSDavid du Colombier
276*0b459c2cSDavid du Colombier@node White Space, Blank Lines, Hunks, Comparison
277*0b459c2cSDavid du Colombier@section Suppressing Differences in Blank and Tab Spacing
278*0b459c2cSDavid du Colombier@cindex blank and tab difference suppression
279*0b459c2cSDavid du Colombier@cindex tab and blank difference suppression
280*0b459c2cSDavid du Colombier
281*0b459c2cSDavid du ColombierThe @samp{-b} and @samp{--ignore-space-change} options ignore white space
282*0b459c2cSDavid du Colombierat line end, and considers all other sequences of one or more
283*0b459c2cSDavid du Colombierwhite space characters to be equivalent.  With these options,
284*0b459c2cSDavid du Colombier@code{diff} considers the following two lines to be equivalent, where
285*0b459c2cSDavid du Colombier@samp{$} denotes the line end:
286*0b459c2cSDavid du Colombier
287*0b459c2cSDavid du Colombier@example
288*0b459c2cSDavid du ColombierHere lyeth  muche rychnesse  in lytell space.   -- John Heywood$
289*0b459c2cSDavid du ColombierHere lyeth muche rychnesse in lytell space. -- John Heywood   $
290*0b459c2cSDavid du Colombier@end example
291*0b459c2cSDavid du Colombier
292*0b459c2cSDavid du ColombierThe @samp{-w} and @samp{--ignore-all-space} options are stronger than
293*0b459c2cSDavid du Colombier@samp{-b}.  They ignore difference even if one file has white space where
294*0b459c2cSDavid du Colombierthe other file has none.  @dfn{White space} characters include
295*0b459c2cSDavid du Colombiertab, newline, vertical tab, form feed, carriage return, and space;
296*0b459c2cSDavid du Colombiersome locales may define additional characters to be white space.
297*0b459c2cSDavid du ColombierWith these options, @code{diff} considers the
298*0b459c2cSDavid du Colombierfollowing two lines to be equivalent, where @samp{$} denotes the line
299*0b459c2cSDavid du Colombierend and @samp{^M} denotes a carriage return:
300*0b459c2cSDavid du Colombier
301*0b459c2cSDavid du Colombier@example
302*0b459c2cSDavid du ColombierHere lyeth  muche  rychnesse in lytell space.--  John Heywood$
303*0b459c2cSDavid du Colombier  He relyeth much erychnes  seinly tells pace.  --John Heywood   ^M$
304*0b459c2cSDavid du Colombier@end example
305*0b459c2cSDavid du Colombier
306*0b459c2cSDavid du Colombier@node Blank Lines, Case Folding, White Space, Comparison
307*0b459c2cSDavid du Colombier@section Suppressing Differences in Blank Lines
308*0b459c2cSDavid du Colombier@cindex blank line difference suppression
309*0b459c2cSDavid du Colombier
310*0b459c2cSDavid du ColombierThe @samp{-B} and @samp{--ignore-blank-lines} options ignore insertions
311*0b459c2cSDavid du Colombieror deletions of blank lines.  These options normally affect only lines
312*0b459c2cSDavid du Colombierthat are completely empty; they do not affect lines that look empty but
313*0b459c2cSDavid du Colombiercontain space or tab characters.  With these options, for example, a
314*0b459c2cSDavid du Colombierfile containing
315*0b459c2cSDavid du Colombier@example
316*0b459c2cSDavid du Colombier1.  A point is that which has no part.
317*0b459c2cSDavid du Colombier
318*0b459c2cSDavid du Colombier2.  A line is breadthless length.
319*0b459c2cSDavid du Colombier-- Euclid, The Elements, I
320*0b459c2cSDavid du Colombier@end example
321*0b459c2cSDavid du Colombier@noindent
322*0b459c2cSDavid du Colombieris considered identical to a file containing
323*0b459c2cSDavid du Colombier@example
324*0b459c2cSDavid du Colombier1.  A point is that which has no part.
325*0b459c2cSDavid du Colombier2.  A line is breadthless length.
326*0b459c2cSDavid du Colombier
327*0b459c2cSDavid du Colombier
328*0b459c2cSDavid du Colombier-- Euclid, The Elements, I
329*0b459c2cSDavid du Colombier@end example
330*0b459c2cSDavid du Colombier
331*0b459c2cSDavid du Colombier@node Case Folding, Specified Folding, Blank Lines, Comparison
332*0b459c2cSDavid du Colombier@section Suppressing Case Differences
333*0b459c2cSDavid du Colombier@cindex case difference suppression
334*0b459c2cSDavid du Colombier
335*0b459c2cSDavid du ColombierGNU @code{diff} can treat lowercase letters as equivalent to their
336*0b459c2cSDavid du Colombieruppercase counterparts, so that, for example, it considers @samp{Funky
337*0b459c2cSDavid du ColombierStuff}, @samp{funky STUFF}, and @samp{fUNKy stuFf} to all be the same.
338*0b459c2cSDavid du ColombierTo request this, use the @samp{-i} or @samp{--ignore-case} option.
339*0b459c2cSDavid du Colombier
340*0b459c2cSDavid du Colombier@node Specified Folding, Brief, Case Folding, Comparison
341*0b459c2cSDavid du Colombier@section Suppressing Lines Matching a Regular Expression
342*0b459c2cSDavid du Colombier@cindex regular expression suppression
343*0b459c2cSDavid du Colombier
344*0b459c2cSDavid du ColombierTo ignore insertions and deletions of lines that match a regular
345*0b459c2cSDavid du Colombierexpression, use the @samp{-I @var{regexp}} or
346*0b459c2cSDavid du Colombier@samp{--ignore-matching-lines=@var{regexp}} option.  You should escape
347*0b459c2cSDavid du Colombierregular expressions that contain shell metacharacters to prevent the
348*0b459c2cSDavid du Colombiershell from expanding them.  For example, @samp{diff -I '^[0-9]'} ignores
349*0b459c2cSDavid du Colombierall changes to lines beginning with a digit.
350*0b459c2cSDavid du Colombier
351*0b459c2cSDavid du ColombierHowever, @samp{-I} only ignores the insertion or deletion of lines that
352*0b459c2cSDavid du Colombiercontain the regular expression if every changed line in the hunk---every
353*0b459c2cSDavid du Colombierinsertion and every deletion---matches the regular expression.  In other
354*0b459c2cSDavid du Colombierwords, for each nonignorable change, @code{diff} prints the complete set
355*0b459c2cSDavid du Colombierof changes in its vicinity, including the ignorable ones.
356*0b459c2cSDavid du Colombier
357*0b459c2cSDavid du ColombierYou can specify more than one regular expression for lines to ignore by
358*0b459c2cSDavid du Colombierusing more than one @samp{-I} option.  @code{diff} tries to match each
359*0b459c2cSDavid du Colombierline against each regular expression, starting with the last one given.
360*0b459c2cSDavid du Colombier
361*0b459c2cSDavid du Colombier@node Brief, Binary, Specified Folding, Comparison
362*0b459c2cSDavid du Colombier@section Summarizing Which Files Differ
363*0b459c2cSDavid du Colombier@cindex summarizing which files differ
364*0b459c2cSDavid du Colombier@cindex brief difference reports
365*0b459c2cSDavid du Colombier
366*0b459c2cSDavid du ColombierWhen you only want to find out whether files are different, and you
367*0b459c2cSDavid du Colombierdon't care what the differences are, you can use the summary output
368*0b459c2cSDavid du Colombierformat.  In this format, instead of showing the differences between the
369*0b459c2cSDavid du Colombierfiles, @code{diff} simply reports whether files differ.  The @samp{-q}
370*0b459c2cSDavid du Colombierand @samp{--brief} options select this output format.
371*0b459c2cSDavid du Colombier
372*0b459c2cSDavid du ColombierThis format is especially useful when comparing the contents of two
373*0b459c2cSDavid du Colombierdirectories.  It is also much faster than doing the normal line by line
374*0b459c2cSDavid du Colombiercomparisons, because @code{diff} can stop analyzing the files as soon as
375*0b459c2cSDavid du Colombierit knows that there are any differences.
376*0b459c2cSDavid du Colombier
377*0b459c2cSDavid du ColombierYou can also get a brief indication of whether two files differ by using
378*0b459c2cSDavid du Colombier@code{cmp}.  For files that are identical, @code{cmp} produces no
379*0b459c2cSDavid du Colombieroutput.  When the files differ, by default, @code{cmp} outputs the byte
380*0b459c2cSDavid du Colombieroffset and line number where the first difference occurs.  You can use
381*0b459c2cSDavid du Colombierthe @samp{-s} option to suppress that information, so that @code{cmp}
382*0b459c2cSDavid du Colombierproduces no output and reports whether the files differ using only its
383*0b459c2cSDavid du Colombierexit status (@pxref{Invoking cmp}).
384*0b459c2cSDavid du Colombier
385*0b459c2cSDavid du Colombier@c Fix this.
386*0b459c2cSDavid du ColombierUnlike @code{diff}, @code{cmp} cannot compare directories; it can only
387*0b459c2cSDavid du Colombiercompare two files.
388*0b459c2cSDavid du Colombier
389*0b459c2cSDavid du Colombier@node Binary, , Brief, Comparison
390*0b459c2cSDavid du Colombier@section Binary Files and Forcing Text Comparisons
391*0b459c2cSDavid du Colombier@cindex binary file diff
392*0b459c2cSDavid du Colombier@cindex text versus binary diff
393*0b459c2cSDavid du Colombier
394*0b459c2cSDavid du ColombierIf @code{diff} thinks that either of the two files it is comparing is
395*0b459c2cSDavid du Colombierbinary (a non-text file), it normally treats that pair of files much as
396*0b459c2cSDavid du Colombierif the summary output format had been selected (@pxref{Brief}), and
397*0b459c2cSDavid du Colombierreports only that the binary files are different.  This is because line
398*0b459c2cSDavid du Colombierby line comparisons are usually not meaningful for binary files.
399*0b459c2cSDavid du Colombier
400*0b459c2cSDavid du Colombier@code{diff} determines whether a file is text or binary by checking the
401*0b459c2cSDavid du Colombierfirst few bytes in the file; the exact number of bytes is system
402*0b459c2cSDavid du Colombierdependent, but it is typically several thousand.  If every character in
403*0b459c2cSDavid du Colombierthat part of the file is non-null, @code{diff} considers the file to be
404*0b459c2cSDavid du Colombiertext; otherwise it considers the file to be binary.
405*0b459c2cSDavid du Colombier
406*0b459c2cSDavid du ColombierSometimes you might want to force @code{diff} to consider files to be
407*0b459c2cSDavid du Colombiertext.  For example, you might be comparing text files that contain
408*0b459c2cSDavid du Colombiernull characters; @code{diff} would erroneously decide that those are
409*0b459c2cSDavid du Colombiernon-text files.  Or you might be comparing documents that are in a
410*0b459c2cSDavid du Colombierformat used by a word processing system that uses null characters to
411*0b459c2cSDavid du Colombierindicate special formatting.  You can force @code{diff} to consider all
412*0b459c2cSDavid du Colombierfiles to be text files, and compare them line by line, by using the
413*0b459c2cSDavid du Colombier@samp{-a} or @samp{--text} option.  If the files you compare using this
414*0b459c2cSDavid du Colombieroption do not in fact contain text, they will probably contain few
415*0b459c2cSDavid du Colombiernewline characters, and the @code{diff} output will consist of hunks
416*0b459c2cSDavid du Colombiershowing differences between long lines of whatever characters the files
417*0b459c2cSDavid du Colombiercontain.
418*0b459c2cSDavid du Colombier
419*0b459c2cSDavid du ColombierYou can also force @code{diff} to consider all files to be binary files,
420*0b459c2cSDavid du Colombierand report only whether they differ (but not how).  Use the
421*0b459c2cSDavid du Colombier@samp{--brief} option for this.
422*0b459c2cSDavid du Colombier
423*0b459c2cSDavid du ColombierIn operating systems that distinguish between text and binary files,
424*0b459c2cSDavid du Colombier@code{diff} normally reads and writes all data as text.  Use the
425*0b459c2cSDavid du Colombier@samp{--binary} option to force @code{diff} to read and write binary
426*0b459c2cSDavid du Colombierdata instead.  This option has no effect on a Posix-compliant system
427*0b459c2cSDavid du Colombierlike GNU or traditional Unix.  However, many personal computer
428*0b459c2cSDavid du Colombieroperating systems represent the end of a line with a carriage return
429*0b459c2cSDavid du Colombierfollowed by a newline.  On such systems, @code{diff} normally ignores
430*0b459c2cSDavid du Colombierthese carriage returns on input and generates them at the end of each
431*0b459c2cSDavid du Colombieroutput line, but with the @samp{--binary} option @code{diff} treats
432*0b459c2cSDavid du Colombiereach carriage return as just another input character, and does not
433*0b459c2cSDavid du Colombiergenerate a carriage return at the end of each output line.  This can be
434*0b459c2cSDavid du Colombieruseful when dealing with non-text files that are meant to be
435*0b459c2cSDavid du Colombierinterchanged with Posix-compliant systems.
436*0b459c2cSDavid du Colombier
437*0b459c2cSDavid du ColombierIf you want to compare two files byte by byte, you can use the
438*0b459c2cSDavid du Colombier@code{cmp} program with the @samp{-l} option to show the values of each
439*0b459c2cSDavid du Colombierdiffering byte in the two files.  With GNU @code{cmp}, you can also use
440*0b459c2cSDavid du Colombierthe @samp{-c} option to show the ASCII representation of those bytes.
441*0b459c2cSDavid du Colombier@xref{Invoking cmp}, for more information.
442*0b459c2cSDavid du Colombier
443*0b459c2cSDavid du ColombierIf @code{diff3} thinks that any of the files it is comparing is binary
444*0b459c2cSDavid du Colombier(a non-text file), it normally reports an error, because such
445*0b459c2cSDavid du Colombiercomparisons are usually not useful.  @code{diff3} uses the same test as
446*0b459c2cSDavid du Colombier@code{diff} to decide whether a file is binary.  As with @code{diff}, if
447*0b459c2cSDavid du Colombierthe input files contain a few non-text characters but otherwise are like
448*0b459c2cSDavid du Colombiertext files, you can force @code{diff3} to consider all files to be text
449*0b459c2cSDavid du Colombierfiles and compare them line by line by using the @samp{-a} or
450*0b459c2cSDavid du Colombier@samp{--text} options.
451*0b459c2cSDavid du Colombier
452*0b459c2cSDavid du Colombier@node Output Formats, Comparing Directories, Comparison, Top
453*0b459c2cSDavid du Colombier@chapter @code{diff} Output Formats
454*0b459c2cSDavid du Colombier@cindex output formats
455*0b459c2cSDavid du Colombier@cindex format of @code{diff} output
456*0b459c2cSDavid du Colombier
457*0b459c2cSDavid du Colombier@code{diff} has several mutually exclusive options for output format.
458*0b459c2cSDavid du ColombierThe following sections describe each format, illustrating how
459*0b459c2cSDavid du Colombier@code{diff} reports the differences between two sample input files.
460*0b459c2cSDavid du Colombier
461*0b459c2cSDavid du Colombier@menu
462*0b459c2cSDavid du Colombier* Sample diff Input::	Sample @code{diff} input files for examples.
463*0b459c2cSDavid du Colombier* Normal::		Showing differences without surrounding text.
464*0b459c2cSDavid du Colombier* Context::		Showing differences with the surrounding text.
465*0b459c2cSDavid du Colombier* Side by Side::        Showing differences in two columns.
466*0b459c2cSDavid du Colombier* Scripts::		Generating scripts for other programs.
467*0b459c2cSDavid du Colombier* If-then-else::	Merging files with if-then-else.
468*0b459c2cSDavid du Colombier@end menu
469*0b459c2cSDavid du Colombier
470*0b459c2cSDavid du Colombier@node Sample diff Input, Normal, , Output Formats
471*0b459c2cSDavid du Colombier@section Two Sample Input Files
472*0b459c2cSDavid du Colombier@cindex @code{diff} sample input
473*0b459c2cSDavid du Colombier@cindex sample input for @code{diff}
474*0b459c2cSDavid du Colombier
475*0b459c2cSDavid du ColombierHere are two sample files that we will use in numerous examples to
476*0b459c2cSDavid du Colombierillustrate the output of @code{diff} and how various options can change
477*0b459c2cSDavid du Colombierit.
478*0b459c2cSDavid du Colombier
479*0b459c2cSDavid du ColombierThis is the file @file{lao}:
480*0b459c2cSDavid du Colombier
481*0b459c2cSDavid du Colombier@example
482*0b459c2cSDavid du ColombierThe Way that can be told of is not the eternal Way;
483*0b459c2cSDavid du ColombierThe name that can be named is not the eternal name.
484*0b459c2cSDavid du ColombierThe Nameless is the origin of Heaven and Earth;
485*0b459c2cSDavid du ColombierThe Named is the mother of all things.
486*0b459c2cSDavid du ColombierTherefore let there always be non-being,
487*0b459c2cSDavid du Colombier  so we may see their subtlety,
488*0b459c2cSDavid du ColombierAnd let there always be being,
489*0b459c2cSDavid du Colombier  so we may see their outcome.
490*0b459c2cSDavid du ColombierThe two are the same,
491*0b459c2cSDavid du ColombierBut after they are produced,
492*0b459c2cSDavid du Colombier  they have different names.
493*0b459c2cSDavid du Colombier@end example
494*0b459c2cSDavid du Colombier
495*0b459c2cSDavid du ColombierThis is the file @file{tzu}:
496*0b459c2cSDavid du Colombier
497*0b459c2cSDavid du Colombier@example
498*0b459c2cSDavid du ColombierThe Nameless is the origin of Heaven and Earth;
499*0b459c2cSDavid du ColombierThe named is the mother of all things.
500*0b459c2cSDavid du Colombier
501*0b459c2cSDavid du ColombierTherefore let there always be non-being,
502*0b459c2cSDavid du Colombier  so we may see their subtlety,
503*0b459c2cSDavid du ColombierAnd let there always be being,
504*0b459c2cSDavid du Colombier  so we may see their outcome.
505*0b459c2cSDavid du ColombierThe two are the same,
506*0b459c2cSDavid du ColombierBut after they are produced,
507*0b459c2cSDavid du Colombier  they have different names.
508*0b459c2cSDavid du ColombierThey both may be called deep and profound.
509*0b459c2cSDavid du ColombierDeeper and more profound,
510*0b459c2cSDavid du ColombierThe door of all subtleties!
511*0b459c2cSDavid du Colombier@end example
512*0b459c2cSDavid du Colombier
513*0b459c2cSDavid du ColombierIn this example, the first hunk contains just the first two lines of
514*0b459c2cSDavid du Colombier@file{lao}, the second hunk contains the fourth line of @file{lao}
515*0b459c2cSDavid du Colombieropposing the second and third lines of @file{tzu}, and the last hunk
516*0b459c2cSDavid du Colombiercontains just the last three lines of @file{tzu}.
517*0b459c2cSDavid du Colombier
518*0b459c2cSDavid du Colombier@node Normal, Context, Sample diff Input, Output Formats
519*0b459c2cSDavid du Colombier@section Showing Differences Without Context
520*0b459c2cSDavid du Colombier@cindex normal output format
521*0b459c2cSDavid du Colombier@cindex @samp{<} output format
522*0b459c2cSDavid du Colombier
523*0b459c2cSDavid du ColombierThe ``normal'' @code{diff} output format shows each hunk of differences
524*0b459c2cSDavid du Colombierwithout any surrounding context.  Sometimes such output is the clearest
525*0b459c2cSDavid du Colombierway to see how lines have changed, without the clutter of nearby
526*0b459c2cSDavid du Colombierunchanged lines (although you can get similar results with the context
527*0b459c2cSDavid du Colombieror unified formats by using 0 lines of context).  However, this format
528*0b459c2cSDavid du Colombieris no longer widely used for sending out patches; for that purpose, the
529*0b459c2cSDavid du Colombiercontext format (@pxref{Context Format}) and the unified format
530*0b459c2cSDavid du Colombier(@pxref{Unified Format}) are superior.  Normal format is the default for
531*0b459c2cSDavid du Colombiercompatibility with older versions of @code{diff} and the Posix standard.
532*0b459c2cSDavid du Colombier
533*0b459c2cSDavid du Colombier@menu
534*0b459c2cSDavid du Colombier* Detailed Normal::	A detailed description of normal output format.
535*0b459c2cSDavid du Colombier* Example Normal::	Sample output in the normal format.
536*0b459c2cSDavid du Colombier@end menu
537*0b459c2cSDavid du Colombier
538*0b459c2cSDavid du Colombier@node Detailed Normal, Example Normal, , Normal
539*0b459c2cSDavid du Colombier@subsection Detailed Description of Normal Format
540*0b459c2cSDavid du Colombier
541*0b459c2cSDavid du ColombierThe normal output format consists of one or more hunks of differences;
542*0b459c2cSDavid du Colombiereach hunk shows one area where the files differ.  Normal format hunks
543*0b459c2cSDavid du Colombierlook like this:
544*0b459c2cSDavid du Colombier
545*0b459c2cSDavid du Colombier@example
546*0b459c2cSDavid du Colombier@var{change-command}
547*0b459c2cSDavid du Colombier< @var{from-file-line}
548*0b459c2cSDavid du Colombier< @var{from-file-line}@dots{}
549*0b459c2cSDavid du Colombier---
550*0b459c2cSDavid du Colombier> @var{to-file-line}
551*0b459c2cSDavid du Colombier> @var{to-file-line}@dots{}
552*0b459c2cSDavid du Colombier@end example
553*0b459c2cSDavid du Colombier
554*0b459c2cSDavid du ColombierThere are three types of change commands.  Each consists of a line
555*0b459c2cSDavid du Colombiernumber or comma-separated range of lines in the first file, a single
556*0b459c2cSDavid du Colombiercharacter indicating the kind of change to make, and a line number or
557*0b459c2cSDavid du Colombiercomma-separated range of lines in the second file.  All line numbers are
558*0b459c2cSDavid du Colombierthe original line numbers in each file.  The types of change commands
559*0b459c2cSDavid du Colombierare:
560*0b459c2cSDavid du Colombier
561*0b459c2cSDavid du Colombier@table @samp
562*0b459c2cSDavid du Colombier@item @var{l}a@var{r}
563*0b459c2cSDavid du ColombierAdd the lines in range @var{r} of the second file after line @var{l} of
564*0b459c2cSDavid du Colombierthe first file.  For example, @samp{8a12,15} means append lines 12--15
565*0b459c2cSDavid du Colombierof file 2 after line 8 of file 1; or, if changing file 2 into file 1,
566*0b459c2cSDavid du Colombierdelete lines 12--15 of file 2.
567*0b459c2cSDavid du Colombier
568*0b459c2cSDavid du Colombier@item @var{f}c@var{t}
569*0b459c2cSDavid du ColombierReplace the lines in range @var{f} of the first file with lines in range
570*0b459c2cSDavid du Colombier@var{t} of the second file.  This is like a combined add and delete, but
571*0b459c2cSDavid du Colombiermore compact.  For example, @samp{5,7c8,10} means change lines 5--7 of
572*0b459c2cSDavid du Colombierfile 1 to read as lines 8--10 of file 2; or, if changing file 2 into
573*0b459c2cSDavid du Colombierfile 1, change lines 8--10 of file 2 to read as lines 5--7 of file 1.
574*0b459c2cSDavid du Colombier
575*0b459c2cSDavid du Colombier@item @var{r}d@var{l}
576*0b459c2cSDavid du ColombierDelete the lines in range @var{r} from the first file; line @var{l} is where
577*0b459c2cSDavid du Colombierthey would have appeared in the second file had they not been deleted.
578*0b459c2cSDavid du ColombierFor example, @samp{5,7d3} means delete lines 5--7 of file 1; or, if
579*0b459c2cSDavid du Colombierchanging file 2 into file 1, append lines 5--7 of file 1 after line 3 of
580*0b459c2cSDavid du Colombierfile 2.
581*0b459c2cSDavid du Colombier@end table
582*0b459c2cSDavid du Colombier
583*0b459c2cSDavid du Colombier@node Example Normal, , Detailed Normal, Normal
584*0b459c2cSDavid du Colombier@subsection An Example of Normal Format
585*0b459c2cSDavid du Colombier
586*0b459c2cSDavid du ColombierHere is the output of the command @samp{diff lao tzu}
587*0b459c2cSDavid du Colombier(@pxref{Sample diff Input}, for the complete contents of the two files).
588*0b459c2cSDavid du ColombierNotice that it shows only the lines that are different between the two
589*0b459c2cSDavid du Colombierfiles.
590*0b459c2cSDavid du Colombier
591*0b459c2cSDavid du Colombier@example
592*0b459c2cSDavid du Colombier1,2d0
593*0b459c2cSDavid du Colombier< The Way that can be told of is not the eternal Way;
594*0b459c2cSDavid du Colombier< The name that can be named is not the eternal name.
595*0b459c2cSDavid du Colombier4c2,3
596*0b459c2cSDavid du Colombier< The Named is the mother of all things.
597*0b459c2cSDavid du Colombier---
598*0b459c2cSDavid du Colombier> The named is the mother of all things.
599*0b459c2cSDavid du Colombier>
600*0b459c2cSDavid du Colombier11a11,13
601*0b459c2cSDavid du Colombier> They both may be called deep and profound.
602*0b459c2cSDavid du Colombier> Deeper and more profound,
603*0b459c2cSDavid du Colombier> The door of all subtleties!
604*0b459c2cSDavid du Colombier@end example
605*0b459c2cSDavid du Colombier
606*0b459c2cSDavid du Colombier@node Context, Side by Side, Normal, Output Formats
607*0b459c2cSDavid du Colombier@section Showing Differences in Their Context
608*0b459c2cSDavid du Colombier@cindex context output format
609*0b459c2cSDavid du Colombier@cindex @samp{!} output format
610*0b459c2cSDavid du Colombier
611*0b459c2cSDavid du ColombierUsually, when you are looking at the differences between files, you will
612*0b459c2cSDavid du Colombieralso want to see the parts of the files near the lines that differ, to
613*0b459c2cSDavid du Colombierhelp you understand exactly what has changed.  These nearby parts of the
614*0b459c2cSDavid du Colombierfiles are called the @dfn{context}.
615*0b459c2cSDavid du Colombier
616*0b459c2cSDavid du ColombierGNU @code{diff} provides two output formats that show context around the
617*0b459c2cSDavid du Colombierdiffering lines: @dfn{context format} and @dfn{unified format}.  It can
618*0b459c2cSDavid du Colombieroptionally show in which function or section of the file the differing
619*0b459c2cSDavid du Colombierlines are found.
620*0b459c2cSDavid du Colombier
621*0b459c2cSDavid du ColombierIf you are distributing new versions of files to other people in the
622*0b459c2cSDavid du Colombierform of @code{diff} output, you should use one of the output formats
623*0b459c2cSDavid du Colombierthat show context so that they can apply the diffs even if they have
624*0b459c2cSDavid du Colombiermade small changes of their own to the files.  @code{patch} can apply
625*0b459c2cSDavid du Colombierthe diffs in this case by searching in the files for the lines of
626*0b459c2cSDavid du Colombiercontext around the differing lines; if those lines are actually a few
627*0b459c2cSDavid du Colombierlines away from where the diff says they are, @code{patch} can adjust
628*0b459c2cSDavid du Colombierthe line numbers accordingly and still apply the diff correctly.
629*0b459c2cSDavid du Colombier@xref{Imperfect}, for more information on using @code{patch} to apply
630*0b459c2cSDavid du Colombierimperfect diffs.
631*0b459c2cSDavid du Colombier
632*0b459c2cSDavid du Colombier@menu
633*0b459c2cSDavid du Colombier* Context Format::	An output format that shows surrounding lines.
634*0b459c2cSDavid du Colombier* Unified Format::	A more compact output format that shows context.
635*0b459c2cSDavid du Colombier* Sections::		Showing which sections of the files differences are in.
636*0b459c2cSDavid du Colombier* Alternate Names::	Showing alternate file names in context headers.
637*0b459c2cSDavid du Colombier@end menu
638*0b459c2cSDavid du Colombier
639*0b459c2cSDavid du Colombier@node Context Format, Unified Format, , Context
640*0b459c2cSDavid du Colombier@subsection Context Format
641*0b459c2cSDavid du Colombier
642*0b459c2cSDavid du ColombierThe context output format shows several lines of context around the
643*0b459c2cSDavid du Colombierlines that differ.  It is the standard format for distributing updates
644*0b459c2cSDavid du Colombierto source code.
645*0b459c2cSDavid du Colombier
646*0b459c2cSDavid du ColombierTo select this output format, use the @samp{-C @var{lines}},
647*0b459c2cSDavid du Colombier@samp{--context@r{[}=@var{lines}@r{]}}, or @samp{-c} option.  The
648*0b459c2cSDavid du Colombierargument @var{lines} that some of these options take is the number of
649*0b459c2cSDavid du Colombierlines of context to show.  If you do not specify @var{lines}, it
650*0b459c2cSDavid du Colombierdefaults to three.  For proper operation, @code{patch} typically needs
651*0b459c2cSDavid du Colombierat least two lines of context.
652*0b459c2cSDavid du Colombier
653*0b459c2cSDavid du Colombier@menu
654*0b459c2cSDavid du Colombier* Detailed Context::	A detailed description of the context output format.
655*0b459c2cSDavid du Colombier* Example Context::	Sample output in context format.
656*0b459c2cSDavid du Colombier* Less Context::	Another sample with less context.
657*0b459c2cSDavid du Colombier@end menu
658*0b459c2cSDavid du Colombier
659*0b459c2cSDavid du Colombier@node Detailed Context, Example Context, , Context Format
660*0b459c2cSDavid du Colombier@subsubsection Detailed Description of Context Format
661*0b459c2cSDavid du Colombier
662*0b459c2cSDavid du ColombierThe context output format starts with a two-line header, which looks
663*0b459c2cSDavid du Colombierlike this:
664*0b459c2cSDavid du Colombier
665*0b459c2cSDavid du Colombier@example
666*0b459c2cSDavid du Colombier*** @var{from-file} @var{from-file-modification-time}
667*0b459c2cSDavid du Colombier--- @var{to-file} @var{to-file-modification time}
668*0b459c2cSDavid du Colombier@end example
669*0b459c2cSDavid du Colombier
670*0b459c2cSDavid du Colombier@noindent
671*0b459c2cSDavid du ColombierYou can change the header's content with the @samp{-L @var{label}} or
672*0b459c2cSDavid du Colombier@samp{--label=@var{label}} option; see @ref{Alternate Names}.
673*0b459c2cSDavid du Colombier
674*0b459c2cSDavid du ColombierNext come one or more hunks of differences; each hunk shows one area
675*0b459c2cSDavid du Colombierwhere the files differ.  Context format hunks look like this:
676*0b459c2cSDavid du Colombier
677*0b459c2cSDavid du Colombier@example
678*0b459c2cSDavid du Colombier***************
679*0b459c2cSDavid du Colombier*** @var{from-file-line-range} ****
680*0b459c2cSDavid du Colombier  @var{from-file-line}
681*0b459c2cSDavid du Colombier  @var{from-file-line}@dots{}
682*0b459c2cSDavid du Colombier--- @var{to-file-line-range} ----
683*0b459c2cSDavid du Colombier  @var{to-file-line}
684*0b459c2cSDavid du Colombier  @var{to-file-line}@dots{}
685*0b459c2cSDavid du Colombier@end example
686*0b459c2cSDavid du Colombier
687*0b459c2cSDavid du ColombierThe lines of context around the lines that differ start with two space
688*0b459c2cSDavid du Colombiercharacters.  The lines that differ between the two files start with one
689*0b459c2cSDavid du Colombierof the following indicator characters, followed by a space character:
690*0b459c2cSDavid du Colombier
691*0b459c2cSDavid du Colombier@table @samp
692*0b459c2cSDavid du Colombier@item !
693*0b459c2cSDavid du ColombierA line that is part of a group of one or more lines that changed between
694*0b459c2cSDavid du Colombierthe two files.  There is a corresponding group of lines marked with
695*0b459c2cSDavid du Colombier@samp{!} in the part of this hunk for the other file.
696*0b459c2cSDavid du Colombier
697*0b459c2cSDavid du Colombier@item +
698*0b459c2cSDavid du ColombierAn ``inserted'' line in the second file that corresponds to nothing in
699*0b459c2cSDavid du Colombierthe first file.
700*0b459c2cSDavid du Colombier
701*0b459c2cSDavid du Colombier@item -
702*0b459c2cSDavid du ColombierA ``deleted'' line in the first file that corresponds to nothing in the
703*0b459c2cSDavid du Colombiersecond file.
704*0b459c2cSDavid du Colombier@end table
705*0b459c2cSDavid du Colombier
706*0b459c2cSDavid du ColombierIf all of the changes in a hunk are insertions, the lines of
707*0b459c2cSDavid du Colombier@var{from-file} are omitted.  If all of the changes are deletions, the
708*0b459c2cSDavid du Colombierlines of @var{to-file} are omitted.
709*0b459c2cSDavid du Colombier
710*0b459c2cSDavid du Colombier@node Example Context, Less Context, Detailed Context, Context Format
711*0b459c2cSDavid du Colombier@subsubsection An Example of Context Format
712*0b459c2cSDavid du Colombier
713*0b459c2cSDavid du ColombierHere is the output of @samp{diff -c lao tzu} (@pxref{Sample diff Input},
714*0b459c2cSDavid du Colombierfor the complete contents of the two files).  Notice that up to three
715*0b459c2cSDavid du Colombierlines that are not different are shown around each line that is
716*0b459c2cSDavid du Colombierdifferent; they are the context lines.  Also notice that the first two
717*0b459c2cSDavid du Colombierhunks have run together, because their contents overlap.
718*0b459c2cSDavid du Colombier
719*0b459c2cSDavid du Colombier@example
720*0b459c2cSDavid du Colombier*** lao	Sat Jan 26 23:30:39 1991
721*0b459c2cSDavid du Colombier--- tzu	Sat Jan 26 23:30:50 1991
722*0b459c2cSDavid du Colombier***************
723*0b459c2cSDavid du Colombier*** 1,7 ****
724*0b459c2cSDavid du Colombier- The Way that can be told of is not the eternal Way;
725*0b459c2cSDavid du Colombier- The name that can be named is not the eternal name.
726*0b459c2cSDavid du Colombier  The Nameless is the origin of Heaven and Earth;
727*0b459c2cSDavid du Colombier! The Named is the mother of all things.
728*0b459c2cSDavid du Colombier  Therefore let there always be non-being,
729*0b459c2cSDavid du Colombier    so we may see their subtlety,
730*0b459c2cSDavid du Colombier  And let there always be being,
731*0b459c2cSDavid du Colombier--- 1,6 ----
732*0b459c2cSDavid du Colombier  The Nameless is the origin of Heaven and Earth;
733*0b459c2cSDavid du Colombier! The named is the mother of all things.
734*0b459c2cSDavid du Colombier!
735*0b459c2cSDavid du Colombier  Therefore let there always be non-being,
736*0b459c2cSDavid du Colombier    so we may see their subtlety,
737*0b459c2cSDavid du Colombier  And let there always be being,
738*0b459c2cSDavid du Colombier***************
739*0b459c2cSDavid du Colombier*** 9,11 ****
740*0b459c2cSDavid du Colombier--- 8,13 ----
741*0b459c2cSDavid du Colombier  The two are the same,
742*0b459c2cSDavid du Colombier  But after they are produced,
743*0b459c2cSDavid du Colombier    they have different names.
744*0b459c2cSDavid du Colombier+ They both may be called deep and profound.
745*0b459c2cSDavid du Colombier+ Deeper and more profound,
746*0b459c2cSDavid du Colombier+ The door of all subtleties!
747*0b459c2cSDavid du Colombier@end example
748*0b459c2cSDavid du Colombier
749*0b459c2cSDavid du Colombier@node Less Context, , Example Context, Context Format
750*0b459c2cSDavid du Colombier@subsubsection An Example of Context Format with Less Context
751*0b459c2cSDavid du Colombier
752*0b459c2cSDavid du ColombierHere is the output of @samp{diff --context=1 lao tzu} (@pxref{Sample
753*0b459c2cSDavid du Colombierdiff Input}, for the complete contents of the two files).  Notice that
754*0b459c2cSDavid du Colombierat most one context line is reported here.
755*0b459c2cSDavid du Colombier
756*0b459c2cSDavid du Colombier@example
757*0b459c2cSDavid du Colombier*** lao	Sat Jan 26 23:30:39 1991
758*0b459c2cSDavid du Colombier--- tzu	Sat Jan 26 23:30:50 1991
759*0b459c2cSDavid du Colombier***************
760*0b459c2cSDavid du Colombier*** 1,5 ****
761*0b459c2cSDavid du Colombier- The Way that can be told of is not the eternal Way;
762*0b459c2cSDavid du Colombier- The name that can be named is not the eternal name.
763*0b459c2cSDavid du Colombier  The Nameless is the origin of Heaven and Earth;
764*0b459c2cSDavid du Colombier! The Named is the mother of all things.
765*0b459c2cSDavid du Colombier  Therefore let there always be non-being,
766*0b459c2cSDavid du Colombier--- 1,4 ----
767*0b459c2cSDavid du Colombier  The Nameless is the origin of Heaven and Earth;
768*0b459c2cSDavid du Colombier! The named is the mother of all things.
769*0b459c2cSDavid du Colombier!
770*0b459c2cSDavid du Colombier  Therefore let there always be non-being,
771*0b459c2cSDavid du Colombier***************
772*0b459c2cSDavid du Colombier*** 11 ****
773*0b459c2cSDavid du Colombier--- 10,13 ----
774*0b459c2cSDavid du Colombier    they have different names.
775*0b459c2cSDavid du Colombier+ They both may be called deep and profound.
776*0b459c2cSDavid du Colombier+ Deeper and more profound,
777*0b459c2cSDavid du Colombier+ The door of all subtleties!
778*0b459c2cSDavid du Colombier@end example
779*0b459c2cSDavid du Colombier
780*0b459c2cSDavid du Colombier@node Unified Format, Sections, Context Format, Context
781*0b459c2cSDavid du Colombier@subsection Unified Format
782*0b459c2cSDavid du Colombier@cindex unified output format
783*0b459c2cSDavid du Colombier@cindex @samp{+-} output format
784*0b459c2cSDavid du Colombier
785*0b459c2cSDavid du ColombierThe unified output format is a variation on the context format that is
786*0b459c2cSDavid du Colombiermore compact because it omits redundant context lines.  To select this
787*0b459c2cSDavid du Colombieroutput format, use the @samp{-U @var{lines}},
788*0b459c2cSDavid du Colombier@samp{--unified@r{[}=@var{lines}@r{]}}, or @samp{-u}
789*0b459c2cSDavid du Colombieroption.  The argument @var{lines} is the number of lines of context to
790*0b459c2cSDavid du Colombiershow.  When it is not given, it defaults to three.
791*0b459c2cSDavid du Colombier
792*0b459c2cSDavid du ColombierAt present, only GNU @code{diff} can produce this format and only GNU
793*0b459c2cSDavid du Colombier@code{patch} can automatically apply diffs in this format.  For proper
794*0b459c2cSDavid du Colombieroperation, @code{patch} typically needs at least two lines of context.
795*0b459c2cSDavid du Colombier
796*0b459c2cSDavid du Colombier@menu
797*0b459c2cSDavid du Colombier* Detailed Unified::	A detailed description of unified format.
798*0b459c2cSDavid du Colombier* Example Unified::	Sample output in unified format.
799*0b459c2cSDavid du Colombier@end menu
800*0b459c2cSDavid du Colombier
801*0b459c2cSDavid du Colombier@node Detailed Unified, Example Unified, , Unified Format
802*0b459c2cSDavid du Colombier@subsubsection Detailed Description of Unified Format
803*0b459c2cSDavid du Colombier
804*0b459c2cSDavid du ColombierThe unified output format starts with a two-line header, which looks
805*0b459c2cSDavid du Colombierlike this:
806*0b459c2cSDavid du Colombier
807*0b459c2cSDavid du Colombier@example
808*0b459c2cSDavid du Colombier--- @var{from-file} @var{from-file-modification-time}
809*0b459c2cSDavid du Colombier+++ @var{to-file} @var{to-file-modification-time}
810*0b459c2cSDavid du Colombier@end example
811*0b459c2cSDavid du Colombier
812*0b459c2cSDavid du Colombier@noindent
813*0b459c2cSDavid du ColombierYou can change the header's content with the @samp{-L @var{label}} or
814*0b459c2cSDavid du Colombier@samp{--label=@var{label}} option; see @xref{Alternate Names}.
815*0b459c2cSDavid du Colombier
816*0b459c2cSDavid du ColombierNext come one or more hunks of differences; each hunk shows one area
817*0b459c2cSDavid du Colombierwhere the files differ.  Unified format hunks look like this:
818*0b459c2cSDavid du Colombier
819*0b459c2cSDavid du Colombier@example
820*0b459c2cSDavid du Colombier@@@@ @var{from-file-range} @var{to-file-range} @@@@
821*0b459c2cSDavid du Colombier @var{line-from-either-file}
822*0b459c2cSDavid du Colombier @var{line-from-either-file}@dots{}
823*0b459c2cSDavid du Colombier@end example
824*0b459c2cSDavid du Colombier
825*0b459c2cSDavid du ColombierThe lines common to both files begin with a space character.  The lines
826*0b459c2cSDavid du Colombierthat actually differ between the two files have one of the following
827*0b459c2cSDavid du Colombierindicator characters in the left column:
828*0b459c2cSDavid du Colombier
829*0b459c2cSDavid du Colombier@table @samp
830*0b459c2cSDavid du Colombier@item +
831*0b459c2cSDavid du ColombierA line was added here to the first file.
832*0b459c2cSDavid du Colombier
833*0b459c2cSDavid du Colombier@item -
834*0b459c2cSDavid du ColombierA line was removed here from the first file.
835*0b459c2cSDavid du Colombier@end table
836*0b459c2cSDavid du Colombier
837*0b459c2cSDavid du Colombier@node Example Unified, , Detailed Unified, Unified Format
838*0b459c2cSDavid du Colombier@subsubsection An Example of Unified Format
839*0b459c2cSDavid du Colombier
840*0b459c2cSDavid du ColombierHere is the output of the command @samp{diff -u lao tzu}
841*0b459c2cSDavid du Colombier(@pxref{Sample diff Input}, for the complete contents of the two files):
842*0b459c2cSDavid du Colombier
843*0b459c2cSDavid du Colombier@example
844*0b459c2cSDavid du Colombier--- lao	Sat Jan 26 23:30:39 1991
845*0b459c2cSDavid du Colombier+++ tzu	Sat Jan 26 23:30:50 1991
846*0b459c2cSDavid du Colombier@@@@ -1,7 +1,6 @@@@
847*0b459c2cSDavid du Colombier-The Way that can be told of is not the eternal Way;
848*0b459c2cSDavid du Colombier-The name that can be named is not the eternal name.
849*0b459c2cSDavid du Colombier The Nameless is the origin of Heaven and Earth;
850*0b459c2cSDavid du Colombier-The Named is the mother of all things.
851*0b459c2cSDavid du Colombier+The named is the mother of all things.
852*0b459c2cSDavid du Colombier+
853*0b459c2cSDavid du Colombier Therefore let there always be non-being,
854*0b459c2cSDavid du Colombier   so we may see their subtlety,
855*0b459c2cSDavid du Colombier And let there always be being,
856*0b459c2cSDavid du Colombier@@@@ -9,3 +8,6 @@@@
857*0b459c2cSDavid du Colombier The two are the same,
858*0b459c2cSDavid du Colombier But after they are produced,
859*0b459c2cSDavid du Colombier   they have different names.
860*0b459c2cSDavid du Colombier+They both may be called deep and profound.
861*0b459c2cSDavid du Colombier+Deeper and more profound,
862*0b459c2cSDavid du Colombier+The door of all subtleties!
863*0b459c2cSDavid du Colombier@end example
864*0b459c2cSDavid du Colombier
865*0b459c2cSDavid du Colombier@node Sections, Alternate Names, Unified Format, Context
866*0b459c2cSDavid du Colombier@subsection Showing Which Sections Differences Are in
867*0b459c2cSDavid du Colombier@cindex headings
868*0b459c2cSDavid du Colombier@cindex section headings
869*0b459c2cSDavid du Colombier
870*0b459c2cSDavid du ColombierSometimes you might want to know which part of the files each change
871*0b459c2cSDavid du Colombierfalls in.  If the files are source code, this could mean which function
872*0b459c2cSDavid du Colombierwas changed.  If the files are documents, it could mean which chapter or
873*0b459c2cSDavid du Colombierappendix was changed.  GNU @code{diff} can show this by displaying the
874*0b459c2cSDavid du Colombiernearest section heading line that precedes the differing lines.  Which
875*0b459c2cSDavid du Colombierlines are ``section headings'' is determined by a regular expression.
876*0b459c2cSDavid du Colombier
877*0b459c2cSDavid du Colombier@menu
878*0b459c2cSDavid du Colombier* Specified Headings::	Showing headings that match regular expressions.
879*0b459c2cSDavid du Colombier* C Function Headings::	Showing headings of C functions.
880*0b459c2cSDavid du Colombier@end menu
881*0b459c2cSDavid du Colombier
882*0b459c2cSDavid du Colombier@node Specified Headings, C Function Headings, , Sections
883*0b459c2cSDavid du Colombier@subsubsection Showing Lines That Match Regular Expressions
884*0b459c2cSDavid du Colombier@cindex specified headings
885*0b459c2cSDavid du Colombier@cindex regular expression matching headings
886*0b459c2cSDavid du Colombier
887*0b459c2cSDavid du ColombierTo show in which sections differences occur for files that are not
888*0b459c2cSDavid du Colombiersource code for C or similar languages, use the @samp{-F @var{regexp}}
889*0b459c2cSDavid du Colombieror @samp{--show-function-line=@var{regexp}} option.  @code{diff}
890*0b459c2cSDavid du Colombierconsiders lines that match the argument @var{regexp} to be the beginning
891*0b459c2cSDavid du Colombierof a section of the file.  Here are suggested regular expressions for
892*0b459c2cSDavid du Colombiersome common languages:
893*0b459c2cSDavid du Colombier
894*0b459c2cSDavid du Colombier@c Please add to this list, e.g. Fortran, Pascal.
895*0b459c2cSDavid du Colombier@table @samp
896*0b459c2cSDavid du Colombier@item ^[A-Za-z_]
897*0b459c2cSDavid du ColombierC, C++, Prolog
898*0b459c2cSDavid du Colombier@item ^(
899*0b459c2cSDavid du ColombierLisp
900*0b459c2cSDavid du Colombier@item ^@@\(chapter\|appendix\|unnumbered\|chapheading\)
901*0b459c2cSDavid du ColombierTexinfo
902*0b459c2cSDavid du Colombier@end table
903*0b459c2cSDavid du Colombier
904*0b459c2cSDavid du ColombierThis option does not automatically select an output format; in order to
905*0b459c2cSDavid du Colombieruse it, you must select the context format (@pxref{Context Format}) or
906*0b459c2cSDavid du Colombierunified format (@pxref{Unified Format}).  In other output formats it
907*0b459c2cSDavid du Colombierhas no effect.
908*0b459c2cSDavid du Colombier
909*0b459c2cSDavid du ColombierThe @samp{-F} and @samp{--show-function-line} options find the nearest
910*0b459c2cSDavid du Colombierunchanged line that precedes each hunk of differences and matches the
911*0b459c2cSDavid du Colombiergiven regular expression.  Then they add that line to the end of the
912*0b459c2cSDavid du Colombierline of asterisks in the context format, or to the @samp{@@@@} line in
913*0b459c2cSDavid du Colombierunified format.  If no matching line exists, they leave the output for
914*0b459c2cSDavid du Colombierthat hunk unchanged.  If that line is more than 40 characters long, they
915*0b459c2cSDavid du Colombieroutput only the first 40 characters.  You can specify more than one
916*0b459c2cSDavid du Colombierregular expression for such lines; @code{diff} tries to match each line
917*0b459c2cSDavid du Colombieragainst each regular expression, starting with the last one given.  This
918*0b459c2cSDavid du Colombiermeans that you can use @samp{-p} and @samp{-F} together, if you wish.
919*0b459c2cSDavid du Colombier
920*0b459c2cSDavid du Colombier@node C Function Headings, , Specified Headings, Sections
921*0b459c2cSDavid du Colombier@subsubsection Showing C Function Headings
922*0b459c2cSDavid du Colombier@cindex C function headings
923*0b459c2cSDavid du Colombier@cindex function headings, C
924*0b459c2cSDavid du Colombier
925*0b459c2cSDavid du ColombierTo show in which functions differences occur for C and similar
926*0b459c2cSDavid du Colombierlanguages, you can use the @samp{-p} or @samp{--show-c-function} option.
927*0b459c2cSDavid du ColombierThis option automatically defaults to the context output format
928*0b459c2cSDavid du Colombier(@pxref{Context Format}), with the default number of lines of context.
929*0b459c2cSDavid du ColombierYou can override that number with @samp{-C @var{lines}} elsewhere in the
930*0b459c2cSDavid du Colombiercommand line.  You can override both the format and the number with
931*0b459c2cSDavid du Colombier@samp{-U @var{lines}} elsewhere in the command line.
932*0b459c2cSDavid du Colombier
933*0b459c2cSDavid du ColombierThe @samp{-p} and @samp{--show-c-function} options are equivalent to
934*0b459c2cSDavid du Colombier@samp{-F'^[_a-zA-Z$]'} if the unified format is specified, otherwise
935*0b459c2cSDavid du Colombier@samp{-c -F'^[_a-zA-Z$]'} (@pxref{Specified Headings}).  GNU @code{diff}
936*0b459c2cSDavid du Colombierprovides them for the sake of convenience.
937*0b459c2cSDavid du Colombier
938*0b459c2cSDavid du Colombier@node Alternate Names, , Sections, Context
939*0b459c2cSDavid du Colombier@subsection Showing Alternate File Names
940*0b459c2cSDavid du Colombier@cindex alternate file names
941*0b459c2cSDavid du Colombier@cindex file name alternates
942*0b459c2cSDavid du Colombier
943*0b459c2cSDavid du ColombierIf you are comparing two files that have meaningless or uninformative
944*0b459c2cSDavid du Colombiernames, you might want @code{diff} to show alternate names in the header
945*0b459c2cSDavid du Colombierof the context and unified output formats.  To do this, use the @samp{-L
946*0b459c2cSDavid du Colombier@var{label}} or @samp{--label=@var{label}} option.  The first time
947*0b459c2cSDavid du Colombieryou give this option, its argument replaces the name and date of the
948*0b459c2cSDavid du Colombierfirst file in the header; the second time, its argument replaces the
949*0b459c2cSDavid du Colombiername and date of the second file.  If you give this option more than
950*0b459c2cSDavid du Colombiertwice, @code{diff} reports an error.  The @samp{-L} option does not
951*0b459c2cSDavid du Colombieraffect the file names in the @code{pr} header when the @samp{-l} or
952*0b459c2cSDavid du Colombier@samp{--paginate} option is used (@pxref{Pagination}).
953*0b459c2cSDavid du Colombier
954*0b459c2cSDavid du ColombierHere are the first two lines of the output from @samp{diff -C2
955*0b459c2cSDavid du Colombier-Loriginal -Lmodified lao tzu}:
956*0b459c2cSDavid du Colombier
957*0b459c2cSDavid du Colombier@example
958*0b459c2cSDavid du Colombier*** original
959*0b459c2cSDavid du Colombier--- modified
960*0b459c2cSDavid du Colombier@end example
961*0b459c2cSDavid du Colombier
962*0b459c2cSDavid du Colombier@node Side by Side, Scripts, Context, Output Formats
963*0b459c2cSDavid du Colombier@section Showing Differences Side by Side
964*0b459c2cSDavid du Colombier@cindex side by side
965*0b459c2cSDavid du Colombier@cindex two-column output
966*0b459c2cSDavid du Colombier@cindex columnar output
967*0b459c2cSDavid du Colombier
968*0b459c2cSDavid du Colombier@code{diff} can produce a side by side difference listing of two files.
969*0b459c2cSDavid du ColombierThe files are listed in two columns with a gutter between them.  The
970*0b459c2cSDavid du Colombiergutter contains one of the following markers:
971*0b459c2cSDavid du Colombier
972*0b459c2cSDavid du Colombier@table @asis
973*0b459c2cSDavid du Colombier@item white space
974*0b459c2cSDavid du ColombierThe corresponding lines are in common.  That is, either the lines are
975*0b459c2cSDavid du Colombieridentical, or the difference is ignored because of one of the
976*0b459c2cSDavid du Colombier@samp{--ignore} options (@pxref{White Space}).
977*0b459c2cSDavid du Colombier
978*0b459c2cSDavid du Colombier@item @samp{|}
979*0b459c2cSDavid du ColombierThe corresponding lines differ, and they are either both complete
980*0b459c2cSDavid du Colombieror both incomplete.
981*0b459c2cSDavid du Colombier
982*0b459c2cSDavid du Colombier@item @samp{<}
983*0b459c2cSDavid du ColombierThe files differ and only the first file contains the line.
984*0b459c2cSDavid du Colombier
985*0b459c2cSDavid du Colombier@item @samp{>}
986*0b459c2cSDavid du ColombierThe files differ and only the second file contains the line.
987*0b459c2cSDavid du Colombier
988*0b459c2cSDavid du Colombier@item @samp{(}
989*0b459c2cSDavid du ColombierOnly the first file contains the line, but the difference is ignored.
990*0b459c2cSDavid du Colombier
991*0b459c2cSDavid du Colombier@item @samp{)}
992*0b459c2cSDavid du ColombierOnly the second file contains the line, but the difference is ignored.
993*0b459c2cSDavid du Colombier
994*0b459c2cSDavid du Colombier@item @samp{\}
995*0b459c2cSDavid du ColombierThe corresponding lines differ, and only the first line is incomplete.
996*0b459c2cSDavid du Colombier
997*0b459c2cSDavid du Colombier@item @samp{/}
998*0b459c2cSDavid du ColombierThe corresponding lines differ, and only the second line is incomplete.
999*0b459c2cSDavid du Colombier@end table
1000*0b459c2cSDavid du Colombier
1001*0b459c2cSDavid du ColombierNormally, an output line is incomplete if and only if the lines that it
1002*0b459c2cSDavid du Colombiercontains are incomplete; @xref{Incomplete Lines}.  However, when an
1003*0b459c2cSDavid du Colombieroutput line represents two differing lines, one might be incomplete
1004*0b459c2cSDavid du Colombierwhile the other is not.  In this case, the output line is complete,
1005*0b459c2cSDavid du Colombierbut its the gutter is marked @samp{\} if the first line is incomplete,
1006*0b459c2cSDavid du Colombier@samp{/} if the second line is.
1007*0b459c2cSDavid du Colombier
1008*0b459c2cSDavid du ColombierSide by side format is sometimes easiest to read, but it has limitations.
1009*0b459c2cSDavid du ColombierIt generates much wider output than usual, and truncates lines that are
1010*0b459c2cSDavid du Colombiertoo long to fit.  Also, it relies on lining up output more heavily than
1011*0b459c2cSDavid du Colombierusual, so its output looks particularly bad if you use varying
1012*0b459c2cSDavid du Colombierwidth fonts, nonstandard tab stops, or nonprinting characters.
1013*0b459c2cSDavid du Colombier
1014*0b459c2cSDavid du ColombierYou can use the @code{sdiff} command to interactively merge side by side
1015*0b459c2cSDavid du Colombierdifferences.  @xref{Interactive Merging}, for more information on merging files.
1016*0b459c2cSDavid du Colombier
1017*0b459c2cSDavid du Colombier@menu
1018*0b459c2cSDavid du Colombier* Side by Side Format::		Controlling side by side output format.
1019*0b459c2cSDavid du Colombier* Example Side by Side::	Sample side by side output.
1020*0b459c2cSDavid du Colombier@end menu
1021*0b459c2cSDavid du Colombier
1022*0b459c2cSDavid du Colombier@node Side by Side Format, Example Side by Side, , Side by Side
1023*0b459c2cSDavid du Colombier@section Controlling Side by Side Format
1024*0b459c2cSDavid du Colombier@cindex side by side format
1025*0b459c2cSDavid du Colombier
1026*0b459c2cSDavid du ColombierThe @samp{-y} or @samp{--side-by-side} option selects side by side
1027*0b459c2cSDavid du Colombierformat.  Because side by side output lines contain two input lines, they
1028*0b459c2cSDavid du Colombierare wider than usual.  They are normally 130 columns, which can fit onto
1029*0b459c2cSDavid du Colombiera traditional printer line.  You can set the length of output lines with
1030*0b459c2cSDavid du Colombierthe @samp{-W @var{columns}} or @samp{--width=@var{columns}} option.  The
1031*0b459c2cSDavid du Colombieroutput line is split into two halves of equal length, separated by a
1032*0b459c2cSDavid du Colombiersmall gutter to mark differences; the right half is aligned to a tab
1033*0b459c2cSDavid du Colombierstop so that tabs line up.  Input lines that are too long to fit in half
1034*0b459c2cSDavid du Colombierof an output line are truncated for output.
1035*0b459c2cSDavid du Colombier
1036*0b459c2cSDavid du ColombierThe @samp{--left-column} option prints only the left column of two
1037*0b459c2cSDavid du Colombiercommon lines.  The @samp{--suppress-common-lines} option suppresses
1038*0b459c2cSDavid du Colombiercommon lines entirely.
1039*0b459c2cSDavid du Colombier
1040*0b459c2cSDavid du Colombier@node Example Side by Side, , Side by Side Format, Side by Side
1041*0b459c2cSDavid du Colombier@subsection An Example of Side by Side Format
1042*0b459c2cSDavid du Colombier
1043*0b459c2cSDavid du ColombierHere is the output of the command @samp{diff -y -W 72 lao tzu}
1044*0b459c2cSDavid du Colombier(@pxref{Sample diff Input}, for the complete contents of the two files).
1045*0b459c2cSDavid du Colombier
1046*0b459c2cSDavid du Colombier@example
1047*0b459c2cSDavid du ColombierThe Way that can be told of is n   <
1048*0b459c2cSDavid du ColombierThe name that can be named is no   <
1049*0b459c2cSDavid du ColombierThe Nameless is the origin of He        The Nameless is the origin of He
1050*0b459c2cSDavid du ColombierThe Named is the mother of all t   |    The named is the mother of all t
1051*0b459c2cSDavid du Colombier                                   >
1052*0b459c2cSDavid du ColombierTherefore let there always be no        Therefore let there always be no
1053*0b459c2cSDavid du Colombier  so we may see their subtlety,           so we may see their subtlety,
1054*0b459c2cSDavid du ColombierAnd let there always be being,          And let there always be being,
1055*0b459c2cSDavid du Colombier  so we may see their outcome.            so we may see their outcome.
1056*0b459c2cSDavid du ColombierThe two are the same,                   The two are the same,
1057*0b459c2cSDavid du ColombierBut after they are produced,            But after they are produced,
1058*0b459c2cSDavid du Colombier  they have different names.              they have different names.
1059*0b459c2cSDavid du Colombier                                   >    They both may be called deep and
1060*0b459c2cSDavid du Colombier                                   >    Deeper and more profound,
1061*0b459c2cSDavid du Colombier                                   >    The door of all subtleties!
1062*0b459c2cSDavid du Colombier@end example
1063*0b459c2cSDavid du Colombier
1064*0b459c2cSDavid du Colombier@node Scripts, If-then-else, Side by Side, Output Formats
1065*0b459c2cSDavid du Colombier@section Making Edit Scripts
1066*0b459c2cSDavid du Colombier@cindex script output formats
1067*0b459c2cSDavid du Colombier
1068*0b459c2cSDavid du ColombierSeveral output modes produce command scripts for editing @var{from-file}
1069*0b459c2cSDavid du Colombierto produce @var{to-file}.
1070*0b459c2cSDavid du Colombier
1071*0b459c2cSDavid du Colombier@menu
1072*0b459c2cSDavid du Colombier* ed Scripts::		Using @code{diff} to produce commands for @code{ed}.
1073*0b459c2cSDavid du Colombier* Forward ed::		Making forward @code{ed} scripts.
1074*0b459c2cSDavid du Colombier* RCS::			A special @code{diff} output format used by RCS.
1075*0b459c2cSDavid du Colombier@end menu
1076*0b459c2cSDavid du Colombier
1077*0b459c2cSDavid du Colombier@node ed Scripts, Forward ed, , Scripts
1078*0b459c2cSDavid du Colombier@subsection @code{ed} Scripts
1079*0b459c2cSDavid du Colombier@cindex @code{ed} script output format
1080*0b459c2cSDavid du Colombier
1081*0b459c2cSDavid du Colombier@code{diff} can produce commands that direct the @code{ed} text editor
1082*0b459c2cSDavid du Colombierto change the first file into the second file.  Long ago, this was the
1083*0b459c2cSDavid du Colombieronly output mode that was suitable for editing one file into another
1084*0b459c2cSDavid du Colombierautomatically; today, with @code{patch}, it is almost obsolete.  Use the
1085*0b459c2cSDavid du Colombier@samp{-e} or @samp{--ed} option to select this output format.
1086*0b459c2cSDavid du Colombier
1087*0b459c2cSDavid du ColombierLike the normal format (@pxref{Normal}), this output format does not
1088*0b459c2cSDavid du Colombiershow any context; unlike the normal format, it does not include the
1089*0b459c2cSDavid du Colombierinformation necessary to apply the diff in reverse (to produce the first
1090*0b459c2cSDavid du Colombierfile if all you have is the second file and the diff).
1091*0b459c2cSDavid du Colombier
1092*0b459c2cSDavid du ColombierIf the file @file{d} contains the output of @samp{diff -e old new}, then
1093*0b459c2cSDavid du Colombierthe command @samp{(cat d && echo w) | ed - old} edits @file{old} to make
1094*0b459c2cSDavid du Colombierit a copy of @file{new}.  More generally, if @file{d1}, @file{d2},
1095*0b459c2cSDavid du Colombier@dots{}, @file{dN} contain the outputs of @samp{diff -e old new1},
1096*0b459c2cSDavid du Colombier@samp{diff -e new1 new2}, @dots{}, @samp{diff -e newN-1 newN},
1097*0b459c2cSDavid du Colombierrespectively, then the command @samp{(cat d1 d2 @dots{} dN && echo w) |
1098*0b459c2cSDavid du Colombiered - old} edits @file{old} to make it a copy of @file{newN}.
1099*0b459c2cSDavid du Colombier
1100*0b459c2cSDavid du Colombier@menu
1101*0b459c2cSDavid du Colombier* Detailed ed::		A detailed description of @code{ed} format.
1102*0b459c2cSDavid du Colombier* Example ed::		A sample @code{ed} script.
1103*0b459c2cSDavid du Colombier@end menu
1104*0b459c2cSDavid du Colombier
1105*0b459c2cSDavid du Colombier@node Detailed ed, Example ed, , ed Scripts
1106*0b459c2cSDavid du Colombier@subsubsection Detailed Description of @code{ed} Format
1107*0b459c2cSDavid du Colombier
1108*0b459c2cSDavid du ColombierThe @code{ed} output format consists of one or more hunks of
1109*0b459c2cSDavid du Colombierdifferences.  The changes closest to the ends of the files come first so
1110*0b459c2cSDavid du Colombierthat commands that change the number of lines do not affect how
1111*0b459c2cSDavid du Colombier@code{ed} interprets line numbers in succeeding commands.  @code{ed}
1112*0b459c2cSDavid du Colombierformat hunks look like this:
1113*0b459c2cSDavid du Colombier
1114*0b459c2cSDavid du Colombier@example
1115*0b459c2cSDavid du Colombier@var{change-command}
1116*0b459c2cSDavid du Colombier@var{to-file-line}
1117*0b459c2cSDavid du Colombier@var{to-file-line}@dots{}
1118*0b459c2cSDavid du Colombier.
1119*0b459c2cSDavid du Colombier@end example
1120*0b459c2cSDavid du Colombier
1121*0b459c2cSDavid du ColombierBecause @code{ed} uses a single period on a line to indicate the end of
1122*0b459c2cSDavid du Colombierinput, GNU @code{diff} protects lines of changes that contain a single
1123*0b459c2cSDavid du Colombierperiod on a line by writing two periods instead, then writing a
1124*0b459c2cSDavid du Colombiersubsequent @code{ed} command to change the two periods into one.  The
1125*0b459c2cSDavid du Colombier@code{ed} format cannot represent an incomplete line, so if the second
1126*0b459c2cSDavid du Colombierfile ends in a changed incomplete line, @code{diff} reports an error and
1127*0b459c2cSDavid du Colombierthen pretends that a newline was appended.
1128*0b459c2cSDavid du Colombier
1129*0b459c2cSDavid du ColombierThere are three types of change commands.  Each consists of a line
1130*0b459c2cSDavid du Colombiernumber or comma-separated range of lines in the first file and a single
1131*0b459c2cSDavid du Colombiercharacter indicating the kind of change to make.  All line numbers are
1132*0b459c2cSDavid du Colombierthe original line numbers in the file.  The types of change commands
1133*0b459c2cSDavid du Colombierare:
1134*0b459c2cSDavid du Colombier
1135*0b459c2cSDavid du Colombier@table @samp
1136*0b459c2cSDavid du Colombier@item @var{l}a
1137*0b459c2cSDavid du ColombierAdd text from the second file after line @var{l} in the first file.  For
1138*0b459c2cSDavid du Colombierexample, @samp{8a} means to add the following lines after line 8 of file
1139*0b459c2cSDavid du Colombier1.
1140*0b459c2cSDavid du Colombier
1141*0b459c2cSDavid du Colombier@item @var{r}c
1142*0b459c2cSDavid du ColombierReplace the lines in range @var{r} in the first file with the following
1143*0b459c2cSDavid du Colombierlines.  Like a combined add and delete, but more compact.  For example,
1144*0b459c2cSDavid du Colombier@samp{5,7c} means change lines 5--7 of file 1 to read as the text file
1145*0b459c2cSDavid du Colombier2.
1146*0b459c2cSDavid du Colombier
1147*0b459c2cSDavid du Colombier@item @var{r}d
1148*0b459c2cSDavid du ColombierDelete the lines in range @var{r} from the first file.  For example,
1149*0b459c2cSDavid du Colombier@samp{5,7d} means delete lines 5--7 of file 1.
1150*0b459c2cSDavid du Colombier@end table
1151*0b459c2cSDavid du Colombier
1152*0b459c2cSDavid du Colombier@node Example ed, , Detailed ed, ed Scripts
1153*0b459c2cSDavid du Colombier@subsubsection Example @code{ed} Script
1154*0b459c2cSDavid du Colombier
1155*0b459c2cSDavid du ColombierHere is the output of @samp{diff -e lao tzu} (@pxref{Sample
1156*0b459c2cSDavid du Colombierdiff Input}, for the complete contents of the two files):
1157*0b459c2cSDavid du Colombier
1158*0b459c2cSDavid du Colombier@example
1159*0b459c2cSDavid du Colombier11a
1160*0b459c2cSDavid du ColombierThey both may be called deep and profound.
1161*0b459c2cSDavid du ColombierDeeper and more profound,
1162*0b459c2cSDavid du ColombierThe door of all subtleties!
1163*0b459c2cSDavid du Colombier.
1164*0b459c2cSDavid du Colombier4c
1165*0b459c2cSDavid du ColombierThe named is the mother of all things.
1166*0b459c2cSDavid du Colombier
1167*0b459c2cSDavid du Colombier.
1168*0b459c2cSDavid du Colombier1,2d
1169*0b459c2cSDavid du Colombier@end example
1170*0b459c2cSDavid du Colombier
1171*0b459c2cSDavid du Colombier@node Forward ed, RCS, ed Scripts, Scripts
1172*0b459c2cSDavid du Colombier@subsection Forward @code{ed} Scripts
1173*0b459c2cSDavid du Colombier@cindex forward @code{ed} script output format
1174*0b459c2cSDavid du Colombier
1175*0b459c2cSDavid du Colombier@code{diff} can produce output that is like an @code{ed} script, but
1176*0b459c2cSDavid du Colombierwith hunks in forward (front to back) order.  The format of the commands
1177*0b459c2cSDavid du Colombieris also changed slightly: command characters precede the lines they
1178*0b459c2cSDavid du Colombiermodify, spaces separate line numbers in ranges, and no attempt is made
1179*0b459c2cSDavid du Colombierto disambiguate hunk lines consisting of a single period.  Like
1180*0b459c2cSDavid du Colombier@code{ed} format, forward @code{ed} format cannot represent incomplete
1181*0b459c2cSDavid du Colombierlines.
1182*0b459c2cSDavid du Colombier
1183*0b459c2cSDavid du ColombierForward @code{ed} format is not very useful, because neither @code{ed}
1184*0b459c2cSDavid du Colombiernor @code{patch} can apply diffs in this format.  It exists mainly for
1185*0b459c2cSDavid du Colombiercompatibility with older versions of @code{diff}.  Use the @samp{-f} or
1186*0b459c2cSDavid du Colombier@samp{--forward-ed} option to select it.
1187*0b459c2cSDavid du Colombier
1188*0b459c2cSDavid du Colombier@node RCS, , Forward ed, Scripts
1189*0b459c2cSDavid du Colombier@subsection RCS Scripts
1190*0b459c2cSDavid du Colombier@cindex RCS script output format
1191*0b459c2cSDavid du Colombier
1192*0b459c2cSDavid du ColombierThe RCS output format is designed specifically for use by the Revision
1193*0b459c2cSDavid du ColombierControl System, which is a set of free programs used for organizing
1194*0b459c2cSDavid du Colombierdifferent versions and systems of files.  Use the @samp{-n} or
1195*0b459c2cSDavid du Colombier@samp{--rcs} option to select this output format.  It is like the
1196*0b459c2cSDavid du Colombierforward @code{ed} format (@pxref{Forward ed}), but it can represent
1197*0b459c2cSDavid du Colombierarbitrary changes to the contents of a file because it avoids the
1198*0b459c2cSDavid du Colombierforward @code{ed} format's problems with lines consisting of a single
1199*0b459c2cSDavid du Colombierperiod and with incomplete lines.  Instead of ending text sections with
1200*0b459c2cSDavid du Colombiera line consisting of a single period, each command specifies the number
1201*0b459c2cSDavid du Colombierof lines it affects; a combination of the @samp{a} and @samp{d}
1202*0b459c2cSDavid du Colombiercommands are used instead of @samp{c}.  Also, if the second file ends
1203*0b459c2cSDavid du Colombierin a changed incomplete line, then the output also ends in an
1204*0b459c2cSDavid du Colombierincomplete line.
1205*0b459c2cSDavid du Colombier
1206*0b459c2cSDavid du ColombierHere is the output of @samp{diff -n lao tzu} (@pxref{Sample
1207*0b459c2cSDavid du Colombierdiff Input}, for the complete contents of the two files):
1208*0b459c2cSDavid du Colombier
1209*0b459c2cSDavid du Colombier@example
1210*0b459c2cSDavid du Colombierd1 2
1211*0b459c2cSDavid du Colombierd4 1
1212*0b459c2cSDavid du Colombiera4 2
1213*0b459c2cSDavid du ColombierThe named is the mother of all things.
1214*0b459c2cSDavid du Colombier
1215*0b459c2cSDavid du Colombiera11 3
1216*0b459c2cSDavid du ColombierThey both may be called deep and profound.
1217*0b459c2cSDavid du ColombierDeeper and more profound,
1218*0b459c2cSDavid du ColombierThe door of all subtleties!
1219*0b459c2cSDavid du Colombier@end example
1220*0b459c2cSDavid du Colombier
1221*0b459c2cSDavid du Colombier@node If-then-else, , Scripts, Output Formats
1222*0b459c2cSDavid du Colombier@section Merging Files with If-then-else
1223*0b459c2cSDavid du Colombier@cindex merged output format
1224*0b459c2cSDavid du Colombier@cindex if-then-else output format
1225*0b459c2cSDavid du Colombier@cindex C if-then-else output format
1226*0b459c2cSDavid du Colombier@cindex @code{ifdef} output format
1227*0b459c2cSDavid du Colombier
1228*0b459c2cSDavid du ColombierYou can use @code{diff} to merge two files of C source code.  The output
1229*0b459c2cSDavid du Colombierof @code{diff} in this format contains all the lines of both files.
1230*0b459c2cSDavid du ColombierLines common to both files are output just once; the differing parts are
1231*0b459c2cSDavid du Colombierseparated by the C preprocessor directives @code{#ifdef @var{name}} or
1232*0b459c2cSDavid du Colombier@code{#ifndef @var{name}}, @code{#else}, and @code{#endif}.  When
1233*0b459c2cSDavid du Colombiercompiling the output, you select which version to use by either defining
1234*0b459c2cSDavid du Colombieror leaving undefined the macro @var{name}.
1235*0b459c2cSDavid du Colombier
1236*0b459c2cSDavid du ColombierTo merge two files, use @code{diff} with the @samp{-D @var{name}} or
1237*0b459c2cSDavid du Colombier@samp{--ifdef=@var{name}} option.  The argument @var{name} is the C
1238*0b459c2cSDavid du Colombierpreprocessor identifier to use in the @code{#ifdef} and @code{#ifndef}
1239*0b459c2cSDavid du Colombierdirectives.
1240*0b459c2cSDavid du Colombier
1241*0b459c2cSDavid du ColombierFor example, if you change an instance of @code{wait (&s)} to
1242*0b459c2cSDavid du Colombier@code{waitpid (-1, &s, 0)} and then merge the old and new files with
1243*0b459c2cSDavid du Colombierthe @samp{--ifdef=HAVE_WAITPID} option, then the affected part of your code
1244*0b459c2cSDavid du Colombiermight look like this:
1245*0b459c2cSDavid du Colombier
1246*0b459c2cSDavid du Colombier@example
1247*0b459c2cSDavid du Colombier    do @{
1248*0b459c2cSDavid du Colombier#ifndef HAVE_WAITPID
1249*0b459c2cSDavid du Colombier        if ((w = wait (&s)) < 0  &&  errno != EINTR)
1250*0b459c2cSDavid du Colombier#else /* HAVE_WAITPID */
1251*0b459c2cSDavid du Colombier        if ((w = waitpid (-1, &s, 0)) < 0  &&  errno != EINTR)
1252*0b459c2cSDavid du Colombier#endif /* HAVE_WAITPID */
1253*0b459c2cSDavid du Colombier            return w;
1254*0b459c2cSDavid du Colombier    @} while (w != child);
1255*0b459c2cSDavid du Colombier@end example
1256*0b459c2cSDavid du Colombier
1257*0b459c2cSDavid du ColombierYou can specify formats for languages other than C by using line group
1258*0b459c2cSDavid du Colombierformats and line formats, as described in the next sections.
1259*0b459c2cSDavid du Colombier
1260*0b459c2cSDavid du Colombier@menu
1261*0b459c2cSDavid du Colombier* Line Group Formats::		Formats for general if-then-else line groups.
1262*0b459c2cSDavid du Colombier* Line Formats::		Formats for each line in a line group.
1263*0b459c2cSDavid du Colombier* Detailed If-then-else::	A detailed description of if-then-else format.
1264*0b459c2cSDavid du Colombier* Example If-then-else::	Sample if-then-else format output.
1265*0b459c2cSDavid du Colombier@end menu
1266*0b459c2cSDavid du Colombier
1267*0b459c2cSDavid du Colombier@node Line Group Formats, Line Formats, , If-then-else
1268*0b459c2cSDavid du Colombier@subsection Line Group Formats
1269*0b459c2cSDavid du Colombier@cindex line group formats
1270*0b459c2cSDavid du Colombier@cindex formats for if-then-else line groups
1271*0b459c2cSDavid du Colombier
1272*0b459c2cSDavid du ColombierLine group formats let you specify formats suitable for many
1273*0b459c2cSDavid du Colombierapplications that allow if-then-else input, including programming
1274*0b459c2cSDavid du Colombierlanguages and text formatting languages.  A line group format specifies
1275*0b459c2cSDavid du Colombierthe output format for a contiguous group of similar lines.
1276*0b459c2cSDavid du Colombier
1277*0b459c2cSDavid du ColombierFor example, the following command compares the TeX files @file{old}
1278*0b459c2cSDavid du Colombierand @file{new}, and outputs a merged file in which old regions are
1279*0b459c2cSDavid du Colombiersurrounded by @samp{\begin@{em@}}-@samp{\end@{em@}} lines, and new
1280*0b459c2cSDavid du Colombierregions are surrounded by @samp{\begin@{bf@}}-@samp{\end@{bf@}} lines.
1281*0b459c2cSDavid du Colombier
1282*0b459c2cSDavid du Colombier@example
1283*0b459c2cSDavid du Colombierdiff \
1284*0b459c2cSDavid du Colombier   --old-group-format='\begin@{em@}
1285*0b459c2cSDavid du Colombier%<\end@{em@}
1286*0b459c2cSDavid du Colombier' \
1287*0b459c2cSDavid du Colombier   --new-group-format='\begin@{bf@}
1288*0b459c2cSDavid du Colombier%>\end@{bf@}
1289*0b459c2cSDavid du Colombier' \
1290*0b459c2cSDavid du Colombier   old new
1291*0b459c2cSDavid du Colombier@end example
1292*0b459c2cSDavid du Colombier
1293*0b459c2cSDavid du ColombierThe following command is equivalent to the above example, but it is a
1294*0b459c2cSDavid du Colombierlittle more verbose, because it spells out the default line group formats.
1295*0b459c2cSDavid du Colombier
1296*0b459c2cSDavid du Colombier@example
1297*0b459c2cSDavid du Colombierdiff \
1298*0b459c2cSDavid du Colombier   --old-group-format='\begin@{em@}
1299*0b459c2cSDavid du Colombier%<\end@{em@}
1300*0b459c2cSDavid du Colombier' \
1301*0b459c2cSDavid du Colombier   --new-group-format='\begin@{bf@}
1302*0b459c2cSDavid du Colombier%>\end@{bf@}
1303*0b459c2cSDavid du Colombier' \
1304*0b459c2cSDavid du Colombier   --unchanged-group-format='%=' \
1305*0b459c2cSDavid du Colombier   --changed-group-format='\begin@{em@}
1306*0b459c2cSDavid du Colombier%<\end@{em@}
1307*0b459c2cSDavid du Colombier\begin@{bf@}
1308*0b459c2cSDavid du Colombier%>\end@{bf@}
1309*0b459c2cSDavid du Colombier' \
1310*0b459c2cSDavid du Colombier   old new
1311*0b459c2cSDavid du Colombier@end example
1312*0b459c2cSDavid du Colombier
1313*0b459c2cSDavid du ColombierHere is a more advanced example, which outputs a diff listing with
1314*0b459c2cSDavid du Colombierheaders containing line numbers in a ``plain English'' style.
1315*0b459c2cSDavid du Colombier
1316*0b459c2cSDavid du Colombier@example
1317*0b459c2cSDavid du Colombierdiff \
1318*0b459c2cSDavid du Colombier   --unchanged-group-format='' \
1319*0b459c2cSDavid du Colombier   --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
1320*0b459c2cSDavid du Colombier%<' \
1321*0b459c2cSDavid du Colombier   --new-group-format='-------- %dN line%(N=1?:s) added after %de:
1322*0b459c2cSDavid du Colombier%>' \
1323*0b459c2cSDavid du Colombier   --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
1324*0b459c2cSDavid du Colombier%<-------- to:
1325*0b459c2cSDavid du Colombier%>' \
1326*0b459c2cSDavid du Colombier   old new
1327*0b459c2cSDavid du Colombier@end example
1328*0b459c2cSDavid du Colombier
1329*0b459c2cSDavid du ColombierTo specify a line group format, use @code{diff} with one of the options
1330*0b459c2cSDavid du Colombierlisted below.  You can specify up to four line group formats, one for
1331*0b459c2cSDavid du Colombiereach kind of line group.  You should quote @var{format}, because it
1332*0b459c2cSDavid du Colombiertypically contains shell metacharacters.
1333*0b459c2cSDavid du Colombier
1334*0b459c2cSDavid du Colombier@table @samp
1335*0b459c2cSDavid du Colombier@item --old-group-format=@var{format}
1336*0b459c2cSDavid du ColombierThese line groups are hunks containing only lines from the first file.
1337*0b459c2cSDavid du ColombierThe default old group format is the same as the changed group format if
1338*0b459c2cSDavid du Colombierit is specified; otherwise it is a format that outputs the line group as-is.
1339*0b459c2cSDavid du Colombier
1340*0b459c2cSDavid du Colombier@item --new-group-format=@var{format}
1341*0b459c2cSDavid du ColombierThese line groups are hunks containing only lines from the second
1342*0b459c2cSDavid du Colombierfile.  The default new group format is same as the the changed group
1343*0b459c2cSDavid du Colombierformat if it is specified; otherwise it is a format that outputs the
1344*0b459c2cSDavid du Colombierline group as-is.
1345*0b459c2cSDavid du Colombier
1346*0b459c2cSDavid du Colombier@item --changed-group-format=@var{format}
1347*0b459c2cSDavid du ColombierThese line groups are hunks containing lines from both files.  The
1348*0b459c2cSDavid du Colombierdefault changed group format is the concatenation of the old and new
1349*0b459c2cSDavid du Colombiergroup formats.
1350*0b459c2cSDavid du Colombier
1351*0b459c2cSDavid du Colombier@item --unchanged-group-format=@var{format}
1352*0b459c2cSDavid du ColombierThese line groups contain lines common to both files.  The default
1353*0b459c2cSDavid du Colombierunchanged group format is a format that outputs the line group as-is.
1354*0b459c2cSDavid du Colombier@end table
1355*0b459c2cSDavid du Colombier
1356*0b459c2cSDavid du ColombierIn a line group format, ordinary characters represent themselves;
1357*0b459c2cSDavid du Colombierconversion specifications start with @samp{%} and have one of the
1358*0b459c2cSDavid du Colombierfollowing forms.
1359*0b459c2cSDavid du Colombier
1360*0b459c2cSDavid du Colombier@table @samp
1361*0b459c2cSDavid du Colombier@item %<
1362*0b459c2cSDavid du Colombierstands for the lines from the first file, including the trailing newline.
1363*0b459c2cSDavid du ColombierEach line is formatted according to the old line format (@pxref{Line Formats}).
1364*0b459c2cSDavid du Colombier
1365*0b459c2cSDavid du Colombier@item %>
1366*0b459c2cSDavid du Colombierstands for the lines from the second file, including the trailing newline.
1367*0b459c2cSDavid du ColombierEach line is formatted according to the new line format.
1368*0b459c2cSDavid du Colombier
1369*0b459c2cSDavid du Colombier@item %=
1370*0b459c2cSDavid du Colombierstands for the lines common to both files, including the trailing newline.
1371*0b459c2cSDavid du ColombierEach line is formatted according to the unchanged line format.
1372*0b459c2cSDavid du Colombier
1373*0b459c2cSDavid du Colombier@item %%
1374*0b459c2cSDavid du Colombierstands for @samp{%}.
1375*0b459c2cSDavid du Colombier
1376*0b459c2cSDavid du Colombier@item %c'@var{C}'
1377*0b459c2cSDavid du Colombierwhere @var{C} is a single character, stands for @var{C}.
1378*0b459c2cSDavid du Colombier@var{C} may not be a backslash or an apostrophe.
1379*0b459c2cSDavid du ColombierFor example, @samp{%c':'} stands for a colon, even inside
1380*0b459c2cSDavid du Colombierthe then-part of an if-then-else format, which a colon would
1381*0b459c2cSDavid du Colombiernormally terminate.
1382*0b459c2cSDavid du Colombier
1383*0b459c2cSDavid du Colombier@item %c'\@var{O}'
1384*0b459c2cSDavid du Colombierwhere @var{O} is a string of 1, 2, or 3 octal digits,
1385*0b459c2cSDavid du Colombierstands for the character with octal code @var{O}.
1386*0b459c2cSDavid du ColombierFor example, @samp{%c'\0'} stands for a null character.
1387*0b459c2cSDavid du Colombier
1388*0b459c2cSDavid du Colombier@item @var{F}@var{n}
1389*0b459c2cSDavid du Colombierwhere @var{F} is a @code{printf} conversion specification and @var{n} is one
1390*0b459c2cSDavid du Colombierof the following letters, stands for @var{n}'s value formatted with @var{F}.
1391*0b459c2cSDavid du Colombier
1392*0b459c2cSDavid du Colombier@table @samp
1393*0b459c2cSDavid du Colombier@item e
1394*0b459c2cSDavid du ColombierThe line number of the line just before the group in the old file.
1395*0b459c2cSDavid du Colombier
1396*0b459c2cSDavid du Colombier@item f
1397*0b459c2cSDavid du ColombierThe line number of the first line in the group in the old file;
1398*0b459c2cSDavid du Colombierequals @var{e} + 1.
1399*0b459c2cSDavid du Colombier
1400*0b459c2cSDavid du Colombier@item l
1401*0b459c2cSDavid du ColombierThe line number of the last line in the group in the old file.
1402*0b459c2cSDavid du Colombier
1403*0b459c2cSDavid du Colombier@item m
1404*0b459c2cSDavid du ColombierThe line number of the line just after the group in the old file;
1405*0b459c2cSDavid du Colombierequals @var{l} + 1.
1406*0b459c2cSDavid du Colombier
1407*0b459c2cSDavid du Colombier@item n
1408*0b459c2cSDavid du ColombierThe number of lines in the group in the old file; equals @var{l} - @var{f} + 1.
1409*0b459c2cSDavid du Colombier
1410*0b459c2cSDavid du Colombier@item E, F, L, M, N
1411*0b459c2cSDavid du ColombierLikewise, for lines in the new file.
1412*0b459c2cSDavid du Colombier
1413*0b459c2cSDavid du Colombier@end table
1414*0b459c2cSDavid du Colombier
1415*0b459c2cSDavid du ColombierThe @code{printf} conversion specification can be @samp{%d},
1416*0b459c2cSDavid du Colombier@samp{%o}, @samp{%x}, or @samp{%X}, specifying decimal, octal,
1417*0b459c2cSDavid du Colombierlower case hexadecimal, or upper case hexadecimal output
1418*0b459c2cSDavid du Colombierrespectively.  After the @samp{%} the following options can appear in
1419*0b459c2cSDavid du Colombiersequence: a @samp{-} specifying left-justification; an integer
1420*0b459c2cSDavid du Colombierspecifying the minimum field width; and a period followed by an
1421*0b459c2cSDavid du Colombieroptional integer specifying the minimum number of digits.
1422*0b459c2cSDavid du ColombierFor example, @samp{%5dN} prints the number of new lines in the group
1423*0b459c2cSDavid du Colombierin a field of width 5 characters, using the @code{printf} format @code{"%5d"}.
1424*0b459c2cSDavid du Colombier
1425*0b459c2cSDavid du Colombier@item (@var{A}=@var{B}?@var{T}:@var{E})
1426*0b459c2cSDavid du ColombierIf @var{A} equals @var{B} then @var{T} else @var{E}.
1427*0b459c2cSDavid du Colombier@var{A} and @var{B} are each either a decimal constant
1428*0b459c2cSDavid du Colombieror a single letter interpreted as above.
1429*0b459c2cSDavid du ColombierThis format spec is equivalent to @var{T} if
1430*0b459c2cSDavid du Colombier@var{A}'s value equals @var{B}'s; otherwise it is equivalent to @var{E}.
1431*0b459c2cSDavid du Colombier
1432*0b459c2cSDavid du ColombierFor example, @samp{%(N=0?no:%dN) line%(N=1?:s)} is equivalent to
1433*0b459c2cSDavid du Colombier@samp{no lines} if @var{N} (the number of lines in the group in the the
1434*0b459c2cSDavid du Colombiernew file) is 0, to @samp{1 line} if @var{N} is 1, and to @samp{%dN lines}
1435*0b459c2cSDavid du Colombierotherwise.
1436*0b459c2cSDavid du Colombier@end table
1437*0b459c2cSDavid du Colombier
1438*0b459c2cSDavid du Colombier@node Line Formats, Detailed If-then-else, Line Group Formats, If-then-else
1439*0b459c2cSDavid du Colombier@subsection Line Formats
1440*0b459c2cSDavid du Colombier@cindex line formats
1441*0b459c2cSDavid du Colombier
1442*0b459c2cSDavid du ColombierLine formats control how each line taken from an input file is
1443*0b459c2cSDavid du Colombieroutput as part of a line group in if-then-else format.
1444*0b459c2cSDavid du Colombier
1445*0b459c2cSDavid du ColombierFor example, the following command outputs text with a one-column
1446*0b459c2cSDavid du Colombierchange indicator to the left of the text.  The first column of output
1447*0b459c2cSDavid du Colombieris @samp{-} for deleted lines, @samp{|} for added lines, and a space
1448*0b459c2cSDavid du Colombierfor unchanged lines.  The formats contain newline characters where
1449*0b459c2cSDavid du Colombiernewlines are desired on output.
1450*0b459c2cSDavid du Colombier
1451*0b459c2cSDavid du Colombier@example
1452*0b459c2cSDavid du Colombierdiff \
1453*0b459c2cSDavid du Colombier   --old-line-format='-%l
1454*0b459c2cSDavid du Colombier' \
1455*0b459c2cSDavid du Colombier   --new-line-format='|%l
1456*0b459c2cSDavid du Colombier' \
1457*0b459c2cSDavid du Colombier   --unchanged-line-format=' %l
1458*0b459c2cSDavid du Colombier' \
1459*0b459c2cSDavid du Colombier   old new
1460*0b459c2cSDavid du Colombier@end example
1461*0b459c2cSDavid du Colombier
1462*0b459c2cSDavid du ColombierTo specify a line format, use one of the following options.  You should
1463*0b459c2cSDavid du Colombierquote @var{format}, since it often contains shell metacharacters.
1464*0b459c2cSDavid du Colombier
1465*0b459c2cSDavid du Colombier@table @samp
1466*0b459c2cSDavid du Colombier@item --old-line-format=@var{format}
1467*0b459c2cSDavid du Colombierformats lines just from the first file.
1468*0b459c2cSDavid du Colombier
1469*0b459c2cSDavid du Colombier@item --new-line-format=@var{format}
1470*0b459c2cSDavid du Colombierformats lines just from the second file.
1471*0b459c2cSDavid du Colombier
1472*0b459c2cSDavid du Colombier@item --unchanged-line-format=@var{format}
1473*0b459c2cSDavid du Colombierformats lines common to both files.
1474*0b459c2cSDavid du Colombier
1475*0b459c2cSDavid du Colombier@item --line-format=@var{format}
1476*0b459c2cSDavid du Colombierformats all lines; in effect, it sets all three above options simultaneously.
1477*0b459c2cSDavid du Colombier@end table
1478*0b459c2cSDavid du Colombier
1479*0b459c2cSDavid du ColombierIn a line format, ordinary characters represent themselves;
1480*0b459c2cSDavid du Colombierconversion specifications start with @samp{%} and have one of the
1481*0b459c2cSDavid du Colombierfollowing forms.
1482*0b459c2cSDavid du Colombier
1483*0b459c2cSDavid du Colombier@table @samp
1484*0b459c2cSDavid du Colombier@item %l
1485*0b459c2cSDavid du Colombierstands for the the contents of the line, not counting its trailing
1486*0b459c2cSDavid du Colombiernewline (if any).  This format ignores whether the line is incomplete;
1487*0b459c2cSDavid du Colombier@xref{Incomplete Lines}.
1488*0b459c2cSDavid du Colombier
1489*0b459c2cSDavid du Colombier@item %L
1490*0b459c2cSDavid du Colombierstands for the the contents of the line, including its trailing newline
1491*0b459c2cSDavid du Colombier(if any).  If a line is incomplete, this format preserves its
1492*0b459c2cSDavid du Colombierincompleteness.
1493*0b459c2cSDavid du Colombier
1494*0b459c2cSDavid du Colombier@item %%
1495*0b459c2cSDavid du Colombierstands for @samp{%}.
1496*0b459c2cSDavid du Colombier
1497*0b459c2cSDavid du Colombier@item %c'@var{C}'
1498*0b459c2cSDavid du Colombierwhere @var{C} is a single character, stands for @var{C}.
1499*0b459c2cSDavid du Colombier@var{C} may not be a backslash or an apostrophe.
1500*0b459c2cSDavid du ColombierFor example, @samp{%c':'} stands for a colon.
1501*0b459c2cSDavid du Colombier
1502*0b459c2cSDavid du Colombier@item %c'\@var{O}'
1503*0b459c2cSDavid du Colombierwhere @var{O} is a string of 1, 2, or 3 octal digits,
1504*0b459c2cSDavid du Colombierstands for the character with octal code @var{O}.
1505*0b459c2cSDavid du ColombierFor example, @samp{%c'\0'} stands for a null character.
1506*0b459c2cSDavid du Colombier
1507*0b459c2cSDavid du Colombier@item @var{F}n
1508*0b459c2cSDavid du Colombierwhere @var{F} is a @code{printf} conversion specification,
1509*0b459c2cSDavid du Colombierstands for the line number formatted with @var{F}.
1510*0b459c2cSDavid du ColombierFor example, @samp{%.5dn} prints the line number using the
1511*0b459c2cSDavid du Colombier@code{printf} format @code{"%.5d"}.  @xref{Line Group Formats}, for
1512*0b459c2cSDavid du Colombiermore about printf conversion specifications.
1513*0b459c2cSDavid du Colombier
1514*0b459c2cSDavid du Colombier@end table
1515*0b459c2cSDavid du Colombier
1516*0b459c2cSDavid du ColombierThe default line format is @samp{%l} followed by a newline character.
1517*0b459c2cSDavid du Colombier
1518*0b459c2cSDavid du ColombierIf the input contains tab characters and it is important that they line
1519*0b459c2cSDavid du Colombierup on output, you should ensure that @samp{%l} or @samp{%L} in a line
1520*0b459c2cSDavid du Colombierformat is just after a tab stop (e.g.@: by preceding @samp{%l} or
1521*0b459c2cSDavid du Colombier@samp{%L} with a tab character), or you should use the @samp{-t} or
1522*0b459c2cSDavid du Colombier@samp{--expand-tabs} option.
1523*0b459c2cSDavid du Colombier
1524*0b459c2cSDavid du ColombierTaken together, the line and line group formats let you specify many
1525*0b459c2cSDavid du Colombierdifferent formats.  For example, the following command uses a format
1526*0b459c2cSDavid du Colombiersimilar to @code{diff}'s normal format.  You can tailor this command
1527*0b459c2cSDavid du Colombierto get fine control over @code{diff}'s output.
1528*0b459c2cSDavid du Colombier
1529*0b459c2cSDavid du Colombier@example
1530*0b459c2cSDavid du Colombierdiff \
1531*0b459c2cSDavid du Colombier   --old-line-format='< %l
1532*0b459c2cSDavid du Colombier' \
1533*0b459c2cSDavid du Colombier   --new-line-format='> %l
1534*0b459c2cSDavid du Colombier' \
1535*0b459c2cSDavid du Colombier   --old-group-format='%df%(f=l?:,%dl)d%dE
1536*0b459c2cSDavid du Colombier%<' \
1537*0b459c2cSDavid du Colombier   --new-group-format='%dea%dF%(F=L?:,%dL)
1538*0b459c2cSDavid du Colombier%>' \
1539*0b459c2cSDavid du Colombier   --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)
1540*0b459c2cSDavid du Colombier%<---
1541*0b459c2cSDavid du Colombier%>' \
1542*0b459c2cSDavid du Colombier   --unchanged-group-format='' \
1543*0b459c2cSDavid du Colombier   old new
1544*0b459c2cSDavid du Colombier@end example
1545*0b459c2cSDavid du Colombier
1546*0b459c2cSDavid du Colombier@node Detailed If-then-else, Example If-then-else, Line Formats, If-then-else
1547*0b459c2cSDavid du Colombier@subsection Detailed Description of If-then-else Format
1548*0b459c2cSDavid du Colombier
1549*0b459c2cSDavid du ColombierFor lines common to both files, @code{diff} uses the unchanged line
1550*0b459c2cSDavid du Colombiergroup format.  For each hunk of differences in the merged output
1551*0b459c2cSDavid du Colombierformat, if the hunk contains only lines from the first file,
1552*0b459c2cSDavid du Colombier@code{diff} uses the old line group format; if the hunk contains only
1553*0b459c2cSDavid du Colombierlines from the second file, @code{diff} uses the new group format;
1554*0b459c2cSDavid du Colombierotherwise, @code{diff} uses the changed group format.
1555*0b459c2cSDavid du Colombier
1556*0b459c2cSDavid du ColombierThe old, new, and unchanged line formats specify the output format of
1557*0b459c2cSDavid du Colombierlines from the first file, lines from the second file, and lines common
1558*0b459c2cSDavid du Colombierto both files, respectively.
1559*0b459c2cSDavid du Colombier
1560*0b459c2cSDavid du ColombierThe option @samp{--ifdef=@var{name}} is equivalent to
1561*0b459c2cSDavid du Colombierthe following sequence of options using shell syntax:
1562*0b459c2cSDavid du Colombier
1563*0b459c2cSDavid du Colombier@example
1564*0b459c2cSDavid du Colombier--old-group-format='#ifndef @var{name}
1565*0b459c2cSDavid du Colombier%<#endif /* not @var{name} */
1566*0b459c2cSDavid du Colombier' \
1567*0b459c2cSDavid du Colombier--new-group-format='#ifdef @var{name}
1568*0b459c2cSDavid du Colombier%>#endif /* @var{name} */
1569*0b459c2cSDavid du Colombier' \
1570*0b459c2cSDavid du Colombier--unchanged-group-format='%=' \
1571*0b459c2cSDavid du Colombier--changed-group-format='#ifndef @var{name}
1572*0b459c2cSDavid du Colombier%<#else /* @var{name} */
1573*0b459c2cSDavid du Colombier%>#endif /* @var{name} */
1574*0b459c2cSDavid du Colombier'
1575*0b459c2cSDavid du Colombier@end example
1576*0b459c2cSDavid du Colombier
1577*0b459c2cSDavid du ColombierYou should carefully check the @code{diff} output for proper nesting.
1578*0b459c2cSDavid du ColombierFor example, when using the the @samp{-D @var{name}} or
1579*0b459c2cSDavid du Colombier@samp{--ifdef=@var{name}} option, you should check that if the
1580*0b459c2cSDavid du Colombierdiffering lines contain any of the C preprocessor directives
1581*0b459c2cSDavid du Colombier@samp{#ifdef}, @samp{#ifndef}, @samp{#else}, @samp{#elif}, or
1582*0b459c2cSDavid du Colombier@samp{#endif}, they are nested properly and match.  If they don't, you
1583*0b459c2cSDavid du Colombiermust make corrections manually.  It is a good idea to carefully check
1584*0b459c2cSDavid du Colombierthe resulting code anyway to make sure that it really does what you
1585*0b459c2cSDavid du Colombierwant it to; depending on how the input files were produced, the output
1586*0b459c2cSDavid du Colombiermight contain duplicate or otherwise incorrect code.
1587*0b459c2cSDavid du Colombier
1588*0b459c2cSDavid du ColombierThe @code{patch} @samp{-D @var{name}} option behaves just like
1589*0b459c2cSDavid du Colombierthe @code{diff} @samp{-D @var{name}} option, except it operates on
1590*0b459c2cSDavid du Colombiera file and a diff to produce a merged file; @xref{patch Options}.
1591*0b459c2cSDavid du Colombier
1592*0b459c2cSDavid du Colombier@node Example If-then-else, , Detailed If-then-else, If-then-else
1593*0b459c2cSDavid du Colombier@subsection An Example of If-then-else Format
1594*0b459c2cSDavid du Colombier
1595*0b459c2cSDavid du ColombierHere is the output of @samp{diff -DTWO lao tzu} (@pxref{Sample
1596*0b459c2cSDavid du Colombierdiff Input}, for the complete contents of the two files):
1597*0b459c2cSDavid du Colombier
1598*0b459c2cSDavid du Colombier@example
1599*0b459c2cSDavid du Colombier#ifndef TWO
1600*0b459c2cSDavid du ColombierThe Way that can be told of is not the eternal Way;
1601*0b459c2cSDavid du ColombierThe name that can be named is not the eternal name.
1602*0b459c2cSDavid du Colombier#endif /* not TWO */
1603*0b459c2cSDavid du ColombierThe Nameless is the origin of Heaven and Earth;
1604*0b459c2cSDavid du Colombier#ifndef TWO
1605*0b459c2cSDavid du ColombierThe Named is the mother of all things.
1606*0b459c2cSDavid du Colombier#else /* TWO */
1607*0b459c2cSDavid du ColombierThe named is the mother of all things.
1608*0b459c2cSDavid du Colombier
1609*0b459c2cSDavid du Colombier#endif /* TWO */
1610*0b459c2cSDavid du ColombierTherefore let there always be non-being,
1611*0b459c2cSDavid du Colombier  so we may see their subtlety,
1612*0b459c2cSDavid du ColombierAnd let there always be being,
1613*0b459c2cSDavid du Colombier  so we may see their outcome.
1614*0b459c2cSDavid du ColombierThe two are the same,
1615*0b459c2cSDavid du ColombierBut after they are produced,
1616*0b459c2cSDavid du Colombier  they have different names.
1617*0b459c2cSDavid du Colombier#ifdef TWO
1618*0b459c2cSDavid du ColombierThey both may be called deep and profound.
1619*0b459c2cSDavid du ColombierDeeper and more profound,
1620*0b459c2cSDavid du ColombierThe door of all subtleties!
1621*0b459c2cSDavid du Colombier#endif /* TWO */
1622*0b459c2cSDavid du Colombier@end example
1623*0b459c2cSDavid du Colombier
1624*0b459c2cSDavid du Colombier@node Comparing Directories, Adjusting Output, Output Formats, Top
1625*0b459c2cSDavid du Colombier@chapter Comparing Directories
1626*0b459c2cSDavid du Colombier
1627*0b459c2cSDavid du ColombierYou can use @code{diff} to compare some or all of the files in two
1628*0b459c2cSDavid du Colombierdirectory trees.  When both file name arguments to @code{diff} are
1629*0b459c2cSDavid du Colombierdirectories, it compares each file that is contained in both
1630*0b459c2cSDavid du Colombierdirectories, examining file names in alphabetical order.  Normally
1631*0b459c2cSDavid du Colombier@code{diff} is silent about pairs of files that contain no differences,
1632*0b459c2cSDavid du Colombierbut if you use the @samp{-s} or @samp{--report-identical-files} option,
1633*0b459c2cSDavid du Colombierit reports pairs of identical files.  Normally @code{diff} reports
1634*0b459c2cSDavid du Colombiersubdirectories common to both directories without comparing
1635*0b459c2cSDavid du Colombiersubdirectories' files, but if you use the @samp{-r} or
1636*0b459c2cSDavid du Colombier@samp{--recursive} option, it compares every corresponding pair of files
1637*0b459c2cSDavid du Colombierin the directory trees, as many levels deep as they go.
1638*0b459c2cSDavid du Colombier
1639*0b459c2cSDavid du ColombierFor file names that are in only one of the directories, @code{diff}
1640*0b459c2cSDavid du Colombiernormally does not show the contents of the file that exists; it reports
1641*0b459c2cSDavid du Colombieronly that the file exists in that directory and not in the other.  You
1642*0b459c2cSDavid du Colombiercan make @code{diff} act as though the file existed but was empty in the
1643*0b459c2cSDavid du Colombierother directory, so that it outputs the entire contents of the file that
1644*0b459c2cSDavid du Colombieractually exists.  (It is output as either an insertion or a
1645*0b459c2cSDavid du Colombierdeletion, depending on whether it is in the first or the second
1646*0b459c2cSDavid du Colombierdirectory given.)  To do this, use the @samp{-N} or @samp{--new-file}
1647*0b459c2cSDavid du Colombieroption.
1648*0b459c2cSDavid du Colombier
1649*0b459c2cSDavid du ColombierIf the older directory contains one or more large files that are not in
1650*0b459c2cSDavid du Colombierthe newer directory, you can make the patch smaller by using the
1651*0b459c2cSDavid du Colombier@samp{-P} or @samp{--unidirectional-new-file} option instead of @samp{-N}.
1652*0b459c2cSDavid du ColombierThis option is like @samp{-N} except that it only inserts the contents
1653*0b459c2cSDavid du Colombierof files that appear in the second directory but not the first (that is,
1654*0b459c2cSDavid du Colombierfiles that were added).  At the top of the patch, write instructions for
1655*0b459c2cSDavid du Colombierthe user applying the patch to remove the files that were deleted before
1656*0b459c2cSDavid du Colombierapplying the patch.  @xref{Making Patches}, for more discussion of
1657*0b459c2cSDavid du Colombiermaking patches for distribution.
1658*0b459c2cSDavid du Colombier
1659*0b459c2cSDavid du ColombierTo ignore some files while comparing directories, use the @samp{-x
1660*0b459c2cSDavid du Colombier@var{pattern}} or @samp{--exclude=@var{pattern}} option.  This option
1661*0b459c2cSDavid du Colombierignores any files or subdirectories whose base names match the shell
1662*0b459c2cSDavid du Colombierpattern @var{pattern}.  Unlike in the shell, a period at the start of
1663*0b459c2cSDavid du Colombierthe base of a file name matches a wildcard at the start of a pattern.
1664*0b459c2cSDavid du ColombierYou should enclose @var{pattern} in quotes so that the shell does not
1665*0b459c2cSDavid du Colombierexpand it.  For example, the option @samp{-x '*.[ao]'} ignores any file
1666*0b459c2cSDavid du Colombierwhose name ends with @samp{.a} or @samp{.o}.
1667*0b459c2cSDavid du Colombier
1668*0b459c2cSDavid du ColombierThis option accumulates if you specify it more than once.  For example,
1669*0b459c2cSDavid du Colombierusing the options @samp{-x 'RCS' -x '*,v'} ignores any file or
1670*0b459c2cSDavid du Colombiersubdirectory whose base name is @samp{RCS} or ends with @samp{,v}.
1671*0b459c2cSDavid du Colombier
1672*0b459c2cSDavid du ColombierIf you need to give this option many times, you can instead put the
1673*0b459c2cSDavid du Colombierpatterns in a file, one pattern per line, and use the @samp{-X
1674*0b459c2cSDavid du Colombier@var{file}} or @samp{--exclude-from=@var{file}} option.
1675*0b459c2cSDavid du Colombier
1676*0b459c2cSDavid du ColombierIf you have been comparing two directories and stopped partway through,
1677*0b459c2cSDavid du Colombierlater you might want to continue where you left off.  You can do this by
1678*0b459c2cSDavid du Colombierusing the @samp{-S @var{file}} or @samp{--starting-file=@var{file}}
1679*0b459c2cSDavid du Colombieroption.  This compares only the file @var{file} and all alphabetically
1680*0b459c2cSDavid du Colombierlater files in the topmost directory level.
1681*0b459c2cSDavid du Colombier
1682*0b459c2cSDavid du Colombier@node Adjusting Output, diff Performance, Comparing Directories, Top
1683*0b459c2cSDavid du Colombier@chapter Making @code{diff} Output Prettier
1684*0b459c2cSDavid du Colombier
1685*0b459c2cSDavid du Colombier@code{diff} provides several ways to adjust the appearance of its output.
1686*0b459c2cSDavid du ColombierThese adjustments can be applied to any output format.
1687*0b459c2cSDavid du Colombier
1688*0b459c2cSDavid du Colombier@menu
1689*0b459c2cSDavid du Colombier* Tabs::		Preserving the alignment of tabstops.
1690*0b459c2cSDavid du Colombier* Pagination::		Page numbering and timestamping @code{diff} output.
1691*0b459c2cSDavid du Colombier@end menu
1692*0b459c2cSDavid du Colombier
1693*0b459c2cSDavid du Colombier@node Tabs, Pagination, , Adjusting Output
1694*0b459c2cSDavid du Colombier@section Preserving Tabstop Alignment
1695*0b459c2cSDavid du Colombier@cindex tabstop alignment
1696*0b459c2cSDavid du Colombier@cindex aligning tabstops
1697*0b459c2cSDavid du Colombier
1698*0b459c2cSDavid du ColombierThe lines of text in some of the @code{diff} output formats are preceded
1699*0b459c2cSDavid du Colombierby one or two characters that indicate whether the text is inserted,
1700*0b459c2cSDavid du Colombierdeleted, or changed.  The addition of those characters can cause tabs to
1701*0b459c2cSDavid du Colombiermove to the next tabstop, throwing off the alignment of columns in the
1702*0b459c2cSDavid du Colombierline.  GNU @code{diff} provides two ways to make tab-aligned columns
1703*0b459c2cSDavid du Colombierline up correctly.
1704*0b459c2cSDavid du Colombier
1705*0b459c2cSDavid du ColombierThe first way is to have @code{diff} convert all tabs into the correct
1706*0b459c2cSDavid du Colombiernumber of spaces before outputting them; select this method with the
1707*0b459c2cSDavid du Colombier@samp{-t} or @samp{--expand-tabs} option.  @code{diff} assumes that
1708*0b459c2cSDavid du Colombiertabstops are set every 8 columns.  To use this form of output with
1709*0b459c2cSDavid du Colombier@code{patch}, you must give @code{patch} the @samp{-l} or
1710*0b459c2cSDavid du Colombier@samp{--ignore-white-space} option (@pxref{Changed White Space}, for more
1711*0b459c2cSDavid du Colombierinformation).
1712*0b459c2cSDavid du Colombier
1713*0b459c2cSDavid du ColombierThe other method for making tabs line up correctly is to add a tab
1714*0b459c2cSDavid du Colombiercharacter instead of a space after the indicator character at the
1715*0b459c2cSDavid du Colombierbeginning of the line.  This ensures that all following tab characters
1716*0b459c2cSDavid du Colombierare in the same position relative to tabstops that they were in the
1717*0b459c2cSDavid du Colombieroriginal files, so that the output is aligned correctly.  Its
1718*0b459c2cSDavid du Colombierdisadvantage is that it can make long lines too long to fit on one line
1719*0b459c2cSDavid du Colombierof the screen or the paper.  It also does not work with the unified
1720*0b459c2cSDavid du Colombieroutput format, which does not have a space character after the change
1721*0b459c2cSDavid du Colombiertype indicator character.  Select this method with the @samp{-T} or
1722*0b459c2cSDavid du Colombier@samp{--initial-tab} option.
1723*0b459c2cSDavid du Colombier
1724*0b459c2cSDavid du Colombier@node Pagination, , Tabs, Adjusting Output
1725*0b459c2cSDavid du Colombier@section Paginating @code{diff} Output
1726*0b459c2cSDavid du Colombier@cindex paginating @code{diff} output
1727*0b459c2cSDavid du Colombier
1728*0b459c2cSDavid du ColombierIt can be convenient to have long output page-numbered and time-stamped.
1729*0b459c2cSDavid du ColombierThe @samp{-l} and @samp{--paginate} options do this by sending the
1730*0b459c2cSDavid du Colombier@code{diff} output through the @code{pr} program.  Here is what the page
1731*0b459c2cSDavid du Colombierheader might look like for @samp{diff -lc lao tzu}:
1732*0b459c2cSDavid du Colombier
1733*0b459c2cSDavid du Colombier@example
1734*0b459c2cSDavid du ColombierMar 11 13:37 1991  diff -lc lao tzu Page 1
1735*0b459c2cSDavid du Colombier@end example
1736*0b459c2cSDavid du Colombier
1737*0b459c2cSDavid du Colombier@node diff Performance, Comparing Three Files, Adjusting Output, Top
1738*0b459c2cSDavid du Colombier@chapter @code{diff} Performance Tradeoffs
1739*0b459c2cSDavid du Colombier@cindex performance of @code{diff}
1740*0b459c2cSDavid du Colombier
1741*0b459c2cSDavid du ColombierGNU @code{diff} runs quite efficiently; however, in some circumstances
1742*0b459c2cSDavid du Colombieryou can cause it to run faster or produce a more compact set of changes.
1743*0b459c2cSDavid du ColombierThere are two ways that you can affect the performance of GNU
1744*0b459c2cSDavid du Colombier@code{diff} by changing the way it compares files.
1745*0b459c2cSDavid du Colombier
1746*0b459c2cSDavid du ColombierPerformance has more than one dimension.  These options improve one
1747*0b459c2cSDavid du Colombieraspect of performance at the cost of another, or they improve
1748*0b459c2cSDavid du Colombierperformance in some cases while hurting it in others.
1749*0b459c2cSDavid du Colombier
1750*0b459c2cSDavid du ColombierThe way that GNU @code{diff} determines which lines have changed always
1751*0b459c2cSDavid du Colombiercomes up with a near-minimal set of differences.  Usually it is good
1752*0b459c2cSDavid du Colombierenough for practical purposes.  If the @code{diff} output is large, you
1753*0b459c2cSDavid du Colombiermight want @code{diff} to use a modified algorithm that sometimes
1754*0b459c2cSDavid du Colombierproduces a smaller set of differences.  The @samp{-d} or
1755*0b459c2cSDavid du Colombier@samp{--minimal} option does this; however, it can also cause
1756*0b459c2cSDavid du Colombier@code{diff} to run more slowly than usual, so it is not the default
1757*0b459c2cSDavid du Colombierbehavior.
1758*0b459c2cSDavid du Colombier
1759*0b459c2cSDavid du ColombierWhen the files you are comparing are large and have small groups of
1760*0b459c2cSDavid du Colombierchanges scattered throughout them, you can use the @samp{-H} or
1761*0b459c2cSDavid du Colombier@samp{--speed-large-files} option to make a different modification to
1762*0b459c2cSDavid du Colombierthe algorithm that @code{diff} uses.  If the input files have a constant
1763*0b459c2cSDavid du Colombiersmall density of changes, this option speeds up the comparisons without
1764*0b459c2cSDavid du Colombierchanging the output.  If not, @code{diff} might produce a larger set of
1765*0b459c2cSDavid du Colombierdifferences; however, the output will still be correct.
1766*0b459c2cSDavid du Colombier
1767*0b459c2cSDavid du ColombierNormally @code{diff} discards the prefix and suffix that is common to
1768*0b459c2cSDavid du Colombierboth files before it attempts to find a minimal set of differences.
1769*0b459c2cSDavid du ColombierThis makes @code{diff} run faster, but occasionally it may produce
1770*0b459c2cSDavid du Colombiernon-minimal output.  The @samp{--horizon-lines=@var{lines}} option
1771*0b459c2cSDavid du Colombierprevents @code{diff} from discarding the last @var{lines} lines of the
1772*0b459c2cSDavid du Colombierprefix and the first @var{lines} lines of the suffix.  This gives
1773*0b459c2cSDavid du Colombier@code{diff} further opportunities to find a minimal output.
1774*0b459c2cSDavid du Colombier
1775*0b459c2cSDavid du Colombier@node Comparing Three Files, diff3 Merging, diff Performance, Top
1776*0b459c2cSDavid du Colombier@chapter Comparing Three Files
1777*0b459c2cSDavid du Colombier@cindex comparing three files
1778*0b459c2cSDavid du Colombier@cindex format of @code{diff3} output
1779*0b459c2cSDavid du Colombier
1780*0b459c2cSDavid du ColombierUse the program @code{diff3} to compare three files and show any
1781*0b459c2cSDavid du Colombierdifferences among them.  (@code{diff3} can also merge files; see
1782*0b459c2cSDavid du Colombier@ref{diff3 Merging}).
1783*0b459c2cSDavid du Colombier
1784*0b459c2cSDavid du ColombierThe ``normal'' @code{diff3} output format shows each hunk of
1785*0b459c2cSDavid du Colombierdifferences without surrounding context.  Hunks are labeled depending
1786*0b459c2cSDavid du Colombieron whether they are two-way or three-way, and lines are annotated by
1787*0b459c2cSDavid du Colombiertheir location in the input files.
1788*0b459c2cSDavid du Colombier
1789*0b459c2cSDavid du Colombier@xref{Invoking diff3}, for more information on how to run @code{diff3}.
1790*0b459c2cSDavid du Colombier
1791*0b459c2cSDavid du Colombier@menu
1792*0b459c2cSDavid du Colombier* Sample diff3 Input::		Sample @code{diff3} input for examples.
1793*0b459c2cSDavid du Colombier* Detailed diff3 Normal::	A detailed description of normal output format.
1794*0b459c2cSDavid du Colombier* diff3 Hunks::			The format of normal output format.
1795*0b459c2cSDavid du Colombier* Example diff3 Normal::	Sample output in the normal format.
1796*0b459c2cSDavid du Colombier@end menu
1797*0b459c2cSDavid du Colombier
1798*0b459c2cSDavid du Colombier@node Sample diff3 Input, Detailed diff3 Normal, , Comparing Three Files
1799*0b459c2cSDavid du Colombier@section A Third Sample Input File
1800*0b459c2cSDavid du Colombier@cindex @code{diff3} sample input
1801*0b459c2cSDavid du Colombier@cindex sample input for @code{diff3}
1802*0b459c2cSDavid du Colombier
1803*0b459c2cSDavid du ColombierHere is a third sample file that will be used in examples to illustrate
1804*0b459c2cSDavid du Colombierthe output of @code{diff3} and how various options can change it.  The
1805*0b459c2cSDavid du Colombierfirst two files are the same that we used for @code{diff} (@pxref{Sample
1806*0b459c2cSDavid du Colombierdiff Input}).  This is the third sample file, called @file{tao}:
1807*0b459c2cSDavid du Colombier
1808*0b459c2cSDavid du Colombier@example
1809*0b459c2cSDavid du ColombierThe Way that can be told of is not the eternal Way;
1810*0b459c2cSDavid du ColombierThe name that can be named is not the eternal name.
1811*0b459c2cSDavid du ColombierThe Nameless is the origin of Heaven and Earth;
1812*0b459c2cSDavid du ColombierThe named is the mother of all things.
1813*0b459c2cSDavid du Colombier
1814*0b459c2cSDavid du ColombierTherefore let there always be non-being,
1815*0b459c2cSDavid du Colombier  so we may see their subtlety,
1816*0b459c2cSDavid du ColombierAnd let there always be being,
1817*0b459c2cSDavid du Colombier  so we may see their result.
1818*0b459c2cSDavid du ColombierThe two are the same,
1819*0b459c2cSDavid du ColombierBut after they are produced,
1820*0b459c2cSDavid du Colombier  they have different names.
1821*0b459c2cSDavid du Colombier
1822*0b459c2cSDavid du Colombier  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
1823*0b459c2cSDavid du Colombier@end example
1824*0b459c2cSDavid du Colombier
1825*0b459c2cSDavid du Colombier@node Detailed diff3 Normal, diff3 Hunks, Sample diff3 Input, Comparing Three Files
1826*0b459c2cSDavid du Colombier@section Detailed Description of @code{diff3} Normal Format
1827*0b459c2cSDavid du Colombier
1828*0b459c2cSDavid du ColombierEach hunk begins with a line marked @samp{====}.  Three-way hunks have
1829*0b459c2cSDavid du Colombierplain @samp{====} lines, and two-way hunks have @samp{1}, @samp{2}, or
1830*0b459c2cSDavid du Colombier@samp{3} appended to specify which of the three input files differ in
1831*0b459c2cSDavid du Colombierthat hunk.  The hunks contain copies of two or three sets of input
1832*0b459c2cSDavid du Colombierlines each preceded by one or two commands identifying where the lines
1833*0b459c2cSDavid du Colombiercame from.
1834*0b459c2cSDavid du Colombier
1835*0b459c2cSDavid du ColombierNormally, two spaces precede each copy of an input line to distinguish
1836*0b459c2cSDavid du Colombierit from the commands.  But with the @samp{-T} or @samp{--initial-tab}
1837*0b459c2cSDavid du Colombieroption, @code{diff3} uses a tab instead of two spaces; this lines up
1838*0b459c2cSDavid du Colombiertabs correctly.  @xref{Tabs}, for more information.
1839*0b459c2cSDavid du Colombier
1840*0b459c2cSDavid du ColombierCommands take the following forms:
1841*0b459c2cSDavid du Colombier
1842*0b459c2cSDavid du Colombier@table @samp
1843*0b459c2cSDavid du Colombier@item @var{file}:@var{l}a
1844*0b459c2cSDavid du ColombierThis hunk appears after line @var{l} of file @var{file}, and
1845*0b459c2cSDavid du Colombiercontains no lines in that file.  To edit this file to yield the other
1846*0b459c2cSDavid du Colombierfiles, one must append hunk lines taken from the other files.  For
1847*0b459c2cSDavid du Colombierexample, @samp{1:11a} means that the hunk follows line 11 in the first
1848*0b459c2cSDavid du Colombierfile and contains no lines from that file.
1849*0b459c2cSDavid du Colombier
1850*0b459c2cSDavid du Colombier@item @var{file}:@var{r}c
1851*0b459c2cSDavid du ColombierThis hunk contains the lines in the range @var{r} of file @var{file}.
1852*0b459c2cSDavid du ColombierThe range @var{r} is a comma-separated pair of line numbers, or just one
1853*0b459c2cSDavid du Colombiernumber if the range is a singleton.  To edit this file to yield the
1854*0b459c2cSDavid du Colombierother files, one must change the specified lines to be the lines taken
1855*0b459c2cSDavid du Colombierfrom the other files.  For example, @samp{2:11,13c} means that the hunk
1856*0b459c2cSDavid du Colombiercontains lines 11 through 13 from the second file.
1857*0b459c2cSDavid du Colombier@end table
1858*0b459c2cSDavid du Colombier
1859*0b459c2cSDavid du ColombierIf the last line in a set of input lines is incomplete
1860*0b459c2cSDavid du Colombier(@pxref{Incomplete Lines}), it is distinguished on output from a full
1861*0b459c2cSDavid du Colombierline by a following line that starts with @samp{\}.
1862*0b459c2cSDavid du Colombier
1863*0b459c2cSDavid du Colombier@node diff3 Hunks, Example diff3 Normal, Detailed diff3 Normal, Comparing Three Files
1864*0b459c2cSDavid du Colombier@section @code{diff3} Hunks
1865*0b459c2cSDavid du Colombier@cindex hunks for @code{diff3}
1866*0b459c2cSDavid du Colombier@cindex @code{diff3} hunks
1867*0b459c2cSDavid du Colombier
1868*0b459c2cSDavid du ColombierGroups of lines that differ in two or three of the input files are
1869*0b459c2cSDavid du Colombiercalled @dfn{diff3 hunks}, by analogy with @code{diff} hunks
1870*0b459c2cSDavid du Colombier(@pxref{Hunks}).  If all three input files differ in a @code{diff3}
1871*0b459c2cSDavid du Colombierhunk, the hunk is called a @dfn{three-way hunk}; if just two input files
1872*0b459c2cSDavid du Colombierdiffer, it is a @dfn{two-way hunk}.
1873*0b459c2cSDavid du Colombier
1874*0b459c2cSDavid du ColombierAs with @code{diff}, several solutions are possible.  When comparing the
1875*0b459c2cSDavid du Colombierfiles @samp{A}, @samp{B}, and @samp{C}, @code{diff3} normally finds
1876*0b459c2cSDavid du Colombier@code{diff3} hunks by merging the two-way hunks output by the two
1877*0b459c2cSDavid du Colombiercommands @samp{diff A B} and @samp{diff A C}.  This does not necessarily
1878*0b459c2cSDavid du Colombierminimize the size of the output, but exceptions should be rare.
1879*0b459c2cSDavid du Colombier
1880*0b459c2cSDavid du ColombierFor example, suppose @file{F} contains the three lines @samp{a},
1881*0b459c2cSDavid du Colombier@samp{b}, @samp{f}, @file{G} contains the lines @samp{g}, @samp{b},
1882*0b459c2cSDavid du Colombier@samp{g}, and @file{H} contains the lines @samp{a}, @samp{b},
1883*0b459c2cSDavid du Colombier@samp{h}.  @samp{diff3 F G H} might output the following:
1884*0b459c2cSDavid du Colombier
1885*0b459c2cSDavid du Colombier@example
1886*0b459c2cSDavid du Colombier====2
1887*0b459c2cSDavid du Colombier1:1c
1888*0b459c2cSDavid du Colombier3:1c
1889*0b459c2cSDavid du Colombier  a
1890*0b459c2cSDavid du Colombier2:1c
1891*0b459c2cSDavid du Colombier  g
1892*0b459c2cSDavid du Colombier====
1893*0b459c2cSDavid du Colombier1:3c
1894*0b459c2cSDavid du Colombier  f
1895*0b459c2cSDavid du Colombier2:3c
1896*0b459c2cSDavid du Colombier  g
1897*0b459c2cSDavid du Colombier3:3c
1898*0b459c2cSDavid du Colombier  h
1899*0b459c2cSDavid du Colombier@end example
1900*0b459c2cSDavid du Colombier
1901*0b459c2cSDavid du Colombier@noindent
1902*0b459c2cSDavid du Colombierbecause it found a two-way hunk containing @samp{a} in the first and
1903*0b459c2cSDavid du Colombierthird files and @samp{g} in the second file, then the single line
1904*0b459c2cSDavid du Colombier@samp{b} common to all three files, then a three-way hunk containing
1905*0b459c2cSDavid du Colombierthe last line of each file.
1906*0b459c2cSDavid du Colombier
1907*0b459c2cSDavid du Colombier@node Example diff3 Normal, , diff3 Hunks, Comparing Three Files
1908*0b459c2cSDavid du Colombier@section An Example of @code{diff3} Normal Format
1909*0b459c2cSDavid du Colombier
1910*0b459c2cSDavid du ColombierHere is the output of the command @samp{diff3 lao tzu tao}
1911*0b459c2cSDavid du Colombier(@pxref{Sample diff3 Input}, for the complete contents of the files).
1912*0b459c2cSDavid du ColombierNotice that it shows only the lines that are different among the three
1913*0b459c2cSDavid du Colombierfiles.
1914*0b459c2cSDavid du Colombier
1915*0b459c2cSDavid du Colombier@example
1916*0b459c2cSDavid du Colombier====2
1917*0b459c2cSDavid du Colombier1:1,2c
1918*0b459c2cSDavid du Colombier3:1,2c
1919*0b459c2cSDavid du Colombier  The Way that can be told of is not the eternal Way;
1920*0b459c2cSDavid du Colombier  The name that can be named is not the eternal name.
1921*0b459c2cSDavid du Colombier2:0a
1922*0b459c2cSDavid du Colombier====1
1923*0b459c2cSDavid du Colombier1:4c
1924*0b459c2cSDavid du Colombier  The Named is the mother of all things.
1925*0b459c2cSDavid du Colombier2:2,3c
1926*0b459c2cSDavid du Colombier3:4,5c
1927*0b459c2cSDavid du Colombier  The named is the mother of all things.
1928*0b459c2cSDavid du Colombier
1929*0b459c2cSDavid du Colombier====3
1930*0b459c2cSDavid du Colombier1:8c
1931*0b459c2cSDavid du Colombier2:7c
1932*0b459c2cSDavid du Colombier    so we may see their outcome.
1933*0b459c2cSDavid du Colombier3:9c
1934*0b459c2cSDavid du Colombier    so we may see their result.
1935*0b459c2cSDavid du Colombier====
1936*0b459c2cSDavid du Colombier1:11a
1937*0b459c2cSDavid du Colombier2:11,13c
1938*0b459c2cSDavid du Colombier  They both may be called deep and profound.
1939*0b459c2cSDavid du Colombier  Deeper and more profound,
1940*0b459c2cSDavid du Colombier  The door of all subtleties!
1941*0b459c2cSDavid du Colombier3:13,14c
1942*0b459c2cSDavid du Colombier
1943*0b459c2cSDavid du Colombier    -- The Way of Lao-Tzu, tr. Wing-tsit Chan
1944*0b459c2cSDavid du Colombier@end example
1945*0b459c2cSDavid du Colombier
1946*0b459c2cSDavid du Colombier@node diff3 Merging, Interactive Merging, Comparing Three Files, Top
1947*0b459c2cSDavid du Colombier@chapter Merging From a Common Ancestor
1948*0b459c2cSDavid du Colombier@cindex merging from a common ancestor
1949*0b459c2cSDavid du Colombier
1950*0b459c2cSDavid du ColombierWhen two people have made changes to copies of the same file,
1951*0b459c2cSDavid du Colombier@code{diff3} can produce a merged output that contains both sets of
1952*0b459c2cSDavid du Colombierchanges together with warnings about conflicts.
1953*0b459c2cSDavid du Colombier
1954*0b459c2cSDavid du ColombierOne might imagine programs with names like @code{diff4} and @code{diff5}
1955*0b459c2cSDavid du Colombierto compare more than three files simultaneously, but in practice the
1956*0b459c2cSDavid du Colombierneed rarely arises.  You can use @code{diff3} to merge three or more
1957*0b459c2cSDavid du Colombiersets of changes to a file by merging two change sets at a time.
1958*0b459c2cSDavid du Colombier
1959*0b459c2cSDavid du Colombier@code{diff3} can incorporate changes from two modified versions into a
1960*0b459c2cSDavid du Colombiercommon preceding version.  This lets you merge the sets of changes
1961*0b459c2cSDavid du Colombierrepresented by the two newer files.  Specify the common ancestor version
1962*0b459c2cSDavid du Colombieras the second argument and the two newer versions as the first and third
1963*0b459c2cSDavid du Colombierarguments, like this:
1964*0b459c2cSDavid du Colombier
1965*0b459c2cSDavid du Colombier@example
1966*0b459c2cSDavid du Colombierdiff3 @var{mine} @var{older} @var{yours}
1967*0b459c2cSDavid du Colombier@end example
1968*0b459c2cSDavid du Colombier
1969*0b459c2cSDavid du Colombier@noindent
1970*0b459c2cSDavid du ColombierYou can remember the order of the arguments by noting that they are in
1971*0b459c2cSDavid du Colombieralphabetical order.
1972*0b459c2cSDavid du Colombier
1973*0b459c2cSDavid du Colombier@cindex conflict
1974*0b459c2cSDavid du Colombier@cindex overlap
1975*0b459c2cSDavid du ColombierYou can think of this as subtracting @var{older} from @var{yours} and
1976*0b459c2cSDavid du Colombieradding the result to @var{mine}, or as merging into @var{mine} the
1977*0b459c2cSDavid du Colombierchanges that would turn @var{older} into @var{yours}.  This merging is
1978*0b459c2cSDavid du Colombierwell-defined as long as @var{mine} and @var{older} match in the
1979*0b459c2cSDavid du Colombierneighborhood of each such change.  This fails to be true when all three
1980*0b459c2cSDavid du Colombierinput files differ or when only @var{older} differs; we call this
1981*0b459c2cSDavid du Colombiera @dfn{conflict}.  When all three input files differ, we call the
1982*0b459c2cSDavid du Colombierconflict an @dfn{overlap}.
1983*0b459c2cSDavid du Colombier
1984*0b459c2cSDavid du Colombier@code{diff3} gives you several ways to handle overlaps and conflicts.
1985*0b459c2cSDavid du ColombierYou can omit overlaps or conflicts, or select only overlaps,
1986*0b459c2cSDavid du Colombieror mark conflicts with special @samp{<<<<<<<} and @samp{>>>>>>>} lines.
1987*0b459c2cSDavid du Colombier
1988*0b459c2cSDavid du Colombier@code{diff3} can output the merge results as an @code{ed} script that
1989*0b459c2cSDavid du Colombierthat can be applied to the first file to yield the merged output.
1990*0b459c2cSDavid du ColombierHowever, it is usually better to have @code{diff3} generate the merged
1991*0b459c2cSDavid du Colombieroutput directly; this bypasses some problems with @code{ed}.
1992*0b459c2cSDavid du Colombier
1993*0b459c2cSDavid du Colombier@menu
1994*0b459c2cSDavid du Colombier* Which Changes::		Selecting changes to incorporate.
1995*0b459c2cSDavid du Colombier* Marking Conflicts::		Marking conflicts.
1996*0b459c2cSDavid du Colombier* Bypassing ed::		Generating merged output directly.
1997*0b459c2cSDavid du Colombier* Merging Incomplete Lines::	How @code{diff3} merges incomplete lines.
1998*0b459c2cSDavid du Colombier* Saving the Changed File::	Emulating System V behavior.
1999*0b459c2cSDavid du Colombier@end menu
2000*0b459c2cSDavid du Colombier
2001*0b459c2cSDavid du Colombier@node Which Changes, Marking Conflicts, , diff3 Merging
2002*0b459c2cSDavid du Colombier@section Selecting Which Changes to Incorporate
2003*0b459c2cSDavid du Colombier@cindex overlapping change, selection of
2004*0b459c2cSDavid du Colombier@cindex unmerged change
2005*0b459c2cSDavid du Colombier
2006*0b459c2cSDavid du ColombierYou can select all unmerged changes from @var{older} to @var{yours} for merging
2007*0b459c2cSDavid du Colombierinto @var{mine} with the @samp{-e} or @samp{--ed} option.  You can
2008*0b459c2cSDavid du Colombierselect only the nonoverlapping unmerged changes with @samp{-3} or
2009*0b459c2cSDavid du Colombier@samp{--easy-only}, and you can select only the overlapping changes with
2010*0b459c2cSDavid du Colombier@samp{-x} or @samp{--overlap-only}.
2011*0b459c2cSDavid du Colombier
2012*0b459c2cSDavid du ColombierThe @samp{-e}, @samp{-3} and @samp{-x} options select only
2013*0b459c2cSDavid du Colombier@dfn{unmerged changes}, i.e.@: changes where @var{mine} and @var{yours}
2014*0b459c2cSDavid du Colombierdiffer; they ignore changes from @var{older} to @var{yours} where
2015*0b459c2cSDavid du Colombier@var{mine} and @var{yours} are identical, because they assume that such
2016*0b459c2cSDavid du Colombierchanges have already been merged.  If this assumption is not a safe
2017*0b459c2cSDavid du Colombierone, you can use the @samp{-A} or @samp{--show-all} option
2018*0b459c2cSDavid du Colombier(@pxref{Marking Conflicts}).
2019*0b459c2cSDavid du Colombier
2020*0b459c2cSDavid du ColombierHere is the output of the command @code{diff3} with each of these three
2021*0b459c2cSDavid du Colombieroptions (@pxref{Sample diff3 Input}, for the complete contents of the files).
2022*0b459c2cSDavid du ColombierNotice that @samp{-e} outputs the union of the disjoint sets of changes
2023*0b459c2cSDavid du Colombieroutput by @samp{-3} and @samp{-x}.
2024*0b459c2cSDavid du Colombier
2025*0b459c2cSDavid du ColombierOutput of @samp{diff3 -e lao tzu tao}:
2026*0b459c2cSDavid du Colombier@example
2027*0b459c2cSDavid du Colombier11a
2028*0b459c2cSDavid du Colombier
2029*0b459c2cSDavid du Colombier  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2030*0b459c2cSDavid du Colombier.
2031*0b459c2cSDavid du Colombier8c
2032*0b459c2cSDavid du Colombier  so we may see their result.
2033*0b459c2cSDavid du Colombier.
2034*0b459c2cSDavid du Colombier@end example
2035*0b459c2cSDavid du Colombier
2036*0b459c2cSDavid du ColombierOutput of @samp{diff3 -3 lao tzu tao}:
2037*0b459c2cSDavid du Colombier@example
2038*0b459c2cSDavid du Colombier8c
2039*0b459c2cSDavid du Colombier  so we may see their result.
2040*0b459c2cSDavid du Colombier.
2041*0b459c2cSDavid du Colombier@end example
2042*0b459c2cSDavid du Colombier
2043*0b459c2cSDavid du ColombierOutput of @samp{diff3 -x lao tzu tao}:
2044*0b459c2cSDavid du Colombier@example
2045*0b459c2cSDavid du Colombier11a
2046*0b459c2cSDavid du Colombier
2047*0b459c2cSDavid du Colombier  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2048*0b459c2cSDavid du Colombier.
2049*0b459c2cSDavid du Colombier@end example
2050*0b459c2cSDavid du Colombier
2051*0b459c2cSDavid du Colombier@node Marking Conflicts, Bypassing ed, Which Changes, diff3 Merging
2052*0b459c2cSDavid du Colombier@section Marking Conflicts
2053*0b459c2cSDavid du Colombier@cindex conflict marking
2054*0b459c2cSDavid du Colombier@cindex @samp{<<<<<<<} for marking conflicts
2055*0b459c2cSDavid du Colombier
2056*0b459c2cSDavid du Colombier@code{diff3} can mark conflicts in the merged output by
2057*0b459c2cSDavid du Colombierbracketing them with special marker lines.  A conflict
2058*0b459c2cSDavid du Colombierthat comes from two files @var{A} and @var{B} is marked as follows:
2059*0b459c2cSDavid du Colombier
2060*0b459c2cSDavid du Colombier@example
2061*0b459c2cSDavid du Colombier<<<<<<< @var{A}
2062*0b459c2cSDavid du Colombier@r{lines from @var{A}}
2063*0b459c2cSDavid du Colombier=======
2064*0b459c2cSDavid du Colombier@r{lines from @var{B}}
2065*0b459c2cSDavid du Colombier>>>>>>> @var{B}
2066*0b459c2cSDavid du Colombier@end example
2067*0b459c2cSDavid du Colombier
2068*0b459c2cSDavid du ColombierA conflict that comes from three files @var{A}, @var{B} and @var{C} is
2069*0b459c2cSDavid du Colombiermarked as follows:
2070*0b459c2cSDavid du Colombier
2071*0b459c2cSDavid du Colombier@example
2072*0b459c2cSDavid du Colombier<<<<<<< @var{A}
2073*0b459c2cSDavid du Colombier@r{lines from @var{A}}
2074*0b459c2cSDavid du Colombier||||||| @var{B}
2075*0b459c2cSDavid du Colombier@r{lines from @var{B}}
2076*0b459c2cSDavid du Colombier=======
2077*0b459c2cSDavid du Colombier@r{lines from @var{C}}
2078*0b459c2cSDavid du Colombier>>>>>>> @var{C}
2079*0b459c2cSDavid du Colombier@end example
2080*0b459c2cSDavid du Colombier
2081*0b459c2cSDavid du ColombierThe @samp{-A} or @samp{--show-all} option acts like the @samp{-e}
2082*0b459c2cSDavid du Colombieroption, except that it brackets conflicts, and it outputs all changes
2083*0b459c2cSDavid du Colombierfrom @var{older} to @var{yours}, not just the unmerged changes.  Thus,
2084*0b459c2cSDavid du Colombiergiven the sample input files (@pxref{Sample diff3 Input}), @samp{diff3
2085*0b459c2cSDavid du Colombier-A lao tzu tao} puts brackets around the conflict where only @file{tzu}
2086*0b459c2cSDavid du Colombierdiffers:
2087*0b459c2cSDavid du Colombier
2088*0b459c2cSDavid du Colombier@example
2089*0b459c2cSDavid du Colombier<<<<<<< tzu
2090*0b459c2cSDavid du Colombier=======
2091*0b459c2cSDavid du ColombierThe Way that can be told of is not the eternal Way;
2092*0b459c2cSDavid du ColombierThe name that can be named is not the eternal name.
2093*0b459c2cSDavid du Colombier>>>>>>> tao
2094*0b459c2cSDavid du Colombier@end example
2095*0b459c2cSDavid du Colombier
2096*0b459c2cSDavid du ColombierAnd it outputs the three-way conflict as follows:
2097*0b459c2cSDavid du Colombier
2098*0b459c2cSDavid du Colombier@example
2099*0b459c2cSDavid du Colombier<<<<<<< lao
2100*0b459c2cSDavid du Colombier||||||| tzu
2101*0b459c2cSDavid du ColombierThey both may be called deep and profound.
2102*0b459c2cSDavid du ColombierDeeper and more profound,
2103*0b459c2cSDavid du ColombierThe door of all subtleties!
2104*0b459c2cSDavid du Colombier=======
2105*0b459c2cSDavid du Colombier
2106*0b459c2cSDavid du Colombier  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2107*0b459c2cSDavid du Colombier>>>>>>> tao
2108*0b459c2cSDavid du Colombier@end example
2109*0b459c2cSDavid du Colombier
2110*0b459c2cSDavid du ColombierThe @samp{-E} or @samp{--show-overlap} option outputs less information
2111*0b459c2cSDavid du Colombierthan the @samp{-A} or @samp{--show-all} option, because it outputs only
2112*0b459c2cSDavid du Colombierunmerged changes, and it never outputs the contents of the second
2113*0b459c2cSDavid du Colombierfile.  Thus the @samp{-E} option acts like the @samp{-e} option,
2114*0b459c2cSDavid du Colombierexcept that it brackets the first and third files from three-way
2115*0b459c2cSDavid du Colombieroverlapping changes.  Similarly, @samp{-X} acts like @samp{-x}, except
2116*0b459c2cSDavid du Colombierit brackets all its (necessarily overlapping) changes.  For example,
2117*0b459c2cSDavid du Colombierfor the three-way overlapping change above, the @samp{-E} and @samp{-X}
2118*0b459c2cSDavid du Colombieroptions output the following:
2119*0b459c2cSDavid du Colombier
2120*0b459c2cSDavid du Colombier@example
2121*0b459c2cSDavid du Colombier<<<<<<< lao
2122*0b459c2cSDavid du Colombier=======
2123*0b459c2cSDavid du Colombier
2124*0b459c2cSDavid du Colombier  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2125*0b459c2cSDavid du Colombier>>>>>>> tao
2126*0b459c2cSDavid du Colombier@end example
2127*0b459c2cSDavid du Colombier
2128*0b459c2cSDavid du ColombierIf you are comparing files that have meaningless or uninformative names,
2129*0b459c2cSDavid du Colombieryou can use the @samp{-L @var{label}} or @samp{--label=@var{label}}
2130*0b459c2cSDavid du Colombieroption to show alternate names in the @samp{<<<<<<<}, @samp{|||||||}
2131*0b459c2cSDavid du Colombierand @samp{>>>>>>>} brackets.  This option can be given up to three
2132*0b459c2cSDavid du Colombiertimes, once for each input file.  Thus @samp{diff3 -A -L X -L Y -L Z A
2133*0b459c2cSDavid du ColombierB C} acts like @samp{diff3 -A A B C}, except that the output looks like
2134*0b459c2cSDavid du Colombierit came from files named @samp{X}, @samp{Y} and @samp{Z} rather than
2135*0b459c2cSDavid du Colombierfrom files named @samp{A}, @samp{B} and @samp{C}.
2136*0b459c2cSDavid du Colombier
2137*0b459c2cSDavid du Colombier@node Bypassing ed, Merging Incomplete Lines, Marking Conflicts, diff3 Merging
2138*0b459c2cSDavid du Colombier@section Generating the Merged Output Directly
2139*0b459c2cSDavid du Colombier@cindex merged @code{diff3} format
2140*0b459c2cSDavid du Colombier
2141*0b459c2cSDavid du ColombierWith the @samp{-m} or @samp{--merge} option, @code{diff3} outputs the
2142*0b459c2cSDavid du Colombiermerged file directly.  This is more efficient than using @code{ed} to
2143*0b459c2cSDavid du Colombiergenerate it, and works even with non-text files that @code{ed} would
2144*0b459c2cSDavid du Colombierreject.  If you specify @samp{-m} without an @code{ed} script option,
2145*0b459c2cSDavid du Colombier@samp{-A} (@samp{--show-all}) is assumed.
2146*0b459c2cSDavid du Colombier
2147*0b459c2cSDavid du ColombierFor example, the command @samp{diff3 -m lao tzu tao}
2148*0b459c2cSDavid du Colombier(@pxref{Sample diff3 Input} for a copy of the input files) would output
2149*0b459c2cSDavid du Colombierthe following:
2150*0b459c2cSDavid du Colombier
2151*0b459c2cSDavid du Colombier@example
2152*0b459c2cSDavid du Colombier<<<<<<< tzu
2153*0b459c2cSDavid du Colombier=======
2154*0b459c2cSDavid du ColombierThe Way that can be told of is not the eternal Way;
2155*0b459c2cSDavid du ColombierThe name that can be named is not the eternal name.
2156*0b459c2cSDavid du Colombier>>>>>>> tao
2157*0b459c2cSDavid du ColombierThe Nameless is the origin of Heaven and Earth;
2158*0b459c2cSDavid du ColombierThe Named is the mother of all things.
2159*0b459c2cSDavid du ColombierTherefore let there always be non-being,
2160*0b459c2cSDavid du Colombier  so we may see their subtlety,
2161*0b459c2cSDavid du ColombierAnd let there always be being,
2162*0b459c2cSDavid du Colombier  so we may see their result.
2163*0b459c2cSDavid du ColombierThe two are the same,
2164*0b459c2cSDavid du ColombierBut after they are produced,
2165*0b459c2cSDavid du Colombier  they have different names.
2166*0b459c2cSDavid du Colombier<<<<<<< lao
2167*0b459c2cSDavid du Colombier||||||| tzu
2168*0b459c2cSDavid du ColombierThey both may be called deep and profound.
2169*0b459c2cSDavid du ColombierDeeper and more profound,
2170*0b459c2cSDavid du ColombierThe door of all subtleties!
2171*0b459c2cSDavid du Colombier=======
2172*0b459c2cSDavid du Colombier
2173*0b459c2cSDavid du Colombier  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2174*0b459c2cSDavid du Colombier>>>>>>> tao
2175*0b459c2cSDavid du Colombier@end example
2176*0b459c2cSDavid du Colombier
2177*0b459c2cSDavid du Colombier@node Merging Incomplete Lines, Saving the Changed File, Bypassing ed, diff3 Merging
2178*0b459c2cSDavid du Colombier@section How @code{diff3} Merges Incomplete Lines
2179*0b459c2cSDavid du Colombier@cindex incomplete line merging
2180*0b459c2cSDavid du Colombier
2181*0b459c2cSDavid du ColombierWith @samp{-m}, incomplete lines (@pxref{Incomplete Lines}) are simply
2182*0b459c2cSDavid du Colombiercopied to the output as they are found; if the merged output ends in an
2183*0b459c2cSDavid du Colombierconflict and one of the input files ends in an incomplete
2184*0b459c2cSDavid du Colombierline, succeeding @samp{|||||||}, @samp{=======} or @samp{>>>>>>>}
2185*0b459c2cSDavid du Colombierbrackets appear somewhere other than the start of a line because
2186*0b459c2cSDavid du Colombierthey are appended to the incomplete line.
2187*0b459c2cSDavid du Colombier
2188*0b459c2cSDavid du ColombierWithout @samp{-m}, if an @code{ed} script option is specified and an
2189*0b459c2cSDavid du Colombierincomplete line is found, @code{diff3} generates a warning and acts as
2190*0b459c2cSDavid du Colombierif a newline had been present.
2191*0b459c2cSDavid du Colombier
2192*0b459c2cSDavid du Colombier@node Saving the Changed File, , Merging Incomplete Lines, diff3 Merging
2193*0b459c2cSDavid du Colombier@section Saving the Changed File
2194*0b459c2cSDavid du Colombier@cindex System V @code{diff3} compatibility
2195*0b459c2cSDavid du Colombier
2196*0b459c2cSDavid du ColombierTraditional Unix @code{diff3} generates an @code{ed} script without the
2197*0b459c2cSDavid du Colombiertrailing @samp{w} and and @samp{q} commands that save the changes.
2198*0b459c2cSDavid du ColombierSystem V @code{diff3} generates these extra commands.  GNU @code{diff3}
2199*0b459c2cSDavid du Colombiernormally behaves like traditional Unix @code{diff3}, but with the
2200*0b459c2cSDavid du Colombier@samp{-i} option it behaves like System V @code{diff3} and appends the
2201*0b459c2cSDavid du Colombier@samp{w} and @samp{q} commands.
2202*0b459c2cSDavid du Colombier
2203*0b459c2cSDavid du ColombierThe @samp{-i} option requires one of the @code{ed} script options
2204*0b459c2cSDavid du Colombier@samp{-AeExX3}, and is incompatible with the merged output option
2205*0b459c2cSDavid du Colombier@samp{-m}.
2206*0b459c2cSDavid du Colombier
2207*0b459c2cSDavid du Colombier@node Interactive Merging, Merging with patch, diff3 Merging, Top
2208*0b459c2cSDavid du Colombier@chapter Interactive Merging with @code{sdiff}
2209*0b459c2cSDavid du Colombier@cindex diff merging
2210*0b459c2cSDavid du Colombier@cindex interactive merging
2211*0b459c2cSDavid du Colombier
2212*0b459c2cSDavid du ColombierWith @code{sdiff}, you can merge two files interactively based on a
2213*0b459c2cSDavid du Colombierside-by-side @samp{-y} format comparison (@pxref{Side by Side}).  Use
2214*0b459c2cSDavid du Colombier@samp{-o @var{file}} or @samp{--output=@var{file}} to specify where to
2215*0b459c2cSDavid du Colombierput the merged text.  @xref{Invoking sdiff}, for more details on the
2216*0b459c2cSDavid du Colombieroptions to @code{sdiff}.
2217*0b459c2cSDavid du Colombier
2218*0b459c2cSDavid du ColombierAnother way to merge files interactively is to use the Emacs Lisp
2219*0b459c2cSDavid du Colombierpackage @code{emerge}.  @xref{emerge, , emerge, emacs, The GNU Emacs
2220*0b459c2cSDavid du ColombierManual}, for more information.
2221*0b459c2cSDavid du Colombier
2222*0b459c2cSDavid du Colombier@menu
2223*0b459c2cSDavid du Colombier* sdiff Option Summary::Summary of @code{sdiff} options.
2224*0b459c2cSDavid du Colombier* Merge Commands::	Merging two files interactively.
2225*0b459c2cSDavid du Colombier@end menu
2226*0b459c2cSDavid du Colombier
2227*0b459c2cSDavid du Colombier@node sdiff Option Summary, Merge Commands, , Interactive Merging
2228*0b459c2cSDavid du Colombier@section Specifying @code{diff} Options to @code{sdiff}
2229*0b459c2cSDavid du Colombier@cindex @code{sdiff} output format
2230*0b459c2cSDavid du Colombier
2231*0b459c2cSDavid du ColombierThe following @code{sdiff} options have the same meaning as for
2232*0b459c2cSDavid du Colombier@code{diff}.  @xref{diff Options}, for the use of these options.
2233*0b459c2cSDavid du Colombier
2234*0b459c2cSDavid du Colombier@example
2235*0b459c2cSDavid du Colombier-a -b -d -i -t -v
2236*0b459c2cSDavid du Colombier-B -H -I @var{regexp}
2237*0b459c2cSDavid du Colombier
2238*0b459c2cSDavid du Colombier--ignore-blank-lines  --ignore-case
2239*0b459c2cSDavid du Colombier--ignore-matching-lines=@var{regexp}  --ignore-space-change
2240*0b459c2cSDavid du Colombier--left-column  --minimal  --speed-large-files
2241*0b459c2cSDavid du Colombier--suppress-common-lines  --expand-tabs
2242*0b459c2cSDavid du Colombier--text  --version  --width=@var{columns}
2243*0b459c2cSDavid du Colombier@end example
2244*0b459c2cSDavid du Colombier
2245*0b459c2cSDavid du ColombierFor historical reasons, @code{sdiff} has alternate names for some
2246*0b459c2cSDavid du Colombieroptions.  The @samp{-l} option is equivalent to the @samp{--left-column}
2247*0b459c2cSDavid du Colombieroption, and similarly @samp{-s} is equivalent to
2248*0b459c2cSDavid du Colombier@samp{--suppress-common-lines}.  The meaning of the @code{sdiff}
2249*0b459c2cSDavid du Colombier@samp{-w} and @samp{-W} options is interchanged from that of
2250*0b459c2cSDavid du Colombier@code{diff}: with @code{sdiff}, @samp{-w @var{columns}} is equivalent to
2251*0b459c2cSDavid du Colombier@samp{--width=@var{columns}}, and @samp{-W} is equivalent to
2252*0b459c2cSDavid du Colombier@samp{--ignore-all-space}.  @code{sdiff} without the @samp{-o} option is
2253*0b459c2cSDavid du Colombierequivalent to @code{diff} with the @samp{-y} or @samp{--side-by-side}
2254*0b459c2cSDavid du Colombieroption (@pxref{Side by Side}).
2255*0b459c2cSDavid du Colombier
2256*0b459c2cSDavid du Colombier@node Merge Commands, , sdiff Option Summary, Interactive Merging
2257*0b459c2cSDavid du Colombier@section Merge Commands
2258*0b459c2cSDavid du Colombier@cindex merge commands
2259*0b459c2cSDavid du Colombier@cindex merging interactively
2260*0b459c2cSDavid du Colombier
2261*0b459c2cSDavid du ColombierGroups of common lines, with a blank gutter, are copied from the first
2262*0b459c2cSDavid du Colombierfile to the output.  After each group of differing lines, @code{sdiff}
2263*0b459c2cSDavid du Colombierprompts with @samp{%} and pauses, waiting for one of the following
2264*0b459c2cSDavid du Colombiercommands.  Follow each command with @key{RET}.
2265*0b459c2cSDavid du Colombier
2266*0b459c2cSDavid du Colombier@table @samp
2267*0b459c2cSDavid du Colombier@item e
2268*0b459c2cSDavid du ColombierDiscard both versions.
2269*0b459c2cSDavid du ColombierInvoke a text editor on an empty temporary file,
2270*0b459c2cSDavid du Colombierthen copy the resulting file to the output.
2271*0b459c2cSDavid du Colombier
2272*0b459c2cSDavid du Colombier@item eb
2273*0b459c2cSDavid du ColombierConcatenate the two versions, edit the result in a temporary file,
2274*0b459c2cSDavid du Colombierthen copy the edited result to the output.
2275*0b459c2cSDavid du Colombier
2276*0b459c2cSDavid du Colombier@item el
2277*0b459c2cSDavid du ColombierEdit a copy of the left version, then copy the result to the output.
2278*0b459c2cSDavid du Colombier
2279*0b459c2cSDavid du Colombier@item er
2280*0b459c2cSDavid du ColombierEdit a copy of the right version, then copy the result to the output.
2281*0b459c2cSDavid du Colombier
2282*0b459c2cSDavid du Colombier@item l
2283*0b459c2cSDavid du ColombierCopy the left version to the output.
2284*0b459c2cSDavid du Colombier
2285*0b459c2cSDavid du Colombier@item q
2286*0b459c2cSDavid du ColombierQuit.
2287*0b459c2cSDavid du Colombier
2288*0b459c2cSDavid du Colombier@item r
2289*0b459c2cSDavid du ColombierCopy the right version to the output.
2290*0b459c2cSDavid du Colombier
2291*0b459c2cSDavid du Colombier@item s
2292*0b459c2cSDavid du ColombierSilently copy common lines.
2293*0b459c2cSDavid du Colombier
2294*0b459c2cSDavid du Colombier@item v
2295*0b459c2cSDavid du ColombierVerbosely copy common lines.  This is the default.
2296*0b459c2cSDavid du Colombier@end table
2297*0b459c2cSDavid du Colombier
2298*0b459c2cSDavid du ColombierThe text editor invoked is specified by the @code{EDITOR} environment
2299*0b459c2cSDavid du Colombiervariable if it is set.  The default is system-dependent.
2300*0b459c2cSDavid du Colombier
2301*0b459c2cSDavid du Colombier@node Merging with patch, Making Patches, Interactive Merging, Top
2302*0b459c2cSDavid du Colombier@chapter Merging with @code{patch}
2303*0b459c2cSDavid du Colombier
2304*0b459c2cSDavid du Colombier@code{patch} takes comparison output produced by @code{diff} and applies
2305*0b459c2cSDavid du Colombierthe differences to a copy of the original file, producing a patched
2306*0b459c2cSDavid du Colombierversion.  With @code{patch}, you can distribute just the changes to a
2307*0b459c2cSDavid du Colombierset of files instead of distributing the entire file set; your
2308*0b459c2cSDavid du Colombiercorrespondents can apply @code{patch} to update their copy of the files
2309*0b459c2cSDavid du Colombierwith your changes.  @code{patch} automatically determines the diff
2310*0b459c2cSDavid du Colombierformat, skips any leading or trailing headers, and uses the headers to
2311*0b459c2cSDavid du Colombierdetermine which file to patch.  This lets your correspondents feed an
2312*0b459c2cSDavid du Colombierarticle or message containing a difference listing directly to
2313*0b459c2cSDavid du Colombier@code{patch}.
2314*0b459c2cSDavid du Colombier
2315*0b459c2cSDavid du Colombier@code{patch} detects and warns about common problems like forward
2316*0b459c2cSDavid du Colombierpatches.  It saves the original version of the files it patches, and
2317*0b459c2cSDavid du Colombiersaves any patches that it could not apply.  It can also maintain a
2318*0b459c2cSDavid du Colombier@code{patchlevel.h} file to ensures that your correspondents apply
2319*0b459c2cSDavid du Colombierdiffs in the proper order.
2320*0b459c2cSDavid du Colombier
2321*0b459c2cSDavid du Colombier@code{patch} accepts a series of diffs in its standard input, usually
2322*0b459c2cSDavid du Colombierseparated by headers that specify which file to patch.  It applies
2323*0b459c2cSDavid du Colombier@code{diff} hunks (@pxref{Hunks}) one by one.  If a hunk does not
2324*0b459c2cSDavid du Colombierexactly match the original file, @code{patch} uses heuristics to try to
2325*0b459c2cSDavid du Colombierpatch the file as well as it can.  If no approximate match can be found,
2326*0b459c2cSDavid du Colombier@code{patch} rejects the hunk and skips to the next hunk.  @code{patch}
2327*0b459c2cSDavid du Colombiernormally replaces each file @var{f} with its new version, saving the
2328*0b459c2cSDavid du Colombieroriginal file in @samp{@var{f}.orig}, and putting reject hunks (if any)
2329*0b459c2cSDavid du Colombierinto @samp{@var{f}.rej}.
2330*0b459c2cSDavid du Colombier
2331*0b459c2cSDavid du Colombier@xref{Invoking patch}, for detailed information on the options to
2332*0b459c2cSDavid du Colombier@code{patch}.  @xref{Backups}, for more information on how
2333*0b459c2cSDavid du Colombier@code{patch} names backup files.  @xref{Rejects}, for more information
2334*0b459c2cSDavid du Colombieron where @code{patch} puts reject hunks.
2335*0b459c2cSDavid du Colombier
2336*0b459c2cSDavid du Colombier@menu
2337*0b459c2cSDavid du Colombier* patch Input::		Selecting the type of @code{patch} input.
2338*0b459c2cSDavid du Colombier* Imperfect::		Dealing with imperfect patches.
2339*0b459c2cSDavid du Colombier* Empty Files::		Removing empty files after patching.
2340*0b459c2cSDavid du Colombier* Multiple Patches::	Handling multiple patches in a file specially.
2341*0b459c2cSDavid du Colombier* patch Messages::	Messages and questions @code{patch} can produce.
2342*0b459c2cSDavid du Colombier@end menu
2343*0b459c2cSDavid du Colombier
2344*0b459c2cSDavid du Colombier@node patch Input, Imperfect, , Merging with patch
2345*0b459c2cSDavid du Colombier@section Selecting the @code{patch} Input Format
2346*0b459c2cSDavid du Colombier@cindex @code{patch} input format
2347*0b459c2cSDavid du Colombier
2348*0b459c2cSDavid du Colombier@code{patch} normally determines which @code{diff} format the patch
2349*0b459c2cSDavid du Colombierfile uses by examining its contents.  For patch files that contain
2350*0b459c2cSDavid du Colombierparticularly confusing leading text, you might need to use one of the
2351*0b459c2cSDavid du Colombierfollowing options to force @code{patch} to interpret the patch file as a
2352*0b459c2cSDavid du Colombiercertain format of diff.  The output formats listed here are the only
2353*0b459c2cSDavid du Colombierones that @code{patch} can understand.
2354*0b459c2cSDavid du Colombier
2355*0b459c2cSDavid du Colombier@table @samp
2356*0b459c2cSDavid du Colombier@item -c
2357*0b459c2cSDavid du Colombier@itemx --context
2358*0b459c2cSDavid du Colombiercontext diff.
2359*0b459c2cSDavid du Colombier
2360*0b459c2cSDavid du Colombier@item -e
2361*0b459c2cSDavid du Colombier@itemx --ed
2362*0b459c2cSDavid du Colombier@code{ed} script.
2363*0b459c2cSDavid du Colombier
2364*0b459c2cSDavid du Colombier@item -n
2365*0b459c2cSDavid du Colombier@itemx --normal
2366*0b459c2cSDavid du Colombiernormal diff.
2367*0b459c2cSDavid du Colombier
2368*0b459c2cSDavid du Colombier@item -u
2369*0b459c2cSDavid du Colombier@itemx --unified
2370*0b459c2cSDavid du Colombierunified diff.
2371*0b459c2cSDavid du Colombier@end table
2372*0b459c2cSDavid du Colombier
2373*0b459c2cSDavid du Colombier@node Imperfect, Empty Files, patch Input, Merging with patch
2374*0b459c2cSDavid du Colombier@section Applying Imperfect Patches
2375*0b459c2cSDavid du Colombier@cindex imperfect patch application
2376*0b459c2cSDavid du Colombier
2377*0b459c2cSDavid du Colombier@code{patch} tries to skip any leading text in the patch file, apply the
2378*0b459c2cSDavid du Colombierdiff, and then skip any trailing text.  Thus you can feed a news article
2379*0b459c2cSDavid du Colombieror mail message directly to @code{patch}, and it should work.  If the
2380*0b459c2cSDavid du Colombierentire diff is indented by a constant amount of white space, @code{patch}
2381*0b459c2cSDavid du Colombierautomatically ignores the indentation.
2382*0b459c2cSDavid du Colombier
2383*0b459c2cSDavid du ColombierHowever, certain other types of imperfect input require user
2384*0b459c2cSDavid du Colombierintervention.
2385*0b459c2cSDavid du Colombier
2386*0b459c2cSDavid du Colombier@menu
2387*0b459c2cSDavid du Colombier* Changed White Space::	When tabs and spaces don't match exactly.
2388*0b459c2cSDavid du Colombier* Reversed Patches::	Applying reversed patches correctly.
2389*0b459c2cSDavid du Colombier* Inexact::		Helping @code{patch} find close matches.
2390*0b459c2cSDavid du Colombier@end menu
2391*0b459c2cSDavid du Colombier
2392*0b459c2cSDavid du Colombier@node Changed White Space, Reversed Patches, , Imperfect
2393*0b459c2cSDavid du Colombier@subsection Applying Patches with Changed White Space
2394*0b459c2cSDavid du Colombier@cindex white space in patches
2395*0b459c2cSDavid du Colombier
2396*0b459c2cSDavid du ColombierSometimes mailers, editors, or other programs change spaces into tabs,
2397*0b459c2cSDavid du Colombieror vice versa.  If this happens to a patch file or an input file, the
2398*0b459c2cSDavid du Colombierfiles might look the same, but @code{patch} will not be able to match
2399*0b459c2cSDavid du Colombierthem properly.  If this problem occurs, use the @samp{-l} or
2400*0b459c2cSDavid du Colombier@samp{--ignore-white-space} option, which makes @code{patch} compare
2401*0b459c2cSDavid du Colombierwhite space loosely so that any sequence of white space in the patch file
2402*0b459c2cSDavid du Colombiermatches any sequence of white space in the input files.  Non-white-space
2403*0b459c2cSDavid du Colombiercharacters must still match exactly.  Each line of the context must
2404*0b459c2cSDavid du Colombierstill match a line in the input file.
2405*0b459c2cSDavid du Colombier
2406*0b459c2cSDavid du Colombier@node Reversed Patches, Inexact, Changed White Space, Imperfect
2407*0b459c2cSDavid du Colombier@subsection Applying Reversed Patches
2408*0b459c2cSDavid du Colombier@cindex reversed patches
2409*0b459c2cSDavid du Colombier
2410*0b459c2cSDavid du ColombierSometimes people run @code{diff} with the new file first instead of
2411*0b459c2cSDavid du Colombiersecond.  This creates a diff that is ``reversed''.  To apply such
2412*0b459c2cSDavid du Colombierpatches, give @code{patch} the @samp{-R} or @samp{--reverse} option.
2413*0b459c2cSDavid du Colombier@code{patch} then attempts to swap each hunk around before applying it.
2414*0b459c2cSDavid du ColombierRejects come out in the swapped format.  The @samp{-R} option does not
2415*0b459c2cSDavid du Colombierwork with @code{ed} scripts because there is too little information in
2416*0b459c2cSDavid du Colombierthem to reconstruct the reverse operation.
2417*0b459c2cSDavid du Colombier
2418*0b459c2cSDavid du ColombierOften @code{patch} can guess that the patch is reversed.  If the first
2419*0b459c2cSDavid du Colombierhunk of a patch fails, @code{patch} reverses the hunk to see if it can
2420*0b459c2cSDavid du Colombierapply it that way.  If it can, @code{patch} asks you if you want to have
2421*0b459c2cSDavid du Colombierthe @samp{-R} option set; if it can't, @code{patch} continues to apply
2422*0b459c2cSDavid du Colombierthe patch normally.  This method cannot detect a reversed patch if it is
2423*0b459c2cSDavid du Colombiera normal diff and the first command is an append (which should have been
2424*0b459c2cSDavid du Colombiera delete) since appends always succeed, because a null context matches
2425*0b459c2cSDavid du Colombieranywhere.  But most patches add or change lines rather than delete them,
2426*0b459c2cSDavid du Colombierso most reversed normal diffs begin with a delete, which fails, and
2427*0b459c2cSDavid du Colombier@code{patch} notices.
2428*0b459c2cSDavid du Colombier
2429*0b459c2cSDavid du ColombierIf you apply a patch that you have already applied, @code{patch} thinks
2430*0b459c2cSDavid du Colombierit is a reversed patch and offers to un-apply the patch.  This could be
2431*0b459c2cSDavid du Colombierconstrued as a feature.  If you did this inadvertently and you don't
2432*0b459c2cSDavid du Colombierwant to un-apply the patch, just answer @samp{n} to this offer and to
2433*0b459c2cSDavid du Colombierthe subsequent ``apply anyway'' question---or type @kbd{C-c} to kill the
2434*0b459c2cSDavid du Colombier@code{patch} process.
2435*0b459c2cSDavid du Colombier
2436*0b459c2cSDavid du Colombier@node Inexact, , Reversed Patches, Imperfect
2437*0b459c2cSDavid du Colombier@subsection Helping @code{patch} Find Inexact Matches
2438*0b459c2cSDavid du Colombier@cindex inexact patches
2439*0b459c2cSDavid du Colombier@cindex fuzz factor when patching
2440*0b459c2cSDavid du Colombier
2441*0b459c2cSDavid du ColombierFor context diffs, and to a lesser extent normal diffs, @code{patch} can
2442*0b459c2cSDavid du Colombierdetect when the line numbers mentioned in the patch are incorrect, and
2443*0b459c2cSDavid du Colombierit attempts to find the correct place to apply each hunk of the patch.
2444*0b459c2cSDavid du ColombierAs a first guess, it takes the line number mentioned in the hunk, plus
2445*0b459c2cSDavid du Colombieror minus any offset used in applying the previous hunk.  If that is not
2446*0b459c2cSDavid du Colombierthe correct place, @code{patch} scans both forward and backward for a
2447*0b459c2cSDavid du Colombierset of lines matching the context given in the hunk.
2448*0b459c2cSDavid du Colombier
2449*0b459c2cSDavid du ColombierFirst @code{patch} looks for a place where all lines of the context
2450*0b459c2cSDavid du Colombiermatch.  If it cannot find such a place, and it is reading a context or
2451*0b459c2cSDavid du Colombierunified diff, and the maximum fuzz factor is set to 1 or more, then
2452*0b459c2cSDavid du Colombier@code{patch} makes another scan, ignoring the first and last line of
2453*0b459c2cSDavid du Colombiercontext.  If that fails, and the maximum fuzz factor is set to 2 or
2454*0b459c2cSDavid du Colombiermore, it makes another scan, ignoring the first two and last two lines
2455*0b459c2cSDavid du Colombierof context are ignored.  It continues similarly if the maximum fuzz
2456*0b459c2cSDavid du Colombierfactor is larger.
2457*0b459c2cSDavid du Colombier
2458*0b459c2cSDavid du ColombierThe @samp{-F @var{lines}} or @samp{--fuzz=@var{lines}} option sets the
2459*0b459c2cSDavid du Colombiermaximum fuzz factor to @var{lines}.  This option only applies to context
2460*0b459c2cSDavid du Colombierand unified diffs; it ignores up to @var{lines} lines while looking for
2461*0b459c2cSDavid du Colombierthe place to install a hunk.  Note that a larger fuzz factor increases
2462*0b459c2cSDavid du Colombierthe odds of making a faulty patch.  The default fuzz factor is 2; it may
2463*0b459c2cSDavid du Colombiernot be set to more than the number of lines of context in the diff,
2464*0b459c2cSDavid du Colombierordinarily 3.
2465*0b459c2cSDavid du Colombier
2466*0b459c2cSDavid du ColombierIf @code{patch} cannot find a place to install a hunk of the patch, it
2467*0b459c2cSDavid du Colombierwrites the hunk out to a reject file (@pxref{Rejects}, for information
2468*0b459c2cSDavid du Colombieron how reject files are named).  It writes out rejected hunks in context
2469*0b459c2cSDavid du Colombierformat no matter what form the input patch is in.  If the input is a
2470*0b459c2cSDavid du Colombiernormal or @code{ed} diff, many of the contexts are simply null.  The
2471*0b459c2cSDavid du Colombierline numbers on the hunks in the reject file may be different from those
2472*0b459c2cSDavid du Colombierin the patch file: they show the approximate location where @code{patch}
2473*0b459c2cSDavid du Colombierthinks the failed hunks belong in the new file rather than in the old
2474*0b459c2cSDavid du Colombierone.
2475*0b459c2cSDavid du Colombier
2476*0b459c2cSDavid du ColombierAs it completes each hunk, @code{patch} tells you whether the hunk
2477*0b459c2cSDavid du Colombiersucceeded or failed, and if it failed, on which line (in the new file)
2478*0b459c2cSDavid du Colombier@code{patch} thinks the hunk should go.  If this is different from the
2479*0b459c2cSDavid du Colombierline number specified in the diff, it tells you the offset.  A single
2480*0b459c2cSDavid du Colombierlarge offset @emph{may} indicate that @code{patch} installed a hunk in
2481*0b459c2cSDavid du Colombierthe wrong place.  @code{patch} also tells you if it used a fuzz factor
2482*0b459c2cSDavid du Colombierto make the match, in which case you should also be slightly suspicious.
2483*0b459c2cSDavid du Colombier
2484*0b459c2cSDavid du Colombier@code{patch} cannot tell if the line numbers are off in an @code{ed}
2485*0b459c2cSDavid du Colombierscript, and can only detect wrong line numbers in a normal diff when it
2486*0b459c2cSDavid du Colombierfinds a change or delete command.  It may have the same problem with a
2487*0b459c2cSDavid du Colombiercontext diff using a fuzz factor equal to or greater than the number of
2488*0b459c2cSDavid du Colombierlines of context shown in the diff (typically 3).  In these cases, you
2489*0b459c2cSDavid du Colombiershould probably look at a context diff between your original and patched
2490*0b459c2cSDavid du Colombierinput files to see if the changes make sense.  Compiling without errors
2491*0b459c2cSDavid du Colombieris a pretty good indication that the patch worked, but not a guarantee.
2492*0b459c2cSDavid du Colombier
2493*0b459c2cSDavid du Colombier@code{patch} usually produces the correct results, even when it must
2494*0b459c2cSDavid du Colombiermake many guesses.  However, the results are guaranteed only when
2495*0b459c2cSDavid du Colombierthe patch is applied to an exact copy of the file that the patch was
2496*0b459c2cSDavid du Colombiergenerated from.
2497*0b459c2cSDavid du Colombier
2498*0b459c2cSDavid du Colombier@node Empty Files, Multiple Patches, Imperfect, Merging with patch
2499*0b459c2cSDavid du Colombier@section Removing Empty Files
2500*0b459c2cSDavid du Colombier@cindex empty files, removing
2501*0b459c2cSDavid du Colombier@cindex removing empty files
2502*0b459c2cSDavid du Colombier
2503*0b459c2cSDavid du ColombierSometimes when comparing two directories, the first directory contains a
2504*0b459c2cSDavid du Colombierfile that the second directory does not.  If you give @code{diff} the
2505*0b459c2cSDavid du Colombier@samp{-N} or @samp{--new-file} option, it outputs a diff that deletes
2506*0b459c2cSDavid du Colombierthe contents of this file.  By default, @code{patch} leaves an empty
2507*0b459c2cSDavid du Colombierfile after applying such a diff.  The @samp{-E} or
2508*0b459c2cSDavid du Colombier@samp{--remove-empty-files} option to @code{patch} deletes output files
2509*0b459c2cSDavid du Colombierthat are empty after applying the diff.
2510*0b459c2cSDavid du Colombier
2511*0b459c2cSDavid du Colombier@node Multiple Patches, patch Messages, Empty Files, Merging with patch
2512*0b459c2cSDavid du Colombier@section Multiple Patches in a File
2513*0b459c2cSDavid du Colombier@cindex multiple patches
2514*0b459c2cSDavid du Colombier
2515*0b459c2cSDavid du ColombierIf the patch file contains more than one patch, @code{patch} tries to
2516*0b459c2cSDavid du Colombierapply each of them as if they came from separate patch files.  This
2517*0b459c2cSDavid du Colombiermeans that it determines the name of the file to patch for each patch,
2518*0b459c2cSDavid du Colombierand that it examines the leading text before each patch for file names
2519*0b459c2cSDavid du Colombierand prerequisite revision level (@pxref{Making Patches}, for more on
2520*0b459c2cSDavid du Colombierthat topic).
2521*0b459c2cSDavid du Colombier
2522*0b459c2cSDavid du ColombierFor the second and subsequent patches in the patch file, you can give
2523*0b459c2cSDavid du Colombieroptions and another original file name by separating their argument
2524*0b459c2cSDavid du Colombierlists with a @samp{+}.  However, the argument list for a second or
2525*0b459c2cSDavid du Colombiersubsequent patch may not specify a new patch file, since that does not
2526*0b459c2cSDavid du Colombiermake sense.
2527*0b459c2cSDavid du Colombier
2528*0b459c2cSDavid du ColombierFor example, to tell @code{patch} to strip the first three slashes from
2529*0b459c2cSDavid du Colombierthe name of the first patch in the patch file and none from subsequent
2530*0b459c2cSDavid du Colombierpatches, and to use @file{code.c} as the first input file, you can use:
2531*0b459c2cSDavid du Colombier
2532*0b459c2cSDavid du Colombier@example
2533*0b459c2cSDavid du Colombierpatch -p3 code.c + -p0 < patchfile
2534*0b459c2cSDavid du Colombier@end example
2535*0b459c2cSDavid du Colombier
2536*0b459c2cSDavid du ColombierThe @samp{-S} or @samp{--skip} option ignores the current patch from the
2537*0b459c2cSDavid du Colombierpatch file, but continue looking for the next patch in the file.  Thus,
2538*0b459c2cSDavid du Colombierto ignore the first and third patches in the patch file, you can use:
2539*0b459c2cSDavid du Colombier
2540*0b459c2cSDavid du Colombier@example
2541*0b459c2cSDavid du Colombierpatch -S + + -S + < patch file
2542*0b459c2cSDavid du Colombier@end example
2543*0b459c2cSDavid du Colombier
2544*0b459c2cSDavid du Colombier@node patch Messages, , Multiple Patches, Merging with patch
2545*0b459c2cSDavid du Colombier@section Messages and Questions from @code{patch}
2546*0b459c2cSDavid du Colombier@cindex @code{patch} messages and questions
2547*0b459c2cSDavid du Colombier@cindex diagnostics from @code{patch}
2548*0b459c2cSDavid du Colombier@cindex messages from @code{patch}
2549*0b459c2cSDavid du Colombier
2550*0b459c2cSDavid du Colombier@code{patch} can produce a variety of messages, especially if it has
2551*0b459c2cSDavid du Colombiertrouble decoding its input.  In a few situations where it's not sure how
2552*0b459c2cSDavid du Colombierto proceed, @code{patch} normally prompts you for more information from
2553*0b459c2cSDavid du Colombierthe keyboard.  There are options to suppress printing non-fatal messages
2554*0b459c2cSDavid du Colombierand stopping for keyboard input.
2555*0b459c2cSDavid du Colombier
2556*0b459c2cSDavid du ColombierThe message @samp{Hmm...} indicates that @code{patch} is reading text in
2557*0b459c2cSDavid du Colombierthe patch file, attempting to determine whether there is a patch in that
2558*0b459c2cSDavid du Colombiertext, and if so, what kind of patch it is.
2559*0b459c2cSDavid du Colombier
2560*0b459c2cSDavid du ColombierYou can inhibit all terminal output from @code{patch}, unless an error
2561*0b459c2cSDavid du Colombieroccurs, by using the @samp{-s}, @samp{--quiet}, or @samp{--silent}
2562*0b459c2cSDavid du Colombieroption.
2563*0b459c2cSDavid du Colombier
2564*0b459c2cSDavid du ColombierThere are two ways you can prevent @code{patch} from asking you any
2565*0b459c2cSDavid du Colombierquestions.  The @samp{-f} or @samp{--force} option assumes that you know
2566*0b459c2cSDavid du Colombierwhat you are doing.  It assumes the following:
2567*0b459c2cSDavid du Colombier
2568*0b459c2cSDavid du Colombier@itemize @bullet
2569*0b459c2cSDavid du Colombier@item
2570*0b459c2cSDavid du Colombierskip patches that do not contain file names in their headers;
2571*0b459c2cSDavid du Colombier
2572*0b459c2cSDavid du Colombier@item
2573*0b459c2cSDavid du Colombierpatch files even though they have the wrong version for the
2574*0b459c2cSDavid du Colombier@samp{Prereq:} line in the patch;
2575*0b459c2cSDavid du Colombier
2576*0b459c2cSDavid du Colombier@item
2577*0b459c2cSDavid du Colombierassume that patches are not reversed even if they look like they are.
2578*0b459c2cSDavid du Colombier@end itemize
2579*0b459c2cSDavid du Colombier
2580*0b459c2cSDavid du ColombierThe @samp{-t} or @samp{--batch} option is similar to @samp{-f}, in that
2581*0b459c2cSDavid du Colombierit suppresses questions, but it makes somewhat different assumptions:
2582*0b459c2cSDavid du Colombier
2583*0b459c2cSDavid du Colombier@itemize @bullet
2584*0b459c2cSDavid du Colombier@item
2585*0b459c2cSDavid du Colombierskip patches that do not contain file names in their headers
2586*0b459c2cSDavid du Colombier(the same as @samp{-f});
2587*0b459c2cSDavid du Colombier
2588*0b459c2cSDavid du Colombier@item
2589*0b459c2cSDavid du Colombierskip patches for which the file has the wrong version for the
2590*0b459c2cSDavid du Colombier@samp{Prereq:} line in the patch;
2591*0b459c2cSDavid du Colombier
2592*0b459c2cSDavid du Colombier@item
2593*0b459c2cSDavid du Colombierassume that patches are reversed if they look like they are.
2594*0b459c2cSDavid du Colombier@end itemize
2595*0b459c2cSDavid du Colombier
2596*0b459c2cSDavid du Colombier@code{patch} exits with a non-zero status if it creates any reject
2597*0b459c2cSDavid du Colombierfiles.  When applying a set of patches in a loop, you should check the
2598*0b459c2cSDavid du Colombierexit status, so you don't apply a later patch to a partially patched
2599*0b459c2cSDavid du Colombierfile.
2600*0b459c2cSDavid du Colombier
2601*0b459c2cSDavid du Colombier@node Making Patches, Invoking cmp, Merging with patch, Top
2602*0b459c2cSDavid du Colombier@chapter Tips for Making Patch Distributions
2603*0b459c2cSDavid du Colombier@cindex patch making tips
2604*0b459c2cSDavid du Colombier@cindex tips for patch making
2605*0b459c2cSDavid du Colombier
2606*0b459c2cSDavid du ColombierHere are some things you should keep in mind if you are going to
2607*0b459c2cSDavid du Colombierdistribute patches for updating a software package.
2608*0b459c2cSDavid du Colombier
2609*0b459c2cSDavid du ColombierMake sure you have specified the file names correctly, either in a
2610*0b459c2cSDavid du Colombiercontext diff header or with an @samp{Index:} line.  If you are patching
2611*0b459c2cSDavid du Colombierfiles in a subdirectory, be sure to tell the patch user to specify a
2612*0b459c2cSDavid du Colombier@samp{-p} or @samp{--strip} option as needed.  Take care to not send out
2613*0b459c2cSDavid du Colombierreversed patches, since these make people wonder whether they have
2614*0b459c2cSDavid du Colombieralready applied the patch.
2615*0b459c2cSDavid du Colombier
2616*0b459c2cSDavid du ColombierTo save people from partially applying a patch before other patches that
2617*0b459c2cSDavid du Colombiershould have gone before it, you can make the first patch in the patch
2618*0b459c2cSDavid du Colombierfile update a file with a name like @file{patchlevel.h} or
2619*0b459c2cSDavid du Colombier@file{version.c}, which contains a patch level or version number.  If
2620*0b459c2cSDavid du Colombierthe input file contains the wrong version number, @code{patch} will
2621*0b459c2cSDavid du Colombiercomplain immediately.
2622*0b459c2cSDavid du Colombier
2623*0b459c2cSDavid du ColombierAn even clearer way to prevent this problem is to put a @samp{Prereq:}
2624*0b459c2cSDavid du Colombierline before the patch.  If the leading text in the patch file contains a
2625*0b459c2cSDavid du Colombierline that starts with @samp{Prereq:}, @code{patch} takes the next word
2626*0b459c2cSDavid du Colombierfrom that line (normally a version number) and checks whether the next
2627*0b459c2cSDavid du Colombierinput file contains that word, preceded and followed by either
2628*0b459c2cSDavid du Colombierwhite space or a newline.  If not, @code{patch} prompts you for
2629*0b459c2cSDavid du Colombierconfirmation before proceeding.  This makes it difficult to accidentally
2630*0b459c2cSDavid du Colombierapply patches in the wrong order.
2631*0b459c2cSDavid du Colombier
2632*0b459c2cSDavid du ColombierSince @code{patch} does not handle incomplete lines properly, make sure
2633*0b459c2cSDavid du Colombierthat all the source files in your program end with a newline whenever
2634*0b459c2cSDavid du Colombieryou release a version.
2635*0b459c2cSDavid du Colombier
2636*0b459c2cSDavid du ColombierTo create a patch that changes an older version of a package into a
2637*0b459c2cSDavid du Colombiernewer version, first make a copy of the older version in a scratch
2638*0b459c2cSDavid du Colombierdirectory.  Typically you do that by unpacking a @code{tar} or
2639*0b459c2cSDavid du Colombier@code{shar} archive of the older version.
2640*0b459c2cSDavid du Colombier
2641*0b459c2cSDavid du ColombierYou might be able to reduce the size of the patch by renaming or
2642*0b459c2cSDavid du Colombierremoving some files before making the patch.  If the older version of
2643*0b459c2cSDavid du Colombierthe package contains any files that the newer version does not, or if
2644*0b459c2cSDavid du Colombierany files have been renamed between the two versions, make a list of
2645*0b459c2cSDavid du Colombier@code{rm} and @code{mv} commands for the user to execute in the old
2646*0b459c2cSDavid du Colombierversion directory before applying the patch.  Then run those commands
2647*0b459c2cSDavid du Colombieryourself in the scratch directory.
2648*0b459c2cSDavid du Colombier
2649*0b459c2cSDavid du ColombierIf there are any files that you don't need to include in the patch
2650*0b459c2cSDavid du Colombierbecause they can easily be rebuilt from other files (for example,
2651*0b459c2cSDavid du Colombier@file{TAGS} and output from @code{yacc} and @code{makeinfo}), replace
2652*0b459c2cSDavid du Colombierthe versions in the scratch directory with the newer versions, using
2653*0b459c2cSDavid du Colombier@code{rm} and @code{ln} or @code{cp}.
2654*0b459c2cSDavid du Colombier
2655*0b459c2cSDavid du ColombierNow you can create the patch.  The de-facto standard @code{diff} format
2656*0b459c2cSDavid du Colombierfor patch distributions is context format with two lines of context,
2657*0b459c2cSDavid du Colombierproduced by giving @code{diff} the @samp{-C 2} option.  Do not use less
2658*0b459c2cSDavid du Colombierthan two lines of context, because @code{patch} typically needs at
2659*0b459c2cSDavid du Colombierleast two lines for proper operation.  Give @code{diff} the @samp{-P}
2660*0b459c2cSDavid du Colombieroption in case the newer version of the package contains any files that
2661*0b459c2cSDavid du Colombierthe older one does not.  Make sure to specify the scratch directory
2662*0b459c2cSDavid du Colombierfirst and the newer directory second.
2663*0b459c2cSDavid du Colombier
2664*0b459c2cSDavid du ColombierAdd to the top of the patch a note telling the user any @code{rm} and
2665*0b459c2cSDavid du Colombier@code{mv} commands to run before applying the patch.  Then you can
2666*0b459c2cSDavid du Colombierremove the scratch directory.
2667*0b459c2cSDavid du Colombier
2668*0b459c2cSDavid du Colombier@node Invoking cmp, Invoking diff, Making Patches, Top
2669*0b459c2cSDavid du Colombier@chapter Invoking @code{cmp}
2670*0b459c2cSDavid du Colombier@cindex invoking @code{cmp}
2671*0b459c2cSDavid du Colombier@cindex @code{cmp} invocation
2672*0b459c2cSDavid du Colombier
2673*0b459c2cSDavid du ColombierThe @code{cmp} command compares two files, and if they differ, tells the
2674*0b459c2cSDavid du Colombierfirst byte and line number where they differ.  Its arguments are as
2675*0b459c2cSDavid du Colombierfollows:
2676*0b459c2cSDavid du Colombier
2677*0b459c2cSDavid du Colombier@example
2678*0b459c2cSDavid du Colombiercmp @var{options}@dots{} @var{from-file} @r{[}@var{to-file}@var{]}
2679*0b459c2cSDavid du Colombier@end example
2680*0b459c2cSDavid du Colombier
2681*0b459c2cSDavid du ColombierThe file name @samp{-} is always the standard input.  @code{cmp} also
2682*0b459c2cSDavid du Colombieruses the standard input if one file name is omitted.
2683*0b459c2cSDavid du Colombier
2684*0b459c2cSDavid du ColombierAn exit status of 0 means no differences were found, 1 means some
2685*0b459c2cSDavid du Colombierdifferences were found, and 2 means trouble.
2686*0b459c2cSDavid du Colombier
2687*0b459c2cSDavid du Colombier@menu
2688*0b459c2cSDavid du Colombier* cmp Options::		Summary of options to @code{cmp}.
2689*0b459c2cSDavid du Colombier@end menu
2690*0b459c2cSDavid du Colombier
2691*0b459c2cSDavid du Colombier@node cmp Options, , , Invoking cmp
2692*0b459c2cSDavid du Colombier@section Options to @code{cmp}
2693*0b459c2cSDavid du Colombier@cindex @code{cmp} options
2694*0b459c2cSDavid du Colombier@cindex options for @code{cmp}
2695*0b459c2cSDavid du Colombier
2696*0b459c2cSDavid du ColombierBelow is a summary of all of the options that GNU @code{cmp} accepts.
2697*0b459c2cSDavid du ColombierMost options have two equivalent names, one of which is a single letter
2698*0b459c2cSDavid du Colombierpreceded by @samp{-}, and the other of which is a long name preceded by
2699*0b459c2cSDavid du Colombier@samp{--}.  Multiple single letter options (unless they take an
2700*0b459c2cSDavid du Colombierargument) can be combined into a single command line word: @samp{-cl} is
2701*0b459c2cSDavid du Colombierequivalent to @samp{-c -l}.
2702*0b459c2cSDavid du Colombier
2703*0b459c2cSDavid du Colombier@table @samp
2704*0b459c2cSDavid du Colombier@item -c
2705*0b459c2cSDavid du ColombierPrint the differing characters.  Display control characters as a
2706*0b459c2cSDavid du Colombier@samp{^} followed by a letter of the alphabet and precede characters
2707*0b459c2cSDavid du Colombierthat have the high bit set with @samp{M-} (which stands for ``meta'').
2708*0b459c2cSDavid du Colombier
2709*0b459c2cSDavid du Colombier@item --ignore-initial=@var{bytes}
2710*0b459c2cSDavid du ColombierIgnore any differences in the the first @var{bytes} bytes of the input files.
2711*0b459c2cSDavid du ColombierTreat files with fewer than @var{bytes} bytes as if they are empty.
2712*0b459c2cSDavid du Colombier
2713*0b459c2cSDavid du Colombier@item -l
2714*0b459c2cSDavid du ColombierPrint the (decimal) offsets and (octal) values of all differing bytes.
2715*0b459c2cSDavid du Colombier
2716*0b459c2cSDavid du Colombier@item --print-chars
2717*0b459c2cSDavid du ColombierPrint the differing characters.  Display control characters as a
2718*0b459c2cSDavid du Colombier@samp{^} followed by a letter of the alphabet and precede characters
2719*0b459c2cSDavid du Colombierthat have the high bit set with @samp{M-} (which stands for ``meta'').
2720*0b459c2cSDavid du Colombier
2721*0b459c2cSDavid du Colombier@item --quiet
2722*0b459c2cSDavid du Colombier@itemx -s
2723*0b459c2cSDavid du Colombier@itemx --silent
2724*0b459c2cSDavid du ColombierDo not print anything; only return an exit status indicating whether
2725*0b459c2cSDavid du Colombierthe files differ.
2726*0b459c2cSDavid du Colombier
2727*0b459c2cSDavid du Colombier@item --verbose
2728*0b459c2cSDavid du ColombierPrint the (decimal) offsets and (octal) values of all differing bytes.
2729*0b459c2cSDavid du Colombier
2730*0b459c2cSDavid du Colombier@item -v
2731*0b459c2cSDavid du Colombier@item --version
2732*0b459c2cSDavid du ColombierOutput the version number of @code{cmp}.
2733*0b459c2cSDavid du Colombier@end table
2734*0b459c2cSDavid du Colombier
2735*0b459c2cSDavid du Colombier@node Invoking diff, Invoking diff3, Invoking cmp, Top
2736*0b459c2cSDavid du Colombier@chapter Invoking @code{diff}
2737*0b459c2cSDavid du Colombier@cindex invoking @code{diff}
2738*0b459c2cSDavid du Colombier@cindex @code{diff} invocation
2739*0b459c2cSDavid du Colombier
2740*0b459c2cSDavid du ColombierThe format for running the @code{diff} command is:
2741*0b459c2cSDavid du Colombier
2742*0b459c2cSDavid du Colombier@example
2743*0b459c2cSDavid du Colombierdiff @var{options}@dots{} @var{from-file} @var{to-file}
2744*0b459c2cSDavid du Colombier@end example
2745*0b459c2cSDavid du Colombier
2746*0b459c2cSDavid du ColombierIn the simplest case, @code{diff} compares the contents of the two files
2747*0b459c2cSDavid du Colombier@var{from-file} and @var{to-file}.  A file name of @samp{-} stands for
2748*0b459c2cSDavid du Colombiertext read from the standard input.  As a special case, @samp{diff - -}
2749*0b459c2cSDavid du Colombiercompares a copy of standard input to itself.
2750*0b459c2cSDavid du Colombier
2751*0b459c2cSDavid du ColombierIf @var{from-file} is a directory and @var{to-file} is not, @code{diff}
2752*0b459c2cSDavid du Colombiercompares the file in @var{from-file} whose file name is that of @var{to-file},
2753*0b459c2cSDavid du Colombierand vice versa.  The non-directory file must not be @samp{-}.
2754*0b459c2cSDavid du Colombier
2755*0b459c2cSDavid du ColombierIf both @var{from-file} and @var{to-file} are directories,
2756*0b459c2cSDavid du Colombier@code{diff} compares corresponding files in both directories, in
2757*0b459c2cSDavid du Colombieralphabetical order; this comparison is not recursive unless the
2758*0b459c2cSDavid du Colombier@samp{-r} or @samp{--recursive} option is given.  @code{diff} never
2759*0b459c2cSDavid du Colombiercompares the actual contents of a directory as if it were a file.  The
2760*0b459c2cSDavid du Colombierfile that is fully specified may not be standard input, because standard
2761*0b459c2cSDavid du Colombierinput is nameless and the notion of ``file with the same name'' does not
2762*0b459c2cSDavid du Colombierapply.
2763*0b459c2cSDavid du Colombier
2764*0b459c2cSDavid du Colombier@code{diff} options begin with @samp{-}, so normally @var{from-file} and
2765*0b459c2cSDavid du Colombier@var{to-file} may not begin with @samp{-}.  However, @samp{--} as an
2766*0b459c2cSDavid du Colombierargument by itself treats the remaining arguments as file names even if
2767*0b459c2cSDavid du Colombierthey begin with @samp{-}.
2768*0b459c2cSDavid du Colombier
2769*0b459c2cSDavid du ColombierAn exit status of 0 means no differences were found, 1 means some
2770*0b459c2cSDavid du Colombierdifferences were found, and 2 means trouble.
2771*0b459c2cSDavid du Colombier
2772*0b459c2cSDavid du Colombier@menu
2773*0b459c2cSDavid du Colombier* diff Options::	Summary of options to @code{diff}.
2774*0b459c2cSDavid du Colombier@end menu
2775*0b459c2cSDavid du Colombier
2776*0b459c2cSDavid du Colombier@node diff Options, , , Invoking diff
2777*0b459c2cSDavid du Colombier@section Options to @code{diff}
2778*0b459c2cSDavid du Colombier@cindex @code{diff} options
2779*0b459c2cSDavid du Colombier@cindex options for @code{diff}
2780*0b459c2cSDavid du Colombier
2781*0b459c2cSDavid du ColombierBelow is a summary of all of the options that GNU @code{diff} accepts.
2782*0b459c2cSDavid du ColombierMost options have two equivalent names, one of which is a single letter
2783*0b459c2cSDavid du Colombierpreceded by @samp{-}, and the other of which is a long name preceded by
2784*0b459c2cSDavid du Colombier@samp{--}.  Multiple single letter options (unless they take an
2785*0b459c2cSDavid du Colombierargument) can be combined into a single command line word: @samp{-ac} is
2786*0b459c2cSDavid du Colombierequivalent to @samp{-a -c}.  Long named options can be abbreviated to
2787*0b459c2cSDavid du Colombierany unique prefix of their name.  Brackets ([ and ]) indicate that an
2788*0b459c2cSDavid du Colombieroption takes an optional argument.
2789*0b459c2cSDavid du Colombier
2790*0b459c2cSDavid du Colombier@table @samp
2791*0b459c2cSDavid du Colombier@item -@var{lines}
2792*0b459c2cSDavid du ColombierShow @var{lines} (an integer) lines of context.  This option does not
2793*0b459c2cSDavid du Colombierspecify an output format by itself; it has no effect unless it is
2794*0b459c2cSDavid du Colombiercombined with @samp{-c} (@pxref{Context Format}) or @samp{-u}
2795*0b459c2cSDavid du Colombier(@pxref{Unified Format}).  This option is obsolete.  For proper
2796*0b459c2cSDavid du Colombieroperation, @code{patch} typically needs at least two lines of context.
2797*0b459c2cSDavid du Colombier
2798*0b459c2cSDavid du Colombier@item -a
2799*0b459c2cSDavid du ColombierTreat all files as text and compare them line-by-line, even if they
2800*0b459c2cSDavid du Colombierdo not seem to be text.  @xref{Binary}.
2801*0b459c2cSDavid du Colombier
2802*0b459c2cSDavid du Colombier@item -b
2803*0b459c2cSDavid du ColombierIgnore changes in amount of white space.  @xref{White Space}.
2804*0b459c2cSDavid du Colombier
2805*0b459c2cSDavid du Colombier@item -B
2806*0b459c2cSDavid du ColombierIgnore changes that just insert or delete blank lines.  @xref{Blank
2807*0b459c2cSDavid du ColombierLines}.
2808*0b459c2cSDavid du Colombier
2809*0b459c2cSDavid du Colombier@item --binary
2810*0b459c2cSDavid du ColombierRead and write data in binary mode.  @xref{Binary}.
2811*0b459c2cSDavid du Colombier
2812*0b459c2cSDavid du Colombier@item --brief
2813*0b459c2cSDavid du ColombierReport only whether the files differ, not the details of the
2814*0b459c2cSDavid du Colombierdifferences.  @xref{Brief}.
2815*0b459c2cSDavid du Colombier
2816*0b459c2cSDavid du Colombier@item -c
2817*0b459c2cSDavid du ColombierUse the context output format.  @xref{Context Format}.
2818*0b459c2cSDavid du Colombier
2819*0b459c2cSDavid du Colombier@item -C @var{lines}
2820*0b459c2cSDavid du Colombier@itemx --context@r{[}=@var{lines}@r{]}
2821*0b459c2cSDavid du ColombierUse the context output format, showing @var{lines} (an integer) lines of
2822*0b459c2cSDavid du Colombiercontext, or three if @var{lines} is not given.  @xref{Context Format}.
2823*0b459c2cSDavid du ColombierFor proper operation, @code{patch} typically needs at least two lines of
2824*0b459c2cSDavid du Colombiercontext.
2825*0b459c2cSDavid du Colombier
2826*0b459c2cSDavid du Colombier@item --changed-group-format=@var{format}
2827*0b459c2cSDavid du ColombierUse @var{format} to output a line group containing differing lines from
2828*0b459c2cSDavid du Colombierboth files in if-then-else format.  @xref{Line Group Formats}.
2829*0b459c2cSDavid du Colombier
2830*0b459c2cSDavid du Colombier@item -d
2831*0b459c2cSDavid du ColombierChange the algorithm perhaps find a smaller set of changes.  This makes
2832*0b459c2cSDavid du Colombier@code{diff} slower (sometimes much slower).  @xref{diff Performance}.
2833*0b459c2cSDavid du Colombier
2834*0b459c2cSDavid du Colombier@item -D @var{name}
2835*0b459c2cSDavid du ColombierMake merged @samp{#ifdef} format output, conditional on the preprocessor
2836*0b459c2cSDavid du Colombiermacro @var{name}.  @xref{If-then-else}.
2837*0b459c2cSDavid du Colombier
2838*0b459c2cSDavid du Colombier@item -e
2839*0b459c2cSDavid du Colombier@itemx --ed
2840*0b459c2cSDavid du ColombierMake output that is a valid @code{ed} script.  @xref{ed Scripts}.
2841*0b459c2cSDavid du Colombier
2842*0b459c2cSDavid du Colombier@item --exclude=@var{pattern}
2843*0b459c2cSDavid du ColombierWhen comparing directories, ignore files and subdirectories whose basenames
2844*0b459c2cSDavid du Colombiermatch @var{pattern}.  @xref{Comparing Directories}.
2845*0b459c2cSDavid du Colombier
2846*0b459c2cSDavid du Colombier@item --exclude-from=@var{file}
2847*0b459c2cSDavid du ColombierWhen comparing directories, ignore files and subdirectories whose basenames
2848*0b459c2cSDavid du Colombiermatch any pattern contained in @var{file}.  @xref{Comparing Directories}.
2849*0b459c2cSDavid du Colombier
2850*0b459c2cSDavid du Colombier@item --expand-tabs
2851*0b459c2cSDavid du ColombierExpand tabs to spaces in the output, to preserve the alignment of tabs
2852*0b459c2cSDavid du Colombierin the input files.  @xref{Tabs}.
2853*0b459c2cSDavid du Colombier
2854*0b459c2cSDavid du Colombier@item -f
2855*0b459c2cSDavid du ColombierMake output that looks vaguely like an @code{ed} script but has changes
2856*0b459c2cSDavid du Colombierin the order they appear in the file.  @xref{Forward ed}.
2857*0b459c2cSDavid du Colombier
2858*0b459c2cSDavid du Colombier@item -F @var{regexp}
2859*0b459c2cSDavid du ColombierIn context and unified format, for each hunk of differences, show some
2860*0b459c2cSDavid du Colombierof the last preceding line that matches @var{regexp}.  @xref{Specified
2861*0b459c2cSDavid du ColombierHeadings}.
2862*0b459c2cSDavid du Colombier
2863*0b459c2cSDavid du Colombier@item --forward-ed
2864*0b459c2cSDavid du ColombierMake output that looks vaguely like an @code{ed} script but has changes
2865*0b459c2cSDavid du Colombierin the order they appear in the file.  @xref{Forward ed}.
2866*0b459c2cSDavid du Colombier
2867*0b459c2cSDavid du Colombier@item -h
2868*0b459c2cSDavid du ColombierThis option currently has no effect; it is present for Unix
2869*0b459c2cSDavid du Colombiercompatibility.
2870*0b459c2cSDavid du Colombier
2871*0b459c2cSDavid du Colombier@item -H
2872*0b459c2cSDavid du ColombierUse heuristics to speed handling of large files that have numerous
2873*0b459c2cSDavid du Colombierscattered small changes.  @xref{diff Performance}.
2874*0b459c2cSDavid du Colombier
2875*0b459c2cSDavid du Colombier@item --horizon-lines=@var{lines}
2876*0b459c2cSDavid du ColombierDo not discard the last @var{lines} lines of the common prefix
2877*0b459c2cSDavid du Colombierand the first @var{lines} lines of the common suffix.
2878*0b459c2cSDavid du Colombier@xref{diff Performance}.
2879*0b459c2cSDavid du Colombier
2880*0b459c2cSDavid du Colombier@item -i
2881*0b459c2cSDavid du ColombierIgnore changes in case; consider upper- and lower-case letters
2882*0b459c2cSDavid du Colombierequivalent.  @xref{Case Folding}.
2883*0b459c2cSDavid du Colombier
2884*0b459c2cSDavid du Colombier@item -I @var{regexp}
2885*0b459c2cSDavid du ColombierIgnore changes that just insert or delete lines that match @var{regexp}.
2886*0b459c2cSDavid du Colombier@xref{Specified Folding}.
2887*0b459c2cSDavid du Colombier
2888*0b459c2cSDavid du Colombier@item --ifdef=@var{name}
2889*0b459c2cSDavid du ColombierMake merged if-then-else output using @var{name}.  @xref{If-then-else}.
2890*0b459c2cSDavid du Colombier
2891*0b459c2cSDavid du Colombier@item --ignore-all-space
2892*0b459c2cSDavid du ColombierIgnore white space when comparing lines.  @xref{White Space}.
2893*0b459c2cSDavid du Colombier
2894*0b459c2cSDavid du Colombier@item --ignore-blank-lines
2895*0b459c2cSDavid du ColombierIgnore changes that just insert or delete blank lines.  @xref{Blank
2896*0b459c2cSDavid du ColombierLines}.
2897*0b459c2cSDavid du Colombier
2898*0b459c2cSDavid du Colombier@item --ignore-case
2899*0b459c2cSDavid du ColombierIgnore changes in case; consider upper- and lower-case to be the same.
2900*0b459c2cSDavid du Colombier@xref{Case Folding}.
2901*0b459c2cSDavid du Colombier
2902*0b459c2cSDavid du Colombier@item --ignore-matching-lines=@var{regexp}
2903*0b459c2cSDavid du ColombierIgnore changes that just insert or delete lines that match @var{regexp}.
2904*0b459c2cSDavid du Colombier@xref{Specified Folding}.
2905*0b459c2cSDavid du Colombier
2906*0b459c2cSDavid du Colombier@item --ignore-space-change
2907*0b459c2cSDavid du ColombierIgnore changes in amount of white space.
2908*0b459c2cSDavid du Colombier@xref{White Space}.
2909*0b459c2cSDavid du Colombier
2910*0b459c2cSDavid du Colombier@item --initial-tab
2911*0b459c2cSDavid du ColombierOutput a tab rather than a space before the text of a line in normal or
2912*0b459c2cSDavid du Colombiercontext format.  This causes the alignment of tabs in the line to look
2913*0b459c2cSDavid du Colombiernormal.  @xref{Tabs}.
2914*0b459c2cSDavid du Colombier
2915*0b459c2cSDavid du Colombier@item -l
2916*0b459c2cSDavid du ColombierPass the output through @code{pr} to paginate it.  @xref{Pagination}.
2917*0b459c2cSDavid du Colombier
2918*0b459c2cSDavid du Colombier@item -L @var{label}
2919*0b459c2cSDavid du ColombierUse @var{label} instead of the file name in the context format
2920*0b459c2cSDavid du Colombier(@pxref{Context Format}) and unified format (@pxref{Unified Format})
2921*0b459c2cSDavid du Colombierheaders.  @xref{RCS}.
2922*0b459c2cSDavid du Colombier
2923*0b459c2cSDavid du Colombier@item --label=@var{label}
2924*0b459c2cSDavid du ColombierUse @var{label} instead of the file name in the context format
2925*0b459c2cSDavid du Colombier(@pxref{Context Format}) and unified format (@pxref{Unified Format})
2926*0b459c2cSDavid du Colombierheaders.
2927*0b459c2cSDavid du Colombier
2928*0b459c2cSDavid du Colombier@item --left-column
2929*0b459c2cSDavid du ColombierPrint only the left column of two common lines in side by side format.
2930*0b459c2cSDavid du Colombier@xref{Side by Side Format}.
2931*0b459c2cSDavid du Colombier
2932*0b459c2cSDavid du Colombier@item --line-format=@var{format}
2933*0b459c2cSDavid du ColombierUse @var{format} to output all input lines in if-then-else format.
2934*0b459c2cSDavid du Colombier@xref{Line Formats}.
2935*0b459c2cSDavid du Colombier
2936*0b459c2cSDavid du Colombier@item --minimal
2937*0b459c2cSDavid du ColombierChange the algorithm to perhaps find a smaller set of changes.  This
2938*0b459c2cSDavid du Colombiermakes @code{diff} slower (sometimes much slower).  @xref{diff
2939*0b459c2cSDavid du ColombierPerformance}.
2940*0b459c2cSDavid du Colombier
2941*0b459c2cSDavid du Colombier@item -n
2942*0b459c2cSDavid du ColombierOutput RCS-format diffs; like @samp{-f} except that each command
2943*0b459c2cSDavid du Colombierspecifies the number of lines affected.  @xref{RCS}.
2944*0b459c2cSDavid du Colombier
2945*0b459c2cSDavid du Colombier@item -N
2946*0b459c2cSDavid du Colombier@itemx --new-file
2947*0b459c2cSDavid du ColombierIn directory comparison, if a file is found in only one directory,
2948*0b459c2cSDavid du Colombiertreat it as present but empty in the other directory.  @xref{Comparing
2949*0b459c2cSDavid du ColombierDirectories}.
2950*0b459c2cSDavid du Colombier
2951*0b459c2cSDavid du Colombier@item --new-group-format=@var{format}
2952*0b459c2cSDavid du ColombierUse @var{format} to output a group of lines taken from just the second
2953*0b459c2cSDavid du Colombierfile in if-then-else format.  @xref{Line Group Formats}.
2954*0b459c2cSDavid du Colombier
2955*0b459c2cSDavid du Colombier@item --new-line-format=@var{format}
2956*0b459c2cSDavid du ColombierUse @var{format} to output a line taken from just the second file in
2957*0b459c2cSDavid du Colombierif-then-else format.  @xref{Line Formats}.
2958*0b459c2cSDavid du Colombier
2959*0b459c2cSDavid du Colombier@item --old-group-format=@var{format}
2960*0b459c2cSDavid du ColombierUse @var{format} to output a group of lines taken from just the first
2961*0b459c2cSDavid du Colombierfile in if-then-else format.  @xref{Line Group Formats}.
2962*0b459c2cSDavid du Colombier
2963*0b459c2cSDavid du Colombier@item --old-line-format=@var{format}
2964*0b459c2cSDavid du ColombierUse @var{format} to output a line taken from just the first file in
2965*0b459c2cSDavid du Colombierif-then-else format.  @xref{Line Formats}.
2966*0b459c2cSDavid du Colombier
2967*0b459c2cSDavid du Colombier@item -p
2968*0b459c2cSDavid du ColombierShow which C function each change is in.  @xref{C Function Headings}.
2969*0b459c2cSDavid du Colombier
2970*0b459c2cSDavid du Colombier@item -P
2971*0b459c2cSDavid du ColombierWhen comparing directories, if a file appears only in the second
2972*0b459c2cSDavid du Colombierdirectory of the two, treat it as present but empty in the other.
2973*0b459c2cSDavid du Colombier@xref{Comparing Directories}.
2974*0b459c2cSDavid du Colombier
2975*0b459c2cSDavid du Colombier@item --paginate
2976*0b459c2cSDavid du ColombierPass the output through @code{pr} to paginate it.  @xref{Pagination}.
2977*0b459c2cSDavid du Colombier
2978*0b459c2cSDavid du Colombier@item -q
2979*0b459c2cSDavid du ColombierReport only whether the files differ, not the details of the
2980*0b459c2cSDavid du Colombierdifferences.  @xref{Brief}.
2981*0b459c2cSDavid du Colombier
2982*0b459c2cSDavid du Colombier@item -r
2983*0b459c2cSDavid du ColombierWhen comparing directories, recursively compare any subdirectories
2984*0b459c2cSDavid du Colombierfound.  @xref{Comparing Directories}.
2985*0b459c2cSDavid du Colombier
2986*0b459c2cSDavid du Colombier@item --rcs
2987*0b459c2cSDavid du ColombierOutput RCS-format diffs; like @samp{-f} except that each command
2988*0b459c2cSDavid du Colombierspecifies the number of lines affected.  @xref{RCS}.
2989*0b459c2cSDavid du Colombier
2990*0b459c2cSDavid du Colombier@item --recursive
2991*0b459c2cSDavid du ColombierWhen comparing directories, recursively compare any subdirectories
2992*0b459c2cSDavid du Colombierfound.  @xref{Comparing Directories}.
2993*0b459c2cSDavid du Colombier
2994*0b459c2cSDavid du Colombier@item --report-identical-files
2995*0b459c2cSDavid du ColombierReport when two files are the same.  @xref{Comparing Directories}.
2996*0b459c2cSDavid du Colombier
2997*0b459c2cSDavid du Colombier@item -s
2998*0b459c2cSDavid du ColombierReport when two files are the same.  @xref{Comparing Directories}.
2999*0b459c2cSDavid du Colombier
3000*0b459c2cSDavid du Colombier@item -S @var{file}
3001*0b459c2cSDavid du ColombierWhen comparing directories, start with the file @var{file}.  This is
3002*0b459c2cSDavid du Colombierused for resuming an aborted comparison.  @xref{Comparing Directories}.
3003*0b459c2cSDavid du Colombier
3004*0b459c2cSDavid du Colombier@item --sdiff-merge-assist
3005*0b459c2cSDavid du ColombierPrint extra information to help @code{sdiff}.  @code{sdiff} uses this
3006*0b459c2cSDavid du Colombieroption when it runs @code{diff}.  This option is not intended for users
3007*0b459c2cSDavid du Colombierto use directly.
3008*0b459c2cSDavid du Colombier
3009*0b459c2cSDavid du Colombier@item --show-c-function
3010*0b459c2cSDavid du ColombierShow which C function each change is in.  @xref{C Function Headings}.
3011*0b459c2cSDavid du Colombier
3012*0b459c2cSDavid du Colombier@item --show-function-line=@var{regexp}
3013*0b459c2cSDavid du ColombierIn context and unified format, for each hunk of differences, show some
3014*0b459c2cSDavid du Colombierof the last preceding line that matches @var{regexp}.  @xref{Specified
3015*0b459c2cSDavid du ColombierHeadings}.
3016*0b459c2cSDavid du Colombier
3017*0b459c2cSDavid du Colombier@item --side-by-side
3018*0b459c2cSDavid du ColombierUse the side by side output format.  @xref{Side by Side Format}.
3019*0b459c2cSDavid du Colombier
3020*0b459c2cSDavid du Colombier@item --speed-large-files
3021*0b459c2cSDavid du ColombierUse heuristics to speed handling of large files that have numerous
3022*0b459c2cSDavid du Colombierscattered small changes.  @xref{diff Performance}.
3023*0b459c2cSDavid du Colombier
3024*0b459c2cSDavid du Colombier@item --starting-file=@var{file}
3025*0b459c2cSDavid du ColombierWhen comparing directories, start with the file @var{file}.  This is
3026*0b459c2cSDavid du Colombierused for resuming an aborted comparison.  @xref{Comparing Directories}.
3027*0b459c2cSDavid du Colombier
3028*0b459c2cSDavid du Colombier@item --suppress-common-lines
3029*0b459c2cSDavid du ColombierDo not print common lines in side by side format.
3030*0b459c2cSDavid du Colombier@xref{Side by Side Format}.
3031*0b459c2cSDavid du Colombier
3032*0b459c2cSDavid du Colombier@item -t
3033*0b459c2cSDavid du ColombierExpand tabs to spaces in the output, to preserve the alignment of tabs
3034*0b459c2cSDavid du Colombierin the input files.  @xref{Tabs}.
3035*0b459c2cSDavid du Colombier
3036*0b459c2cSDavid du Colombier@item -T
3037*0b459c2cSDavid du ColombierOutput a tab rather than a space before the text of a line in normal or
3038*0b459c2cSDavid du Colombiercontext format.  This causes the alignment of tabs in the line to look
3039*0b459c2cSDavid du Colombiernormal.  @xref{Tabs}.
3040*0b459c2cSDavid du Colombier
3041*0b459c2cSDavid du Colombier@item --text
3042*0b459c2cSDavid du ColombierTreat all files as text and compare them line-by-line, even if they
3043*0b459c2cSDavid du Colombierdo not appear to be text.  @xref{Binary}.
3044*0b459c2cSDavid du Colombier
3045*0b459c2cSDavid du Colombier@item -u
3046*0b459c2cSDavid du ColombierUse the unified output format.  @xref{Unified Format}.
3047*0b459c2cSDavid du Colombier
3048*0b459c2cSDavid du Colombier@item --unchanged-group-format=@var{format}
3049*0b459c2cSDavid du ColombierUse @var{format} to output a group of common lines taken from both files
3050*0b459c2cSDavid du Colombierin if-then-else format.  @xref{Line Group Formats}.
3051*0b459c2cSDavid du Colombier
3052*0b459c2cSDavid du Colombier@item --unchanged-line-format=@var{format}
3053*0b459c2cSDavid du ColombierUse @var{format} to output a line common to both files in if-then-else
3054*0b459c2cSDavid du Colombierformat.  @xref{Line Formats}.
3055*0b459c2cSDavid du Colombier
3056*0b459c2cSDavid du Colombier@item --unidirectional-new-file
3057*0b459c2cSDavid du ColombierWhen comparing directories, if a file appears only in the second
3058*0b459c2cSDavid du Colombierdirectory of the two, treat it as present but empty in the other.
3059*0b459c2cSDavid du Colombier@xref{Comparing Directories}.
3060*0b459c2cSDavid du Colombier
3061*0b459c2cSDavid du Colombier@item -U @var{lines}
3062*0b459c2cSDavid du Colombier@itemx --unified@r{[}=@var{lines}@r{]}
3063*0b459c2cSDavid du ColombierUse the unified output format, showing @var{lines} (an integer) lines of
3064*0b459c2cSDavid du Colombiercontext, or three if @var{lines} is not given.  @xref{Unified Format}.
3065*0b459c2cSDavid du ColombierFor proper operation, @code{patch} typically needs at least two lines of
3066*0b459c2cSDavid du Colombiercontext.
3067*0b459c2cSDavid du Colombier
3068*0b459c2cSDavid du Colombier@item -v
3069*0b459c2cSDavid du Colombier@itemx --version
3070*0b459c2cSDavid du ColombierOutput the version number of @code{diff}.
3071*0b459c2cSDavid du Colombier
3072*0b459c2cSDavid du Colombier@item -w
3073*0b459c2cSDavid du ColombierIgnore white space when comparing lines.  @xref{White Space}.
3074*0b459c2cSDavid du Colombier
3075*0b459c2cSDavid du Colombier@item -W @var{columns}
3076*0b459c2cSDavid du Colombier@itemx --width=@var{columns}
3077*0b459c2cSDavid du ColombierUse an output width of @var{columns} in side by side format.
3078*0b459c2cSDavid du Colombier@xref{Side by Side Format}.
3079*0b459c2cSDavid du Colombier
3080*0b459c2cSDavid du Colombier@item -x @var{pattern}
3081*0b459c2cSDavid du ColombierWhen comparing directories, ignore files and subdirectories whose basenames
3082*0b459c2cSDavid du Colombiermatch @var{pattern}.  @xref{Comparing Directories}.
3083*0b459c2cSDavid du Colombier
3084*0b459c2cSDavid du Colombier@item -X @var{file}
3085*0b459c2cSDavid du ColombierWhen comparing directories, ignore files and subdirectories whose basenames
3086*0b459c2cSDavid du Colombiermatch any pattern contained in @var{file}.  @xref{Comparing Directories}.
3087*0b459c2cSDavid du Colombier
3088*0b459c2cSDavid du Colombier@item -y
3089*0b459c2cSDavid du ColombierUse the side by side output format.  @xref{Side by Side Format}.
3090*0b459c2cSDavid du Colombier@end table
3091*0b459c2cSDavid du Colombier
3092*0b459c2cSDavid du Colombier@node Invoking diff3, Invoking patch, Invoking diff, Top
3093*0b459c2cSDavid du Colombier@chapter Invoking @code{diff3}
3094*0b459c2cSDavid du Colombier@cindex invoking @code{diff3}
3095*0b459c2cSDavid du Colombier@cindex @code{diff3} invocation
3096*0b459c2cSDavid du Colombier
3097*0b459c2cSDavid du ColombierThe @code{diff3} command compares three files and outputs descriptions
3098*0b459c2cSDavid du Colombierof their differences.  Its arguments are as follows:
3099*0b459c2cSDavid du Colombier
3100*0b459c2cSDavid du Colombier@example
3101*0b459c2cSDavid du Colombierdiff3 @var{options}@dots{} @var{mine} @var{older} @var{yours}
3102*0b459c2cSDavid du Colombier@end example
3103*0b459c2cSDavid du Colombier
3104*0b459c2cSDavid du ColombierThe files to compare are @var{mine}, @var{older}, and @var{yours}.
3105*0b459c2cSDavid du ColombierAt most one of these three file names may be @samp{-},
3106*0b459c2cSDavid du Colombierwhich tells @code{diff3} to read the standard input for that file.
3107*0b459c2cSDavid du Colombier
3108*0b459c2cSDavid du ColombierAn exit status of 0 means @code{diff3} was successful, 1 means some
3109*0b459c2cSDavid du Colombierconflicts were found, and 2 means trouble.
3110*0b459c2cSDavid du Colombier
3111*0b459c2cSDavid du Colombier@menu
3112*0b459c2cSDavid du Colombier* diff3 Options::		Summary of options to @code{diff3}.
3113*0b459c2cSDavid du Colombier@end menu
3114*0b459c2cSDavid du Colombier
3115*0b459c2cSDavid du Colombier@node diff3 Options, , , Invoking diff3
3116*0b459c2cSDavid du Colombier@section Options to @code{diff3}
3117*0b459c2cSDavid du Colombier@cindex @code{diff3} options
3118*0b459c2cSDavid du Colombier@cindex options for @code{diff3}
3119*0b459c2cSDavid du Colombier
3120*0b459c2cSDavid du ColombierBelow is a summary of all of the options that GNU @code{diff3}
3121*0b459c2cSDavid du Colombieraccepts.  Multiple single letter options (unless they take an argument)
3122*0b459c2cSDavid du Colombiercan be combined into a single command line argument.
3123*0b459c2cSDavid du Colombier
3124*0b459c2cSDavid du Colombier@table @samp
3125*0b459c2cSDavid du Colombier@item -a
3126*0b459c2cSDavid du ColombierTreat all files as text and compare them line-by-line, even if they
3127*0b459c2cSDavid du Colombierdo not appear to be text.  @xref{Binary}.
3128*0b459c2cSDavid du Colombier
3129*0b459c2cSDavid du Colombier@item -A
3130*0b459c2cSDavid du ColombierIncorporate all changes from @var{older} to @var{yours} into @var{mine},
3131*0b459c2cSDavid du Colombiersurrounding all conflicts with bracket lines.
3132*0b459c2cSDavid du Colombier@xref{Marking Conflicts}.
3133*0b459c2cSDavid du Colombier
3134*0b459c2cSDavid du Colombier@item -e
3135*0b459c2cSDavid du ColombierGenerate an @code{ed} script that incorporates all the changes from
3136*0b459c2cSDavid du Colombier@var{older} to @var{yours} into @var{mine}.  @xref{Which Changes}.
3137*0b459c2cSDavid du Colombier
3138*0b459c2cSDavid du Colombier@item -E
3139*0b459c2cSDavid du ColombierLike @samp{-e}, except bracket lines from overlapping changes' first
3140*0b459c2cSDavid du Colombierand third files.
3141*0b459c2cSDavid du Colombier@xref{Marking Conflicts}.
3142*0b459c2cSDavid du ColombierWith @samp{-e}, an overlapping change looks like this:
3143*0b459c2cSDavid du Colombier
3144*0b459c2cSDavid du Colombier@example
3145*0b459c2cSDavid du Colombier<<<<<<< @var{mine}
3146*0b459c2cSDavid du Colombier@r{lines from @var{mine}}
3147*0b459c2cSDavid du Colombier=======
3148*0b459c2cSDavid du Colombier@r{lines from @var{yours}}
3149*0b459c2cSDavid du Colombier>>>>>>> @var{yours}
3150*0b459c2cSDavid du Colombier@end example
3151*0b459c2cSDavid du Colombier
3152*0b459c2cSDavid du Colombier@item --ed
3153*0b459c2cSDavid du ColombierGenerate an @code{ed} script that incorporates all the changes from
3154*0b459c2cSDavid du Colombier@var{older} to @var{yours} into @var{mine}.  @xref{Which Changes}.
3155*0b459c2cSDavid du Colombier
3156*0b459c2cSDavid du Colombier@item --easy-only
3157*0b459c2cSDavid du ColombierLike @samp{-e}, except output only the nonoverlapping changes.
3158*0b459c2cSDavid du Colombier@xref{Which Changes}.
3159*0b459c2cSDavid du Colombier
3160*0b459c2cSDavid du Colombier@item -i
3161*0b459c2cSDavid du ColombierGenerate @samp{w} and @samp{q} commands at the end of the @code{ed}
3162*0b459c2cSDavid du Colombierscript for System V compatibility.  This option must be combined with
3163*0b459c2cSDavid du Colombierone of the @samp{-AeExX3} options, and may not be combined with @samp{-m}.
3164*0b459c2cSDavid du Colombier@xref{Saving the Changed File}.
3165*0b459c2cSDavid du Colombier
3166*0b459c2cSDavid du Colombier@item --initial-tab
3167*0b459c2cSDavid du ColombierOutput a tab rather than two spaces before the text of a line in normal format.
3168*0b459c2cSDavid du ColombierThis causes the alignment of tabs in the line to look normal.  @xref{Tabs}.
3169*0b459c2cSDavid du Colombier
3170*0b459c2cSDavid du Colombier@item -L @var{label}
3171*0b459c2cSDavid du Colombier@itemx --label=@var{label}
3172*0b459c2cSDavid du ColombierUse the label @var{label} for the brackets output by the @samp{-A},
3173*0b459c2cSDavid du Colombier@samp{-E} and @samp{-X} options.  This option may be given up to three
3174*0b459c2cSDavid du Colombiertimes, one for each input file.  The default labels are the names of
3175*0b459c2cSDavid du Colombierthe input files.  Thus @samp{diff3 -L X -L Y -L Z -m A B C} acts like
3176*0b459c2cSDavid du Colombier@samp{diff3 -m A B C}, except that the output looks like it came from
3177*0b459c2cSDavid du Colombierfiles named @samp{X}, @samp{Y} and @samp{Z} rather than from files
3178*0b459c2cSDavid du Colombiernamed @samp{A}, @samp{B} and @samp{C}.  @xref{Marking Conflicts}.
3179*0b459c2cSDavid du Colombier
3180*0b459c2cSDavid du Colombier@item -m
3181*0b459c2cSDavid du Colombier@itemx --merge
3182*0b459c2cSDavid du ColombierApply the edit script to the first file and send the result to standard
3183*0b459c2cSDavid du Colombieroutput.  Unlike piping the output from @code{diff3} to @code{ed}, this
3184*0b459c2cSDavid du Colombierworks even for binary files and incomplete lines.  @samp{-A} is assumed
3185*0b459c2cSDavid du Colombierif no edit script option is specified.  @xref{Bypassing ed}.
3186*0b459c2cSDavid du Colombier
3187*0b459c2cSDavid du Colombier@item --overlap-only
3188*0b459c2cSDavid du ColombierLike @samp{-e}, except output only the overlapping changes.
3189*0b459c2cSDavid du Colombier@xref{Which Changes}.
3190*0b459c2cSDavid du Colombier
3191*0b459c2cSDavid du Colombier@item --show-all
3192*0b459c2cSDavid du ColombierIncorporate all unmerged changes from @var{older} to @var{yours} into
3193*0b459c2cSDavid du Colombier@var{mine}, surrounding all overlapping changes with bracket lines.
3194*0b459c2cSDavid du Colombier@xref{Marking Conflicts}.
3195*0b459c2cSDavid du Colombier
3196*0b459c2cSDavid du Colombier@item --show-overlap
3197*0b459c2cSDavid du ColombierLike @samp{-e}, except bracket lines from overlapping changes' first
3198*0b459c2cSDavid du Colombierand third files.
3199*0b459c2cSDavid du Colombier@xref{Marking Conflicts}.
3200*0b459c2cSDavid du Colombier
3201*0b459c2cSDavid du Colombier@item -T
3202*0b459c2cSDavid du ColombierOutput a tab rather than two spaces before the text of a line in normal format.
3203*0b459c2cSDavid du ColombierThis causes the alignment of tabs in the line to look normal.  @xref{Tabs}.
3204*0b459c2cSDavid du Colombier
3205*0b459c2cSDavid du Colombier@item --text
3206*0b459c2cSDavid du ColombierTreat all files as text and compare them line-by-line, even if they
3207*0b459c2cSDavid du Colombierdo not appear to be text.  @xref{Binary}.
3208*0b459c2cSDavid du Colombier
3209*0b459c2cSDavid du Colombier@item -v
3210*0b459c2cSDavid du Colombier@itemx --version
3211*0b459c2cSDavid du ColombierOutput the version number of @code{diff3}.
3212*0b459c2cSDavid du Colombier
3213*0b459c2cSDavid du Colombier@item -x
3214*0b459c2cSDavid du ColombierLike @samp{-e}, except output only the overlapping changes.
3215*0b459c2cSDavid du Colombier@xref{Which Changes}.
3216*0b459c2cSDavid du Colombier
3217*0b459c2cSDavid du Colombier@item -X
3218*0b459c2cSDavid du ColombierLike @samp{-E}, except output only the overlapping changes.
3219*0b459c2cSDavid du ColombierIn other words, like @samp{-x}, except bracket changes as in @samp{-E}.
3220*0b459c2cSDavid du Colombier@xref{Marking Conflicts}.
3221*0b459c2cSDavid du Colombier
3222*0b459c2cSDavid du Colombier@item -3
3223*0b459c2cSDavid du ColombierLike @samp{-e}, except output only the nonoverlapping changes.
3224*0b459c2cSDavid du Colombier@xref{Which Changes}.
3225*0b459c2cSDavid du Colombier@end table
3226*0b459c2cSDavid du Colombier
3227*0b459c2cSDavid du Colombier@node Invoking patch, Invoking sdiff, Invoking diff3, Top
3228*0b459c2cSDavid du Colombier@chapter Invoking @code{patch}
3229*0b459c2cSDavid du Colombier@cindex invoking @code{patch}
3230*0b459c2cSDavid du Colombier@cindex @code{patch} invocation
3231*0b459c2cSDavid du Colombier
3232*0b459c2cSDavid du ColombierNormally @code{patch} is invoked like this:
3233*0b459c2cSDavid du Colombier
3234*0b459c2cSDavid du Colombier@example
3235*0b459c2cSDavid du Colombierpatch <@var{patchfile}
3236*0b459c2cSDavid du Colombier@end example
3237*0b459c2cSDavid du Colombier
3238*0b459c2cSDavid du ColombierThe full format for invoking @code{patch} is:
3239*0b459c2cSDavid du Colombier
3240*0b459c2cSDavid du Colombier@example
3241*0b459c2cSDavid du Colombierpatch @var{options}@dots{} @r{[}@var{origfile} @r{[}@var{patchfile}@r{]}@r{]} @r{[}+ @var{options}@dots{} @r{[}@var{origfile}@r{]}@r{]}@dots{}
3242*0b459c2cSDavid du Colombier@end example
3243*0b459c2cSDavid du Colombier
3244*0b459c2cSDavid du ColombierIf you do not specify @var{patchfile}, or if @var{patchfile} is
3245*0b459c2cSDavid du Colombier@samp{-}, @code{patch} reads the patch (that is, the @code{diff} output)
3246*0b459c2cSDavid du Colombierfrom the standard input.
3247*0b459c2cSDavid du Colombier
3248*0b459c2cSDavid du ColombierYou can specify one or more of the original files as @var{orig} arguments;
3249*0b459c2cSDavid du Colombiereach one and options for interpreting it is separated from the others with a
3250*0b459c2cSDavid du Colombier@samp{+}.  @xref{Multiple Patches}, for more information.
3251*0b459c2cSDavid du Colombier
3252*0b459c2cSDavid du ColombierIf you do not specify an input file on the command line, @code{patch}
3253*0b459c2cSDavid du Colombiertries to figure out from the @dfn{leading text} (any text in the patch
3254*0b459c2cSDavid du Colombierthat comes before the @code{diff} output) which file to edit.  In the
3255*0b459c2cSDavid du Colombierheader of a context or unified diff, @code{patch} looks in lines
3256*0b459c2cSDavid du Colombierbeginning with @samp{***}, @samp{---}, or @samp{+++}; among those, it
3257*0b459c2cSDavid du Colombierchooses the shortest name of an existing file.  Otherwise, if there is
3258*0b459c2cSDavid du Colombieran @samp{Index:} line in the leading text, @code{patch} tries to use the
3259*0b459c2cSDavid du Colombierfile name from that line.  If @code{patch} cannot figure out the name of
3260*0b459c2cSDavid du Colombieran existing file from the leading text, it prompts you for the name of
3261*0b459c2cSDavid du Colombierthe file to patch.
3262*0b459c2cSDavid du Colombier
3263*0b459c2cSDavid du ColombierIf the input file does not exist or is read-only, and a suitable RCS or
3264*0b459c2cSDavid du ColombierSCCS file exists, @code{patch} attempts to check out or get the file
3265*0b459c2cSDavid du Colombierbefore proceeding.
3266*0b459c2cSDavid du Colombier
3267*0b459c2cSDavid du ColombierBy default, @code{patch} replaces the original input file with the
3268*0b459c2cSDavid du Colombierpatched version, after renaming the original file into a backup file
3269*0b459c2cSDavid du Colombier(@pxref{Backups}, for a description of how @code{patch} names backup
3270*0b459c2cSDavid du Colombierfiles).  You can also specify where to put the output with the @samp{-o
3271*0b459c2cSDavid du Colombier@var{output-file}} or @samp{--output=@var{output-file}} option.
3272*0b459c2cSDavid du Colombier
3273*0b459c2cSDavid du Colombier@menu
3274*0b459c2cSDavid du Colombier* patch Directories::	Changing directory and stripping directories.
3275*0b459c2cSDavid du Colombier* Backups::		Backup file names.
3276*0b459c2cSDavid du Colombier* Rejects::		Reject file names.
3277*0b459c2cSDavid du Colombier* patch Options::	Summary table of options to @code{patch}.
3278*0b459c2cSDavid du Colombier@end menu
3279*0b459c2cSDavid du Colombier
3280*0b459c2cSDavid du Colombier@node patch Directories, Backups, , Invoking patch
3281*0b459c2cSDavid du Colombier@section Applying Patches in Other Directories
3282*0b459c2cSDavid du Colombier@cindex directories and patch
3283*0b459c2cSDavid du Colombier@cindex patching directories
3284*0b459c2cSDavid du Colombier
3285*0b459c2cSDavid du ColombierThe @samp{-d @var{directory}} or @samp{--directory=@var{directory}}
3286*0b459c2cSDavid du Colombieroption to @code{patch} makes directory @var{directory} the current
3287*0b459c2cSDavid du Colombierdirectory for interpreting both file names in the patch file, and file
3288*0b459c2cSDavid du Colombiernames given as arguments to other options (such as @samp{-B} and
3289*0b459c2cSDavid du Colombier@samp{-o}).  For example, while in a news reading program, you can patch
3290*0b459c2cSDavid du Colombiera file in the @file{/usr/src/emacs} directory directly from the article
3291*0b459c2cSDavid du Colombiercontaining the patch like this:
3292*0b459c2cSDavid du Colombier
3293*0b459c2cSDavid du Colombier@example
3294*0b459c2cSDavid du Colombier| patch -d /usr/src/emacs
3295*0b459c2cSDavid du Colombier@end example
3296*0b459c2cSDavid du Colombier
3297*0b459c2cSDavid du ColombierSometimes the file names given in a patch contain leading directories,
3298*0b459c2cSDavid du Colombierbut you keep your files in a directory different from the one given in
3299*0b459c2cSDavid du Colombierthe patch.  In those cases, you can use the
3300*0b459c2cSDavid du Colombier@samp{-p@r{[}@var{number}@r{]}} or @samp{--strip@r{[}=@var{number}@r{]}}
3301*0b459c2cSDavid du Colombieroption to set the file name strip count to @var{number}.  The strip
3302*0b459c2cSDavid du Colombiercount tells @code{patch} how many slashes, along with the directory
3303*0b459c2cSDavid du Colombiernames between them, to strip from the front of file names.  @samp{-p}
3304*0b459c2cSDavid du Colombierwith no @var{number} given is equivalent to @samp{-p0}.  By default,
3305*0b459c2cSDavid du Colombier@code{patch} strips off all leading directories, leaving just the base file
3306*0b459c2cSDavid du Colombiernames, except that when a file name given in the patch is a relative
3307*0b459c2cSDavid du Colombierfile name and all of its leading directories already exist, @code{patch} does
3308*0b459c2cSDavid du Colombiernot strip off the leading directory.  (A @dfn{relative} file name is one
3309*0b459c2cSDavid du Colombierthat does not start with a slash.)
3310*0b459c2cSDavid du Colombier
3311*0b459c2cSDavid du Colombier@code{patch} looks for each file (after any slashes have been stripped)
3312*0b459c2cSDavid du Colombierin the current directory, or if you used the @samp{-d @var{directory}}
3313*0b459c2cSDavid du Colombieroption, in that directory.
3314*0b459c2cSDavid du Colombier
3315*0b459c2cSDavid du ColombierFor example, suppose the file name in the patch file is
3316*0b459c2cSDavid du Colombier@file{/gnu/src/emacs/etc/NEWS}.  Using @samp{-p} or @samp{-p0} gives the
3317*0b459c2cSDavid du Colombierentire file name unmodified, @samp{-p1} gives
3318*0b459c2cSDavid du Colombier@file{gnu/src/emacs/etc/NEWS} (no leading slash), @samp{-p4} gives
3319*0b459c2cSDavid du Colombier@file{etc/NEWS}, and not specifying @samp{-p} at all gives @file{NEWS}.
3320*0b459c2cSDavid du Colombier
3321*0b459c2cSDavid du Colombier@node Backups, Rejects, patch Directories, Invoking patch
3322*0b459c2cSDavid du Colombier@section Backup File Names
3323*0b459c2cSDavid du Colombier@cindex backup file names
3324*0b459c2cSDavid du Colombier
3325*0b459c2cSDavid du ColombierNormally, @code{patch} renames an original input file into a backup file
3326*0b459c2cSDavid du Colombierby appending to its name the extension @samp{.orig}, or @samp{~} on
3327*0b459c2cSDavid du Colombiersystems that do not support long file names.  The @samp{-b
3328*0b459c2cSDavid du Colombier@var{backup-suffix}} or @samp{--suffix=@var{backup-suffix}} option uses
3329*0b459c2cSDavid du Colombier@var{backup-suffix} as the backup extension instead.
3330*0b459c2cSDavid du Colombier
3331*0b459c2cSDavid du ColombierAlternately, you can specify the extension for backup files with the
3332*0b459c2cSDavid du Colombier@code{SIMPLE_BACKUP_SUFFIX} environment variable, which the options
3333*0b459c2cSDavid du Colombieroverride.
3334*0b459c2cSDavid du Colombier
3335*0b459c2cSDavid du Colombier@code{patch} can also create numbered backup files the way GNU Emacs
3336*0b459c2cSDavid du Colombierdoes.  With this method, instead of having a single backup of each file,
3337*0b459c2cSDavid du Colombier@code{patch} makes a new backup file name each time it patches a file.
3338*0b459c2cSDavid du ColombierFor example, the backups of a file named @file{sink} would be called,
3339*0b459c2cSDavid du Colombiersuccessively, @file{sink.~1~}, @file{sink.~2~}, @file{sink.~3~}, etc.
3340*0b459c2cSDavid du Colombier
3341*0b459c2cSDavid du ColombierThe @samp{-V @var{backup-style}} or
3342*0b459c2cSDavid du Colombier@samp{--version-control=@var{backup-style}} option takes as an argument
3343*0b459c2cSDavid du Colombiera method for creating backup file names.  You can alternately control
3344*0b459c2cSDavid du Colombierthe type of backups that @code{patch} makes with the
3345*0b459c2cSDavid du Colombier@code{VERSION_CONTROL} environment variable, which the @samp{-V} option
3346*0b459c2cSDavid du Colombieroverrides.  The value of the @code{VERSION_CONTROL} environment variable
3347*0b459c2cSDavid du Colombierand the argument to the @samp{-V} option are like the GNU Emacs
3348*0b459c2cSDavid du Colombier@code{version-control} variable (@pxref{Backups,
3349*0b459c2cSDavid du Colombieremacs, The GNU Emacs Manual}, for more information on backup versions in
3350*0b459c2cSDavid du ColombierEmacs).  They also recognize synonyms that are more descriptive.  The
3351*0b459c2cSDavid du Colombiervalid values are listed below; unique abbreviations are acceptable.
3352*0b459c2cSDavid du Colombier
3353*0b459c2cSDavid du Colombier@table @samp
3354*0b459c2cSDavid du Colombier@item t
3355*0b459c2cSDavid du Colombier@itemx numbered
3356*0b459c2cSDavid du ColombierAlways make numbered backups.
3357*0b459c2cSDavid du Colombier
3358*0b459c2cSDavid du Colombier@item nil
3359*0b459c2cSDavid du Colombier@itemx existing
3360*0b459c2cSDavid du ColombierMake numbered backups of files that already have them, simple backups of
3361*0b459c2cSDavid du Colombierthe others.  This is the default.
3362*0b459c2cSDavid du Colombier
3363*0b459c2cSDavid du Colombier@item never
3364*0b459c2cSDavid du Colombier@itemx simple
3365*0b459c2cSDavid du ColombierAlways make simple backups.
3366*0b459c2cSDavid du Colombier@end table
3367*0b459c2cSDavid du Colombier
3368*0b459c2cSDavid du ColombierAlternately, you can tell @code{patch} to prepend a prefix, such as a
3369*0b459c2cSDavid du Colombierdirectory name, to produce backup file names.  The @samp{-B
3370*0b459c2cSDavid du Colombier@var{backup-prefix}} or @samp{--prefix=@var{backup-prefix}} option makes
3371*0b459c2cSDavid du Colombierbackup files by prepending @var{backup-prefix} to them.  If you use this
3372*0b459c2cSDavid du Colombieroption, @code{patch} ignores any @samp{-b} option that you give.
3373*0b459c2cSDavid du Colombier
3374*0b459c2cSDavid du ColombierIf the backup file already exists, @code{patch} creates a new backup
3375*0b459c2cSDavid du Colombierfile name by changing the first lowercase letter in the last component
3376*0b459c2cSDavid du Colombierof the file name into uppercase.  If there are no more lowercase letters
3377*0b459c2cSDavid du Colombierin the name, it removes the first character from the name.  It repeats
3378*0b459c2cSDavid du Colombierthis process until it comes up with a backup file name that does not
3379*0b459c2cSDavid du Colombieralready exist.
3380*0b459c2cSDavid du Colombier
3381*0b459c2cSDavid du ColombierIf you specify the output file with the @samp{-o} option, that file is
3382*0b459c2cSDavid du Colombierthe one that is backed up, not the input file.
3383*0b459c2cSDavid du Colombier
3384*0b459c2cSDavid du Colombier@node Rejects, patch Options, Backups, Invoking patch
3385*0b459c2cSDavid du Colombier@section Reject File Names
3386*0b459c2cSDavid du Colombier@cindex reject file names
3387*0b459c2cSDavid du Colombier
3388*0b459c2cSDavid du ColombierThe names for reject files (files containing patches that @code{patch}
3389*0b459c2cSDavid du Colombiercould not find a place to apply) are normally the name of the output
3390*0b459c2cSDavid du Colombierfile with @samp{.rej} appended (or @samp{#} on systems that do not
3391*0b459c2cSDavid du Colombiersupport long file names).
3392*0b459c2cSDavid du Colombier
3393*0b459c2cSDavid du ColombierAlternatively, you can tell @code{patch} to place all of the rejected
3394*0b459c2cSDavid du Colombierpatches in a single file.  The @samp{-r @var{reject-file}} or
3395*0b459c2cSDavid du Colombier@samp{--reject-file=@var{reject-file}} option uses @var{reject-file} as
3396*0b459c2cSDavid du Colombierthe reject file name.
3397*0b459c2cSDavid du Colombier
3398*0b459c2cSDavid du Colombier@node patch Options, , Rejects, Invoking patch
3399*0b459c2cSDavid du Colombier@section Options to @code{patch}
3400*0b459c2cSDavid du Colombier@cindex @code{patch} options
3401*0b459c2cSDavid du Colombier@cindex options for @code{patch}
3402*0b459c2cSDavid du Colombier
3403*0b459c2cSDavid du ColombierHere is a summary of all of the options that @code{patch} accepts.
3404*0b459c2cSDavid du ColombierOlder versions of @code{patch} do not accept long-named options or the
3405*0b459c2cSDavid du Colombier@samp{-t}, @samp{-E}, or @samp{-V} options.
3406*0b459c2cSDavid du Colombier
3407*0b459c2cSDavid du ColombierMultiple single-letter options that do not take an argument can be
3408*0b459c2cSDavid du Colombiercombined into a single command line argument (with only one dash).
3409*0b459c2cSDavid du ColombierBrackets ([ and ]) indicate that an option takes an optional argument.
3410*0b459c2cSDavid du Colombier
3411*0b459c2cSDavid du Colombier@table @samp
3412*0b459c2cSDavid du Colombier@item -b @var{backup-suffix}
3413*0b459c2cSDavid du ColombierUse @var{backup-suffix} as the backup extension instead of
3414*0b459c2cSDavid du Colombier@samp{.orig} or @samp{~}.  @xref{Backups}.
3415*0b459c2cSDavid du Colombier
3416*0b459c2cSDavid du Colombier@item -B @var{backup-prefix}
3417*0b459c2cSDavid du ColombierUse @var{backup-prefix} as a prefix to the backup file name.  If this
3418*0b459c2cSDavid du Colombieroption is specified, any @samp{-b} option is ignored.  @xref{Backups}.
3419*0b459c2cSDavid du Colombier
3420*0b459c2cSDavid du Colombier@item --batch
3421*0b459c2cSDavid du ColombierDo not ask any questions.  @xref{patch Messages}.
3422*0b459c2cSDavid du Colombier
3423*0b459c2cSDavid du Colombier@item -c
3424*0b459c2cSDavid du Colombier@itemx --context
3425*0b459c2cSDavid du ColombierInterpret the patch file as a context diff.  @xref{patch Input}.
3426*0b459c2cSDavid du Colombier
3427*0b459c2cSDavid du Colombier@item -d @var{directory}
3428*0b459c2cSDavid du Colombier@itemx --directory=@var{directory}
3429*0b459c2cSDavid du ColombierMakes directory @var{directory} the current directory for interpreting
3430*0b459c2cSDavid du Colombierboth file names in the patch file, and file names given as arguments to
3431*0b459c2cSDavid du Colombierother options.  @xref{patch Directories}.
3432*0b459c2cSDavid du Colombier
3433*0b459c2cSDavid du Colombier@item -D @var{name}
3434*0b459c2cSDavid du ColombierMake merged if-then-else output using @var{format}.  @xref{If-then-else}.
3435*0b459c2cSDavid du Colombier
3436*0b459c2cSDavid du Colombier@item --debug=@var{number}
3437*0b459c2cSDavid du ColombierSet internal debugging flags.  Of interest only to @code{patch}
3438*0b459c2cSDavid du Colombierpatchers.
3439*0b459c2cSDavid du Colombier
3440*0b459c2cSDavid du Colombier@item -e
3441*0b459c2cSDavid du Colombier@itemx --ed
3442*0b459c2cSDavid du ColombierInterpret the patch file as an @code{ed} script.  @xref{patch Input}.
3443*0b459c2cSDavid du Colombier
3444*0b459c2cSDavid du Colombier@item -E
3445*0b459c2cSDavid du ColombierRemove output files that are empty after the patches have been applied.
3446*0b459c2cSDavid du Colombier@xref{Empty Files}.
3447*0b459c2cSDavid du Colombier
3448*0b459c2cSDavid du Colombier@item -f
3449*0b459c2cSDavid du ColombierAssume that the user knows exactly what he or she is doing, and do not
3450*0b459c2cSDavid du Colombierask any questions.  @xref{patch Messages}.
3451*0b459c2cSDavid du Colombier
3452*0b459c2cSDavid du Colombier@item -F @var{lines}
3453*0b459c2cSDavid du ColombierSet the maximum fuzz factor to @var{lines}.  @xref{Inexact}.
3454*0b459c2cSDavid du Colombier
3455*0b459c2cSDavid du Colombier@item --force
3456*0b459c2cSDavid du ColombierAssume that the user knows exactly what he or she is doing, and do not
3457*0b459c2cSDavid du Colombierask any questions.  @xref{patch Messages}.
3458*0b459c2cSDavid du Colombier
3459*0b459c2cSDavid du Colombier@item --forward
3460*0b459c2cSDavid du ColombierIgnore patches that @code{patch} thinks are reversed or already applied.
3461*0b459c2cSDavid du ColombierSee also @samp{-R}.  @xref{Reversed Patches}.
3462*0b459c2cSDavid du Colombier
3463*0b459c2cSDavid du Colombier@item --fuzz=@var{lines}
3464*0b459c2cSDavid du ColombierSet the maximum fuzz factor to @var{lines}.  @xref{Inexact}.
3465*0b459c2cSDavid du Colombier
3466*0b459c2cSDavid du Colombier@item --help
3467*0b459c2cSDavid du ColombierPrint a summary of the options that @code{patch} recognizes, then exit.
3468*0b459c2cSDavid du Colombier
3469*0b459c2cSDavid du Colombier@item --ifdef=@var{name}
3470*0b459c2cSDavid du ColombierMake merged if-then-else output using @var{format}.  @xref{If-then-else}.
3471*0b459c2cSDavid du Colombier
3472*0b459c2cSDavid du Colombier@item --ignore-white-space
3473*0b459c2cSDavid du Colombier@itemx -l
3474*0b459c2cSDavid du ColombierLet any sequence of white space in the patch file match any sequence of
3475*0b459c2cSDavid du Colombierwhite space in the input file.  @xref{Changed White Space}.
3476*0b459c2cSDavid du Colombier
3477*0b459c2cSDavid du Colombier@item -n
3478*0b459c2cSDavid du Colombier@itemx --normal
3479*0b459c2cSDavid du ColombierInterpret the patch file as a normal diff.  @xref{patch Input}.
3480*0b459c2cSDavid du Colombier
3481*0b459c2cSDavid du Colombier@item -N
3482*0b459c2cSDavid du ColombierIgnore patches that @code{patch} thinks are reversed or already applied.
3483*0b459c2cSDavid du ColombierSee also @samp{-R}.  @xref{Reversed Patches}.
3484*0b459c2cSDavid du Colombier
3485*0b459c2cSDavid du Colombier@item -o @var{output-file}
3486*0b459c2cSDavid du Colombier@itemx --output=@var{output-file}
3487*0b459c2cSDavid du ColombierUse @var{output-file} as the output file name.  @xref{patch Options}.
3488*0b459c2cSDavid du Colombier
3489*0b459c2cSDavid du Colombier@item -p@r{[}@var{number}@r{]}
3490*0b459c2cSDavid du ColombierSet the file name strip count to @var{number}.  @xref{patch Directories}.
3491*0b459c2cSDavid du Colombier
3492*0b459c2cSDavid du Colombier@item --prefix=@var{backup-prefix}
3493*0b459c2cSDavid du ColombierUse @var{backup-prefix} as a prefix to the backup file name.  If this
3494*0b459c2cSDavid du Colombieroption is specified, any @samp{-b} option is ignored.  @xref{Backups}.
3495*0b459c2cSDavid du Colombier
3496*0b459c2cSDavid du Colombier@item --quiet
3497*0b459c2cSDavid du ColombierWork silently unless an error occurs.  @xref{patch Messages}.
3498*0b459c2cSDavid du Colombier
3499*0b459c2cSDavid du Colombier@item -r @var{reject-file}
3500*0b459c2cSDavid du ColombierUse @var{reject-file} as the reject file name.  @xref{Rejects}.
3501*0b459c2cSDavid du Colombier
3502*0b459c2cSDavid du Colombier@item -R
3503*0b459c2cSDavid du ColombierAssume that this patch was created with the old and new files swapped.
3504*0b459c2cSDavid du Colombier@xref{Reversed Patches}.
3505*0b459c2cSDavid du Colombier
3506*0b459c2cSDavid du Colombier@item --reject-file=@var{reject-file}
3507*0b459c2cSDavid du ColombierUse @var{reject-file} as the reject file name.  @xref{Rejects}.
3508*0b459c2cSDavid du Colombier
3509*0b459c2cSDavid du Colombier@item --remove-empty-files
3510*0b459c2cSDavid du ColombierRemove output files that are empty after the patches have been applied.
3511*0b459c2cSDavid du Colombier@xref{Empty Files}.
3512*0b459c2cSDavid du Colombier
3513*0b459c2cSDavid du Colombier@item --reverse
3514*0b459c2cSDavid du ColombierAssume that this patch was created with the old and new files swapped.
3515*0b459c2cSDavid du Colombier@xref{Reversed Patches}.
3516*0b459c2cSDavid du Colombier
3517*0b459c2cSDavid du Colombier@item -s
3518*0b459c2cSDavid du ColombierWork silently unless an error occurs.  @xref{patch Messages}.
3519*0b459c2cSDavid du Colombier
3520*0b459c2cSDavid du Colombier@item -S
3521*0b459c2cSDavid du ColombierIgnore this patch from the patch file, but continue looking for the next
3522*0b459c2cSDavid du Colombierpatch in the file.  @xref{Multiple Patches}.
3523*0b459c2cSDavid du Colombier
3524*0b459c2cSDavid du Colombier@item --silent
3525*0b459c2cSDavid du ColombierWork silently unless an error occurs.  @xref{patch Messages}.
3526*0b459c2cSDavid du Colombier
3527*0b459c2cSDavid du Colombier@item --skip
3528*0b459c2cSDavid du ColombierIgnore this patch from the patch file, but continue looking for the next
3529*0b459c2cSDavid du Colombierpatch in the file.  @xref{Multiple Patches}.
3530*0b459c2cSDavid du Colombier
3531*0b459c2cSDavid du Colombier@item --strip@r{[}=@var{number}@r{]}
3532*0b459c2cSDavid du ColombierSet the file name strip count to @var{number}.  @xref{patch Directories}.
3533*0b459c2cSDavid du Colombier
3534*0b459c2cSDavid du Colombier@item --suffix=@var{backup-suffix}
3535*0b459c2cSDavid du ColombierUse @var{backup-suffix} as the backup extension instead of
3536*0b459c2cSDavid du Colombier@samp{.orig} or @samp{~}.  @xref{Backups}.
3537*0b459c2cSDavid du Colombier
3538*0b459c2cSDavid du Colombier@item -t
3539*0b459c2cSDavid du ColombierDo not ask any questions.  @xref{patch Messages}.
3540*0b459c2cSDavid du Colombier
3541*0b459c2cSDavid du Colombier@item -u
3542*0b459c2cSDavid du Colombier@itemx --unified
3543*0b459c2cSDavid du ColombierInterpret the patch file as a unified diff.  @xref{patch Input}.
3544*0b459c2cSDavid du Colombier
3545*0b459c2cSDavid du Colombier@item -v
3546*0b459c2cSDavid du ColombierOutput the revision header and patch level of @code{patch}.
3547*0b459c2cSDavid du Colombier
3548*0b459c2cSDavid du Colombier@item -V @var{backup-style}
3549*0b459c2cSDavid du ColombierSelect the kind of backups to make.  @xref{Backups}.
3550*0b459c2cSDavid du Colombier
3551*0b459c2cSDavid du Colombier@item --version
3552*0b459c2cSDavid du ColombierOutput the revision header and patch level of @code{patch}, then exit.
3553*0b459c2cSDavid du Colombier
3554*0b459c2cSDavid du Colombier@item --version=control=@var{backup-style}
3555*0b459c2cSDavid du ColombierSelect the kind of backups to make.  @xref{Backups}.
3556*0b459c2cSDavid du Colombier
3557*0b459c2cSDavid du Colombier@item -x @var{number}
3558*0b459c2cSDavid du ColombierSet internal debugging flags.  Of interest only to @code{patch}
3559*0b459c2cSDavid du Colombierpatchers.
3560*0b459c2cSDavid du Colombier@end table
3561*0b459c2cSDavid du Colombier
3562*0b459c2cSDavid du Colombier@node Invoking sdiff, Incomplete Lines, Invoking patch, Top
3563*0b459c2cSDavid du Colombier@chapter Invoking @code{sdiff}
3564*0b459c2cSDavid du Colombier@cindex invoking @code{sdiff}
3565*0b459c2cSDavid du Colombier@cindex @code{sdiff} invocation
3566*0b459c2cSDavid du Colombier
3567*0b459c2cSDavid du ColombierThe @code{sdiff} command merges two files and interactively outputs the
3568*0b459c2cSDavid du Colombierresults.  Its arguments are as follows:
3569*0b459c2cSDavid du Colombier
3570*0b459c2cSDavid du Colombier@example
3571*0b459c2cSDavid du Colombiersdiff -o @var{outfile} @var{options}@dots{} @var{from-file} @var{to-file}
3572*0b459c2cSDavid du Colombier@end example
3573*0b459c2cSDavid du Colombier
3574*0b459c2cSDavid du ColombierThis merges @var{from-file} with @var{to-file}, with output to @var{outfile}.
3575*0b459c2cSDavid du ColombierIf @var{from-file} is a directory and @var{to-file} is not, @code{sdiff}
3576*0b459c2cSDavid du Colombiercompares the file in @var{from-file} whose file name is that of @var{to-file},
3577*0b459c2cSDavid du Colombierand vice versa.  @var{from-file} and @var{to-file} may not both be
3578*0b459c2cSDavid du Colombierdirectories.
3579*0b459c2cSDavid du Colombier
3580*0b459c2cSDavid du Colombier@code{sdiff} options begin with @samp{-}, so normally @var{from-file}
3581*0b459c2cSDavid du Colombierand @var{to-file} may not begin with @samp{-}.  However, @samp{--} as an
3582*0b459c2cSDavid du Colombierargument by itself treats the remaining arguments as file names even if
3583*0b459c2cSDavid du Colombierthey begin with @samp{-}.  You may not use @samp{-} as an input file.
3584*0b459c2cSDavid du Colombier
3585*0b459c2cSDavid du ColombierAn exit status of 0 means no differences were found, 1 means some
3586*0b459c2cSDavid du Colombierdifferences were found, and 2 means trouble.
3587*0b459c2cSDavid du Colombier
3588*0b459c2cSDavid du Colombier@code{sdiff} without @samp{-o} (or @samp{--output}) produces a
3589*0b459c2cSDavid du Colombierside-by-side difference.  This usage is obsolete; use @samp{diff
3590*0b459c2cSDavid du Colombier--side-by-side} instead.
3591*0b459c2cSDavid du Colombier
3592*0b459c2cSDavid du Colombier@menu
3593*0b459c2cSDavid du Colombier* sdiff Options::	Summary of options to @code{diff}.
3594*0b459c2cSDavid du Colombier@end menu
3595*0b459c2cSDavid du Colombier
3596*0b459c2cSDavid du Colombier@node sdiff Options, , , Invoking sdiff
3597*0b459c2cSDavid du Colombier@section Options to @code{sdiff}
3598*0b459c2cSDavid du Colombier@cindex @code{sdiff} options
3599*0b459c2cSDavid du Colombier@cindex options for @code{sdiff}
3600*0b459c2cSDavid du Colombier
3601*0b459c2cSDavid du ColombierBelow is a summary of all of the options that GNU @code{sdiff} accepts.
3602*0b459c2cSDavid du ColombierEach option has two equivalent names, one of which is a single
3603*0b459c2cSDavid du Colombierletter preceded by @samp{-}, and the other of which is a long name
3604*0b459c2cSDavid du Colombierpreceded by @samp{--}.  Multiple single letter options (unless they take
3605*0b459c2cSDavid du Colombieran argument) can be combined into a single command line argument.  Long
3606*0b459c2cSDavid du Colombiernamed options can be abbreviated to any unique prefix of their name.
3607*0b459c2cSDavid du Colombier
3608*0b459c2cSDavid du Colombier@table @samp
3609*0b459c2cSDavid du Colombier@item -a
3610*0b459c2cSDavid du ColombierTreat all files as text and compare them line-by-line, even if they
3611*0b459c2cSDavid du Colombierdo not appear to be text.  @xref{Binary}.
3612*0b459c2cSDavid du Colombier
3613*0b459c2cSDavid du Colombier@item -b
3614*0b459c2cSDavid du ColombierIgnore changes in amount of white space.  @xref{White Space}.
3615*0b459c2cSDavid du Colombier
3616*0b459c2cSDavid du Colombier@item -B
3617*0b459c2cSDavid du ColombierIgnore changes that just insert or delete blank lines.  @xref{Blank
3618*0b459c2cSDavid du ColombierLines}.
3619*0b459c2cSDavid du Colombier
3620*0b459c2cSDavid du Colombier@item -d
3621*0b459c2cSDavid du ColombierChange the algorithm to perhaps find a smaller set of changes.  This
3622*0b459c2cSDavid du Colombiermakes @code{sdiff} slower (sometimes much slower).  @xref{diff
3623*0b459c2cSDavid du ColombierPerformance}.
3624*0b459c2cSDavid du Colombier
3625*0b459c2cSDavid du Colombier@item -H
3626*0b459c2cSDavid du ColombierUse heuristics to speed handling of large files that have numerous
3627*0b459c2cSDavid du Colombierscattered small changes.  @xref{diff Performance}.
3628*0b459c2cSDavid du Colombier
3629*0b459c2cSDavid du Colombier@item --expand-tabs
3630*0b459c2cSDavid du ColombierExpand tabs to spaces in the output, to preserve the alignment of tabs
3631*0b459c2cSDavid du Colombierin the input files.  @xref{Tabs}.
3632*0b459c2cSDavid du Colombier
3633*0b459c2cSDavid du Colombier@item -i
3634*0b459c2cSDavid du ColombierIgnore changes in case; consider upper- and lower-case to be the same.
3635*0b459c2cSDavid du Colombier@xref{Case Folding}.
3636*0b459c2cSDavid du Colombier
3637*0b459c2cSDavid du Colombier@item -I @var{regexp}
3638*0b459c2cSDavid du ColombierIgnore changes that just insert or delete lines that match @var{regexp}.
3639*0b459c2cSDavid du Colombier@xref{Specified Folding}.
3640*0b459c2cSDavid du Colombier
3641*0b459c2cSDavid du Colombier@item --ignore-all-space
3642*0b459c2cSDavid du ColombierIgnore white space when comparing lines.  @xref{White Space}.
3643*0b459c2cSDavid du Colombier
3644*0b459c2cSDavid du Colombier@item --ignore-blank-lines
3645*0b459c2cSDavid du ColombierIgnore changes that just insert or delete blank lines.  @xref{Blank
3646*0b459c2cSDavid du ColombierLines}.
3647*0b459c2cSDavid du Colombier
3648*0b459c2cSDavid du Colombier@item --ignore-case
3649*0b459c2cSDavid du ColombierIgnore changes in case; consider upper- and lower-case to be the same.
3650*0b459c2cSDavid du Colombier@xref{Case Folding}.
3651*0b459c2cSDavid du Colombier
3652*0b459c2cSDavid du Colombier@item --ignore-matching-lines=@var{regexp}
3653*0b459c2cSDavid du ColombierIgnore changes that just insert or delete lines that match @var{regexp}.
3654*0b459c2cSDavid du Colombier@xref{Specified Folding}.
3655*0b459c2cSDavid du Colombier
3656*0b459c2cSDavid du Colombier@item --ignore-space-change
3657*0b459c2cSDavid du ColombierIgnore changes in amount of white space.
3658*0b459c2cSDavid du Colombier@xref{White Space}.
3659*0b459c2cSDavid du Colombier
3660*0b459c2cSDavid du Colombier@item -l
3661*0b459c2cSDavid du Colombier@itemx --left-column
3662*0b459c2cSDavid du ColombierPrint only the left column of two common lines.
3663*0b459c2cSDavid du Colombier@xref{Side by Side Format}.
3664*0b459c2cSDavid du Colombier
3665*0b459c2cSDavid du Colombier@item --minimal
3666*0b459c2cSDavid du ColombierChange the algorithm to perhaps find a smaller set of changes.  This
3667*0b459c2cSDavid du Colombiermakes @code{sdiff} slower (sometimes much slower).  @xref{diff
3668*0b459c2cSDavid du ColombierPerformance}.
3669*0b459c2cSDavid du Colombier
3670*0b459c2cSDavid du Colombier@item -o @var{file}
3671*0b459c2cSDavid du Colombier@itemx --output=@var{file}
3672*0b459c2cSDavid du ColombierPut merged output into @var{file}.  This option is required for merging.
3673*0b459c2cSDavid du Colombier
3674*0b459c2cSDavid du Colombier@item -s
3675*0b459c2cSDavid du Colombier@itemx --suppress-common-lines
3676*0b459c2cSDavid du ColombierDo not print common lines.  @xref{Side by Side Format}.
3677*0b459c2cSDavid du Colombier
3678*0b459c2cSDavid du Colombier@item --speed-large-files
3679*0b459c2cSDavid du ColombierUse heuristics to speed handling of large files that have numerous
3680*0b459c2cSDavid du Colombierscattered small changes.  @xref{diff Performance}.
3681*0b459c2cSDavid du Colombier
3682*0b459c2cSDavid du Colombier@item -t
3683*0b459c2cSDavid du ColombierExpand tabs to spaces in the output, to preserve the alignment of tabs
3684*0b459c2cSDavid du Colombierin the input files.  @xref{Tabs}.
3685*0b459c2cSDavid du Colombier
3686*0b459c2cSDavid du Colombier@item --text
3687*0b459c2cSDavid du ColombierTreat all files as text and compare them line-by-line, even if they
3688*0b459c2cSDavid du Colombierdo not appear to be text.  @xref{Binary}.
3689*0b459c2cSDavid du Colombier
3690*0b459c2cSDavid du Colombier@item -v
3691*0b459c2cSDavid du Colombier@itemx --version
3692*0b459c2cSDavid du ColombierOutput the version number of @code{sdiff}.
3693*0b459c2cSDavid du Colombier
3694*0b459c2cSDavid du Colombier@item -w @var{columns}
3695*0b459c2cSDavid du Colombier@itemx --width=@var{columns}
3696*0b459c2cSDavid du ColombierUse an output width of @var{columns}.  @xref{Side by Side Format}.
3697*0b459c2cSDavid du ColombierNote that for historical reasons, this option is @samp{-W} in @code{diff},
3698*0b459c2cSDavid du Colombier@samp{-w} in @code{sdiff}.
3699*0b459c2cSDavid du Colombier
3700*0b459c2cSDavid du Colombier@item -W
3701*0b459c2cSDavid du ColombierIgnore horizontal white space when comparing lines.  @xref{White Space}.
3702*0b459c2cSDavid du ColombierNote that for historical reasons, this option is @samp{-w} in @code{diff},
3703*0b459c2cSDavid du Colombier@samp{-W} in @code{sdiff}.
3704*0b459c2cSDavid du Colombier@end table
3705*0b459c2cSDavid du Colombier
3706*0b459c2cSDavid du Colombier@node Incomplete Lines, Projects, Invoking sdiff, Top
3707*0b459c2cSDavid du Colombier@chapter Incomplete Lines
3708*0b459c2cSDavid du Colombier@cindex incomplete lines
3709*0b459c2cSDavid du Colombier@cindex full lines
3710*0b459c2cSDavid du Colombier@cindex newline treatment by @code{diff}
3711*0b459c2cSDavid du Colombier
3712*0b459c2cSDavid du ColombierWhen an input file ends in a non-newline character, its last line is
3713*0b459c2cSDavid du Colombiercalled an @dfn{incomplete line} because its last character is not a
3714*0b459c2cSDavid du Colombiernewline.  All other lines are called @dfn{full lines} and end in a
3715*0b459c2cSDavid du Colombiernewline character.  Incomplete lines do not match full lines unless
3716*0b459c2cSDavid du Colombierdifferences in white space are ignored (@pxref{White Space}).
3717*0b459c2cSDavid du Colombier
3718*0b459c2cSDavid du ColombierAn incomplete line is normally distinguished on output from a full line
3719*0b459c2cSDavid du Colombierby a following line that starts with @samp{\}.  However, the RCS format
3720*0b459c2cSDavid du Colombier(@pxref{RCS}) outputs the incomplete line as-is, without any trailing
3721*0b459c2cSDavid du Colombiernewline or following line.  The side by side format normally represents
3722*0b459c2cSDavid du Colombierincomplete lines as-is, but in some cases uses a @samp{\} or @samp{/}
3723*0b459c2cSDavid du Colombiergutter marker; @xref{Side by Side}.  The if-then-else line format
3724*0b459c2cSDavid du Colombierpreserves a line's incompleteness with @samp{%L}, and discards the
3725*0b459c2cSDavid du Colombiernewline with @samp{%l}; @xref{Line Formats}.  Finally, with the
3726*0b459c2cSDavid du Colombier@code{ed} and forward @code{ed} output formats (@pxref{Output Formats})
3727*0b459c2cSDavid du Colombier@code{diff} cannot represent an incomplete line, so it pretends there
3728*0b459c2cSDavid du Colombierwas a newline and reports an error.
3729*0b459c2cSDavid du Colombier
3730*0b459c2cSDavid du ColombierFor example, suppose @file{F} and @file{G} are one-byte files that
3731*0b459c2cSDavid du Colombiercontain just @samp{f} and @samp{g}, respectively.  Then @samp{diff F G}
3732*0b459c2cSDavid du Colombieroutputs
3733*0b459c2cSDavid du Colombier
3734*0b459c2cSDavid du Colombier@example
3735*0b459c2cSDavid du Colombier1c1
3736*0b459c2cSDavid du Colombier< f
3737*0b459c2cSDavid du Colombier\ No newline at end of file
3738*0b459c2cSDavid du Colombier---
3739*0b459c2cSDavid du Colombier> g
3740*0b459c2cSDavid du Colombier\ No newline at end of file
3741*0b459c2cSDavid du Colombier@end example
3742*0b459c2cSDavid du Colombier
3743*0b459c2cSDavid du Colombier@noindent
3744*0b459c2cSDavid du Colombier(The exact message may differ in non-English locales.)
3745*0b459c2cSDavid du Colombier@samp{diff -n F G} outputs the following without a trailing newline:
3746*0b459c2cSDavid du Colombier
3747*0b459c2cSDavid du Colombier@example
3748*0b459c2cSDavid du Colombierd1 1
3749*0b459c2cSDavid du Colombiera1 1
3750*0b459c2cSDavid du Colombierg
3751*0b459c2cSDavid du Colombier@end example
3752*0b459c2cSDavid du Colombier
3753*0b459c2cSDavid du Colombier@samp{diff -e F G} reports two errors and outputs the following:
3754*0b459c2cSDavid du Colombier
3755*0b459c2cSDavid du Colombier@example
3756*0b459c2cSDavid du Colombier1c
3757*0b459c2cSDavid du Colombierg
3758*0b459c2cSDavid du Colombier.
3759*0b459c2cSDavid du Colombier@end example
3760*0b459c2cSDavid du Colombier
3761*0b459c2cSDavid du Colombier@node Projects, Concept Index, Incomplete Lines, Top
3762*0b459c2cSDavid du Colombier@chapter Future Projects
3763*0b459c2cSDavid du Colombier
3764*0b459c2cSDavid du ColombierHere are some ideas for improving GNU @code{diff} and @code{patch}.  The
3765*0b459c2cSDavid du ColombierGNU project has identified some improvements as potential programming
3766*0b459c2cSDavid du Colombierprojects for volunteers.  You can also help by reporting any bugs that
3767*0b459c2cSDavid du Colombieryou find.
3768*0b459c2cSDavid du Colombier
3769*0b459c2cSDavid du ColombierIf you are a programmer and would like to contribute something to the
3770*0b459c2cSDavid du ColombierGNU project, please consider volunteering for one of these projects.  If
3771*0b459c2cSDavid du Colombieryou are seriously contemplating work, please write to
3772*0b459c2cSDavid du Colombier@samp{gnu@@prep.ai.mit.edu} to coordinate with other volunteers.
3773*0b459c2cSDavid du Colombier
3774*0b459c2cSDavid du Colombier@menu
3775*0b459c2cSDavid du Colombier* Shortcomings::	Suggested projects for improvements.
3776*0b459c2cSDavid du Colombier* Bugs::		Reporting bugs.
3777*0b459c2cSDavid du Colombier@end menu
3778*0b459c2cSDavid du Colombier
3779*0b459c2cSDavid du Colombier@node Shortcomings, Bugs, , Projects
3780*0b459c2cSDavid du Colombier@section Suggested Projects for Improving GNU @code{diff} and @code{patch}
3781*0b459c2cSDavid du Colombier@cindex projects for directories
3782*0b459c2cSDavid du Colombier
3783*0b459c2cSDavid du ColombierOne should be able to use GNU @code{diff} to generate a patch from any
3784*0b459c2cSDavid du Colombierpair of directory trees, and given the patch and a copy of one such
3785*0b459c2cSDavid du Colombiertree, use @code{patch} to generate a faithful copy of the other.
3786*0b459c2cSDavid du ColombierUnfortunately, some changes to directory trees cannot be expressed using
3787*0b459c2cSDavid du Colombiercurrent patch formats; also, @code{patch} does not handle some of the
3788*0b459c2cSDavid du Colombierexisting formats.  These shortcomings motivate the following suggested
3789*0b459c2cSDavid du Colombierprojects.
3790*0b459c2cSDavid du Colombier
3791*0b459c2cSDavid du Colombier@menu
3792*0b459c2cSDavid du Colombier* Changing Structure::	Handling changes to the directory structure.
3793*0b459c2cSDavid du Colombier* Special Files::	Handling symbolic links, device special files, etc.
3794*0b459c2cSDavid du Colombier* Unusual File Names::	Handling file names that contain unusual characters.
3795*0b459c2cSDavid du Colombier* Arbitrary Limits::	Patching non-text files.
3796*0b459c2cSDavid du Colombier* Large Files::		Handling files that do not fit in memory.
3797*0b459c2cSDavid du Colombier* Ignoring Changes::	Ignoring certain changes while showing others.
3798*0b459c2cSDavid du Colombier@end menu
3799*0b459c2cSDavid du Colombier
3800*0b459c2cSDavid du Colombier@node Changing Structure, Special Files, , Shortcomings
3801*0b459c2cSDavid du Colombier@subsection Handling Changes to the Directory Structure
3802*0b459c2cSDavid du Colombier@cindex directory structure changes
3803*0b459c2cSDavid du Colombier
3804*0b459c2cSDavid du Colombier@code{diff} and @code{patch} do not handle some changes to directory
3805*0b459c2cSDavid du Colombierstructure.  For example, suppose one directory tree contains a directory
3806*0b459c2cSDavid du Colombiernamed @samp{D} with some subsidiary files, and another contains a file
3807*0b459c2cSDavid du Colombierwith the same name @samp{D}.  @samp{diff -r} does not output enough
3808*0b459c2cSDavid du Colombierinformation for @code{patch} to transform the the directory subtree into
3809*0b459c2cSDavid du Colombierthe file.
3810*0b459c2cSDavid du Colombier
3811*0b459c2cSDavid du ColombierThere should be a way to specify that a file has been deleted without
3812*0b459c2cSDavid du Colombierhaving to include its entire contents in the patch file.  There should
3813*0b459c2cSDavid du Colombieralso be a way to tell @code{patch} that a file was renamed, even if
3814*0b459c2cSDavid du Colombierthere is no way for @code{diff} to generate such information.
3815*0b459c2cSDavid du Colombier
3816*0b459c2cSDavid du ColombierThese problems can be fixed by extending the @code{diff} output format
3817*0b459c2cSDavid du Colombierto represent changes in directory structure, and extending @code{patch}
3818*0b459c2cSDavid du Colombierto understand these extensions.
3819*0b459c2cSDavid du Colombier
3820*0b459c2cSDavid du Colombier@node Special Files, Unusual File Names, Changing Structure, Shortcomings
3821*0b459c2cSDavid du Colombier@subsection Files that are Neither Directories Nor Regular Files
3822*0b459c2cSDavid du Colombier@cindex special files
3823*0b459c2cSDavid du Colombier
3824*0b459c2cSDavid du ColombierSome files are neither directories nor regular files: they are unusual
3825*0b459c2cSDavid du Colombierfiles like symbolic links, device special files, named pipes, and
3826*0b459c2cSDavid du Colombiersockets.  Currently, @code{diff} treats symbolic links like regular files;
3827*0b459c2cSDavid du Colombierit treats other special files like regular files if they are specified
3828*0b459c2cSDavid du Colombierat the top level, but simply reports their presence when comparing
3829*0b459c2cSDavid du Colombierdirectories.  This means that @code{patch} cannot represent changes
3830*0b459c2cSDavid du Colombierto such files.  For example, if you change which file a symbolic link
3831*0b459c2cSDavid du Colombierpoints to, @code{diff} outputs the difference between the two files,
3832*0b459c2cSDavid du Colombierinstead of the change to the symbolic link.
3833*0b459c2cSDavid du Colombier
3834*0b459c2cSDavid du Colombier@c This might not be a good idea; is it wise for root to install devices
3835*0b459c2cSDavid du Colombier@c this way?
3836*0b459c2cSDavid du Colombier@code{diff} should optionally report changes to special files specially,
3837*0b459c2cSDavid du Colombierand @code{patch} should be extended to understand these extensions.
3838*0b459c2cSDavid du Colombier
3839*0b459c2cSDavid du Colombier@node Unusual File Names, Arbitrary Limits, Special Files, Shortcomings
3840*0b459c2cSDavid du Colombier@subsection File Names that Contain Unusual Characters
3841*0b459c2cSDavid du Colombier@cindex file names with unusual characters
3842*0b459c2cSDavid du Colombier
3843*0b459c2cSDavid du ColombierWhen a file name contains an unusual character like a newline or
3844*0b459c2cSDavid du Colombierwhite space, @samp{diff -r} generates a patch that @code{patch} cannot
3845*0b459c2cSDavid du Colombierparse.  The problem is with format of @code{diff} output, not just with
3846*0b459c2cSDavid du Colombier@code{patch}, because with odd enough file names one can cause
3847*0b459c2cSDavid du Colombier@code{diff} to generate a patch that is syntactically correct but
3848*0b459c2cSDavid du Colombierpatches the wrong files.  The format of @code{diff} output should be
3849*0b459c2cSDavid du Colombierextended to handle all possible file names.
3850*0b459c2cSDavid du Colombier
3851*0b459c2cSDavid du Colombier@node Arbitrary Limits, Large Files, Unusual File Names, Shortcomings
3852*0b459c2cSDavid du Colombier@subsection Arbitrary Limits
3853*0b459c2cSDavid du Colombier@cindex binary file patching
3854*0b459c2cSDavid du Colombier
3855*0b459c2cSDavid du ColombierGNU @code{diff} can analyze files with arbitrarily long lines and files
3856*0b459c2cSDavid du Colombierthat end in incomplete lines.  However, @code{patch} cannot patch such
3857*0b459c2cSDavid du Colombierfiles.  The @code{patch} internal limits on line lengths should be
3858*0b459c2cSDavid du Colombierremoved, and @code{patch} should be extended to parse @code{diff}
3859*0b459c2cSDavid du Colombierreports of incomplete lines.
3860*0b459c2cSDavid du Colombier
3861*0b459c2cSDavid du Colombier@node Large Files, Ignoring Changes, Arbitrary Limits, Shortcomings
3862*0b459c2cSDavid du Colombier@subsection Handling Files that Do Not Fit in Memory
3863*0b459c2cSDavid du Colombier@cindex large files
3864*0b459c2cSDavid du Colombier
3865*0b459c2cSDavid du Colombier@code{diff} operates by reading both files into memory.  This method
3866*0b459c2cSDavid du Colombierfails if the files are too large, and @code{diff} should have a fallback.
3867*0b459c2cSDavid du Colombier
3868*0b459c2cSDavid du ColombierOne way to do this is to scan the files sequentially to compute hash
3869*0b459c2cSDavid du Colombiercodes of the lines and put the lines in equivalence classes based only
3870*0b459c2cSDavid du Colombieron hash code.  Then compare the files normally.  This does produce some
3871*0b459c2cSDavid du Colombierfalse matches.
3872*0b459c2cSDavid du Colombier
3873*0b459c2cSDavid du ColombierThen scan the two files sequentially again, checking each match to see
3874*0b459c2cSDavid du Colombierwhether it is real.  When a match is not real, mark both the
3875*0b459c2cSDavid du Colombier``matching'' lines as changed.  Then build an edit script as usual.
3876*0b459c2cSDavid du Colombier
3877*0b459c2cSDavid du ColombierThe output routines would have to be changed to scan the files
3878*0b459c2cSDavid du Colombiersequentially looking for the text to print.
3879*0b459c2cSDavid du Colombier
3880*0b459c2cSDavid du Colombier@node Ignoring Changes,, Large Files, Shortcomings
3881*0b459c2cSDavid du Colombier@subsection Ignoring Certain Changes
3882*0b459c2cSDavid du Colombier
3883*0b459c2cSDavid du ColombierIt would be nice to have a feature for specifying two strings, one in
3884*0b459c2cSDavid du Colombier@var{from-file} and one in @var{to-file}, which should be considered to
3885*0b459c2cSDavid du Colombiermatch.  Thus, if the two strings are @samp{foo} and @samp{bar}, then if
3886*0b459c2cSDavid du Colombiertwo lines differ only in that @samp{foo} in file 1 corresponds to
3887*0b459c2cSDavid du Colombier@samp{bar} in file 2, the lines are treated as identical.
3888*0b459c2cSDavid du Colombier
3889*0b459c2cSDavid du ColombierIt is not clear how general this feature can or should be, or
3890*0b459c2cSDavid du Colombierwhat syntax should be used for it.
3891*0b459c2cSDavid du Colombier
3892*0b459c2cSDavid du Colombier@node Bugs, , Shortcomings, Projects
3893*0b459c2cSDavid du Colombier@section Reporting Bugs
3894*0b459c2cSDavid du Colombier@cindex bug reports
3895*0b459c2cSDavid du Colombier@cindex reporting bugs
3896*0b459c2cSDavid du Colombier
3897*0b459c2cSDavid du ColombierIf you think you have found a bug in GNU @code{cmp}, @code{diff},
3898*0b459c2cSDavid du Colombier@code{diff3}, @code{sdiff}, or @code{patch}, please report it by
3899*0b459c2cSDavid du Colombierelectronic mail to @samp{bug-gnu-utils@@prep.ai.mit.edu}.  Send as
3900*0b459c2cSDavid du Colombierprecise a description of the problem as you can, including sample input
3901*0b459c2cSDavid du Colombierfiles that produce the bug, if applicable.
3902*0b459c2cSDavid du Colombier
3903*0b459c2cSDavid du ColombierBecause Larry Wall has not released a new version of @code{patch} since
3904*0b459c2cSDavid du Colombiermid 1988 and the GNU version of @code{patch} has been changed since
3905*0b459c2cSDavid du Colombierthen, please send bug reports for @code{patch} by electronic mail to
3906*0b459c2cSDavid du Colombierboth @samp{bug-gnu-utils@@prep.ai.mit.edu} and
3907*0b459c2cSDavid du Colombier@samp{lwall@@netlabs.com}.
3908*0b459c2cSDavid du Colombier
3909*0b459c2cSDavid du Colombier@node Concept Index, , Projects, Top
3910*0b459c2cSDavid du Colombier@unnumbered Concept Index
3911*0b459c2cSDavid du Colombier
3912*0b459c2cSDavid du Colombier@printindex cp
3913*0b459c2cSDavid du Colombier
3914*0b459c2cSDavid du Colombier@shortcontents
3915*0b459c2cSDavid du Colombier@contents
3916*0b459c2cSDavid du Colombier@bye
3917