1279519Sbapt.Dd 2015-03-02
2279519Sbapt.Dt DIFF 7
3279519Sbapt.Os
4279519Sbapt.Sh NAME
5279519Sbapt.Nm diff
6279519Sbapt.Nd Comparing and Merging Files
7279519Sbapt.Sh  Comparing and Merging Files
8279519Sbapt.Sh  Overview
9279519SbaptComputer users often find occasion to ask how two files differ. Perhaps one
10279519Sbaptfile is a newer version of the other file. Or maybe the two files started
11279519Sbaptout as identical copies but were changed by different people.
12279519Sbapt.Pp
13279519SbaptYou can use the
14279519Sbapt.Xr diff
15279519Sbaptcommand to show differences between two files, or each corresponding file
16279519Sbaptin two directories.
17279519Sbapt.Xr diff
18279519Sbaptoutputs differences between files line by line in any of several formats,
19279519Sbaptselectable by command line options. This set of differences is often called
20279519Sbapta
21279519Sbapt.Em diff
22279519Sbaptor
23279519Sbapt.Em patch .
24279519SbaptFor files that are identical,
25279519Sbapt.Xr diff
26279519Sbaptnormally produces no output; for binary (non-text) files,
27279519Sbapt.Xr diff
28279519Sbaptnormally reports only that they are different.
29279519Sbapt.Pp
30279519SbaptYou can use the
31279519Sbapt.Xr cmp
32279519Sbaptcommand to show the byte and line numbers where two files differ.
33279519Sbapt.Xr cmp
34279519Sbaptcan also show all the bytes that differ between the two files, side by side.
35279519SbaptA way to compare two files character by character is the Emacs command
36279519Sbapt.Li M-x compare-windows .
37279519SbaptSee Section.Dq Other Window ,
38279519Sbaptfor more information on that command.
39279519Sbapt.Pp
40279519SbaptYou can use the
41279519Sbapt.Xr diff3
42279519Sbaptcommand to show differences among three files. When two people have made independent
43279519Sbaptchanges to a common original,
44279519Sbapt.Xr diff3
45279519Sbaptcan report the differences between the original and the two changed versions,
46279519Sbaptand can produce a merged file that contains both persons' changes together
47279519Sbaptwith warnings about conflicts.
48279519Sbapt.Pp
49279519SbaptYou can use the
50279519Sbapt.Xr sdiff
51279519Sbaptcommand to merge two files interactively.
52279519Sbapt.Pp
53279519SbaptYou can use the set of differences produced by
54279519Sbapt.Xr diff
55279519Sbaptto distribute updates to text files (such as program source code) to other
56279519Sbaptpeople. This method is especially useful when the differences are small compared
57279519Sbaptto the complete files. Given
58279519Sbapt.Xr diff
59279519Sbaptoutput, you can use the
60279519Sbapt.Xr patch
61279519Sbaptprogram to update, or
62279519Sbapt.Em patch ,
63279519Sbapta copy of the file. If you think of
64279519Sbapt.Xr diff
65279519Sbaptas subtracting one file from another to produce their difference, you can
66279519Sbaptthink of
67279519Sbapt.Xr patch
68279519Sbaptas adding the difference to one file to reproduce the other.
69279519Sbapt.Pp
70279519SbaptThis manual first concentrates on making diffs, and later shows how to use
71279519Sbaptdiffs to update files.
72279519Sbapt.Pp
73279519SbaptGNU
74279519Sbapt.Xr diff
75279519Sbaptwas written by Paul Eggert, Mike Haertel, David Hayes, Richard Stallman, and
76279519SbaptLen Tower. Wayne Davison designed and implemented the unified output format.
77279519SbaptThe basic algorithm is described by Eugene W. Myers in \(lqAn O(ND) Difference
78279519SbaptAlgorithm and its Variations\(rq,
79279519Sbapt.Em Algorithmica
80279519SbaptVol. 1 No. 2, 1986, pp. 251--266; and in \(lqA File Comparison Program\(rq, Webb Miller
81279519Sbaptand Eugene W. Myers,
82279519Sbapt.Em Software---Practice and Experience
83279519SbaptVol. 15 No. 11, 1985, pp. 1025--1040. The algorithm was independently discovered
84279519Sbaptas described by E. Ukkonen in \(lqAlgorithms for Approximate String Matching\(rq,
85279519Sbapt.Em Information and Control
86279519SbaptVol. 64, 1985, pp. 100--118. Unless the
87279519Sbapt.Op --minimal
88279519Sbaptoption is used,
89279519Sbapt.Xr diff
90279519Sbaptuses a heuristic by Paul Eggert that limits the cost to O(N^1.5 log N) at
91279519Sbaptthe price of producing suboptimal output for large inputs with many differences.
92279519SbaptRelated algorithms are surveyed by Alfred V. Aho in section 6.3 of \(lqAlgorithms
93279519Sbaptfor Finding Patterns in Strings\(rq,
94279519Sbapt.Em Handbook of Theoretical Computer Science
95279519Sbapt(Jan Van Leeuwen, ed.), Vol. A,
96279519Sbapt.Em Algorithms and Complexity ,
97279519SbaptElsevier/MIT Press, 1990, pp. 255--300.
98279519Sbapt.Pp
99279519SbaptGNU
100279519Sbapt.Xr diff3
101279519Sbaptwas written by Randy Smith. GNU
102279519Sbapt.Xr sdiff
103279519Sbaptwas written by Thomas Lord. GNU
104279519Sbapt.Xr cmp
105279519Sbaptwas written by Torbj\(:orn Granlund and David MacKenzie.
106279519Sbapt.Pp
107279519SbaptGNU
108279519Sbapt.Xr patch
109279519Sbaptwas written mainly by Larry Wall and Paul Eggert; several GNU enhancements
110279519Sbaptwere contributed by Wayne Davison and David MacKenzie. Parts of this manual
111279519Sbaptare adapted from a manual page written by Larry Wall, with his permission.
112279519Sbapt.Pp
113279519Sbapt.Sh  What Comparison Means
114279519SbaptThere are several ways to think about the differences between two files. One
115279519Sbaptway to think of the differences is as a series of lines that were deleted
116279519Sbaptfrom, inserted in, or changed in one file to produce the other file.
117279519Sbapt.Xr diff
118279519Sbaptcompares two files line by line, finds groups of lines that differ, and reports
119279519Sbapteach group of differing lines. It can report the differing lines in several
120279519Sbaptformats, which have different purposes.
121279519Sbapt.Pp
122279519SbaptGNU
123279519Sbapt.Xr diff
124279519Sbaptcan show whether files are different without detailing the differences. It
125279519Sbaptalso provides ways to suppress certain kinds of differences that are not important
126279519Sbaptto you. Most commonly, such differences are changes in the amount of white
127279519Sbaptspace between words or lines.
128279519Sbapt.Xr diff
129279519Sbaptalso provides ways to suppress differences in alphabetic case or in lines
130279519Sbaptthat match a regular expression that you provide. These options can accumulate;
131279519Sbaptfor example, you can ignore changes in both white space and alphabetic case.
132279519Sbapt.Pp
133279519SbaptAnother way to think of the differences between two files is as a sequence
134279519Sbaptof pairs of bytes that can be either identical or different.
135279519Sbapt.Xr cmp
136279519Sbaptreports the differences between two files byte by byte, instead of line by
137279519Sbaptline. As a result, it is often more useful than
138279519Sbapt.Xr diff
139279519Sbaptfor comparing binary files. For text files,
140279519Sbapt.Xr cmp
141279519Sbaptis useful mainly when you want to know only whether two files are identical,
142279519Sbaptor whether one file is a prefix of the other.
143279519Sbapt.Pp
144279519SbaptTo illustrate the effect that considering changes byte by byte can have compared
145279519Sbaptwith considering them line by line, think of what happens if a single newline
146279519Sbaptcharacter is added to the beginning of a file. If that file is then compared
147279519Sbaptwith an otherwise identical file that lacks the newline at the beginning,
148279519Sbapt.Xr diff
149279519Sbaptwill report that a blank line has been added to the file, while
150279519Sbapt.Xr cmp
151279519Sbaptwill report that almost every byte of the two files differs.
152279519Sbapt.Pp
153279519Sbapt.Xr diff3
154279519Sbaptnormally compares three input files line by line, finds groups of lines that
155279519Sbaptdiffer, and reports each group of differing lines. Its output is designed
156279519Sbaptto make it easy to inspect two different sets of changes to the same file.
157279519Sbapt.Pp
158279519Sbapt.Ss  Hunks
159279519SbaptWhen comparing two files,
160279519Sbapt.Xr diff
161279519Sbaptfinds sequences of lines common to both files, interspersed with groups of
162279519Sbaptdiffering lines called
163279519Sbapt.Em hunks .
164279519SbaptComparing two identical files yields one sequence of common lines and no hunks,
165279519Sbaptbecause no lines differ. Comparing two entirely different files yields no
166279519Sbaptcommon lines and one large hunk that contains all lines of both files. In
167279519Sbaptgeneral, there are many ways to match up lines between two given files.
168279519Sbapt.Xr diff
169279519Sbapttries to minimize the total hunk size by finding large sequences of common
170279519Sbaptlines interspersed with small hunks of differing lines.
171279519Sbapt.Pp
172279519SbaptFor example, suppose the file
173279519Sbapt.Pa F
174279519Sbaptcontains the three lines
175279519Sbapt.Li a ,
176279519Sbapt.Li b ,
177279519Sbapt.Li c ,
178279519Sbaptand the file
179279519Sbapt.Pa G
180279519Sbaptcontains the same three lines in reverse order
181279519Sbapt.Li c ,
182279519Sbapt.Li b ,
183279519Sbapt.Li a .
184279519SbaptIf
185279519Sbapt.Xr diff
186279519Sbaptfinds the line
187279519Sbapt.Li c
188279519Sbaptas common, then the command
189279519Sbapt.Li diff F G
190279519Sbaptproduces this output:
191279519Sbapt.Pp
192279519Sbapt.Bd -literal -offset indent
193279519Sbapt1,2d0
194279519Sbapt< a
195279519Sbapt< b
196279519Sbapt3a2,3
197279519Sbapt> b
198279519Sbapt> a
199279519Sbapt.Ed
200279519Sbapt.Pp
201279519SbaptBut if
202279519Sbapt.Xr diff
203279519Sbaptnotices the common line
204279519Sbapt.Li b
205279519Sbaptinstead, it produces this output:
206279519Sbapt.Pp
207279519Sbapt.Bd -literal -offset indent
208279519Sbapt1c1
209279519Sbapt< a
210279519Sbapt---
211279519Sbapt> c
212279519Sbapt3c3
213279519Sbapt< c
214279519Sbapt---
215279519Sbapt> a
216279519Sbapt.Ed
217279519Sbapt.Pp
218279519SbaptIt is also possible to find
219279519Sbapt.Li a
220279519Sbaptas the common line.
221279519Sbapt.Xr diff
222279519Sbaptdoes not always find an optimal matching between the files; it takes shortcuts
223279519Sbaptto run faster. But its output is usually close to the shortest possible. You
224279519Sbaptcan adjust this tradeoff with the
225279519Sbapt.Op -d
226279519Sbaptor
227279519Sbapt.Op --minimal
228279519Sbaptoption (see Section
229279519Sbapt.Dq diff Performance ) .
230279519Sbapt.Pp
231279519Sbapt.Ss  Suppressing Differences in Blank and Tab Spacing
232279519SbaptThe
233279519Sbapt.Op -E
234279519Sbaptor
235279519Sbapt.Op --ignore-tab-expansion
236279519Sbaptoption ignores the distinction between tabs and spaces on input. A tab is
237279519Sbaptconsidered to be equivalent to the number of spaces to the next tab stop (see Section
238279519Sbapt.Dq Tabs ) .
239279519Sbapt.Pp
240279519SbaptThe
241279519Sbapt.Op -b
242279519Sbaptor
243279519Sbapt.Op --ignore-space-change
244279519Sbaptoption is stronger. It ignores white space at line end, and considers all
245279519Sbaptother sequences of one or more white space characters within a line to be
246279519Sbaptequivalent. With this option,
247279519Sbapt.Xr diff
248279519Sbaptconsiders the following two lines to be equivalent, where
249279519Sbapt.Li $
250279519Sbaptdenotes the line end:
251279519Sbapt.Pp
252279519Sbapt.Bd -literal -offset indent
253279519SbaptHere lyeth  muche rychnesse  in lytell space.   -- John Heywood$
254279519SbaptHere lyeth muche rychnesse in lytell space. -- John Heywood   $
255279519Sbapt.Ed
256279519Sbapt.Pp
257279519SbaptThe
258279519Sbapt.Op -w
259279519Sbaptor
260279519Sbapt.Op --ignore-all-space
261279519Sbaptoption is stronger still. It ignores differences even if one line has white
262279519Sbaptspace where the other line has none.
263279519Sbapt.Em White space
264279519Sbaptcharacters include tab, newline, vertical tab, form feed, carriage return,
265279519Sbaptand space; some locales may define additional characters to be white space.
266279519SbaptWith this option,
267279519Sbapt.Xr diff
268279519Sbaptconsiders the following two lines to be equivalent, where
269279519Sbapt.Li $
270279519Sbaptdenotes the line end and
271279519Sbapt.Li ^M
272279519Sbaptdenotes a carriage return:
273279519Sbapt.Pp
274279519Sbapt.Bd -literal -offset indent
275279519SbaptHere lyeth  muche  rychnesse in lytell space.--  John Heywood$
276279519Sbapt  He relyeth much erychnes  seinly tells pace.  --John Heywood   ^M$
277279519Sbapt.Ed
278279519Sbapt.Pp
279279519Sbapt.Ss  Suppressing Differences Whose Lines Are All Blank
280279519SbaptThe
281279519Sbapt.Op -B
282279519Sbaptor
283279519Sbapt.Op --ignore-blank-lines
284279519Sbaptoption ignores changes that consist entirely of blank lines. With this option,
285279519Sbaptfor example, a file containing
286279519Sbapt.Bd -literal -offset indent
287279519Sbapt1.  A point is that which has no part.
288279519Sbapt
289279519Sbapt2.  A line is breadthless length.
290279519Sbapt-- Euclid, The Elements, I
291279519Sbapt.Ed
292279519Sbaptis considered identical to a file containing
293279519Sbapt.Bd -literal -offset indent
294279519Sbapt1.  A point is that which has no part.
295279519Sbapt2.  A line is breadthless length.
296279519Sbapt
297279519Sbapt
298279519Sbapt-- Euclid, The Elements, I
299279519Sbapt.Ed
300279519Sbapt.Pp
301279519SbaptNormally this option affects only lines that are completely empty, but if
302279519Sbaptyou also specify the
303279519Sbapt.Op -b
304279519Sbaptor
305279519Sbapt.Op --ignore-space-change
306279519Sbaptoption, or the
307279519Sbapt.Op -w
308279519Sbaptor
309279519Sbapt.Op --ignore-all-space
310279519Sbaptoption, lines are also affected if they look empty but contain white space.
311279519SbaptIn other words,
312279519Sbapt.Op -B
313279519Sbaptis equivalent to
314279519Sbapt.Li -I '^$'
315279519Sbaptby default, but it is equivalent to
316279519Sbapt.Op -I '^[[:space:]]*$'
317279519Sbaptif
318279519Sbapt.Op -b
319279519Sbaptor
320279519Sbapt.Op -w
321279519Sbaptis also specified.
322279519Sbapt.Pp
323279519Sbapt.Ss  Suppressing Differences Whose Lines All Match a Regular Expression
324279519SbaptTo ignore insertions and deletions of lines that match a
325279519Sbapt.Xr grep
326279519Sbapt-style regular expression, use the
327279519Sbapt.Op -I Va regexp
328279519Sbaptor
329279519Sbapt.Op --ignore-matching-lines= Va regexp
330279519Sbaptoption. You should escape regular expressions that contain shell metacharacters
331279519Sbaptto prevent the shell from expanding them. For example,
332279519Sbapt.Li diff -I '^[[:digit:]]'
333279519Sbaptignores all changes to lines beginning with a digit.
334279519Sbapt.Pp
335279519SbaptHowever,
336279519Sbapt.Op -I
337279519Sbaptonly ignores the insertion or deletion of lines that contain the regular expression
338279519Sbaptif every changed line in the hunk---every insertion and every deletion---matches
339279519Sbaptthe regular expression. In other words, for each nonignorable change,
340279519Sbapt.Xr diff
341279519Sbaptprints the complete set of changes in its vicinity, including the ignorable
342279519Sbaptones.
343279519Sbapt.Pp
344279519SbaptYou can specify more than one regular expression for lines to ignore by using
345279519Sbaptmore than one
346279519Sbapt.Op -I
347279519Sbaptoption.
348279519Sbapt.Xr diff
349279519Sbapttries to match each line against each regular expression.
350279519Sbapt.Pp
351279519Sbapt.Ss  Suppressing Case Differences
352279519SbaptGNU
353279519Sbapt.Xr diff
354279519Sbaptcan treat lower case letters as equivalent to their upper case counterparts,
355279519Sbaptso that, for example, it considers
356279519Sbapt.Li Funky Stuff ,
357279519Sbapt.Li funky STUFF ,
358279519Sbaptand
359279519Sbapt.Li fUNKy stuFf
360279519Sbaptto all be the same. To request this, use the
361279519Sbapt.Op -i
362279519Sbaptor
363279519Sbapt.Op --ignore-case
364279519Sbaptoption.
365279519Sbapt.Pp
366279519Sbapt.Ss  Summarizing Which Files Differ
367279519SbaptWhen you only want to find out whether files are different, and you don't
368279519Sbaptcare what the differences are, you can use the summary output format. In this
369279519Sbaptformat, instead of showing the differences between the files,
370279519Sbapt.Xr diff
371279519Sbaptsimply reports whether files differ. The
372279519Sbapt.Op -q
373279519Sbaptor
374279519Sbapt.Op --brief
375279519Sbaptoption selects this output format.
376279519Sbapt.Pp
377279519SbaptThis format is especially useful when comparing the contents of two directories.
378279519SbaptIt is also much faster than doing the normal line by line comparisons, because
379279519Sbapt.Xr diff
380279519Sbaptcan stop analyzing the files as soon as it knows that there are any differences.
381279519Sbapt.Pp
382279519SbaptYou can also get a brief indication of whether two files differ by using
383279519Sbapt.Xr cmp .
384279519SbaptFor files that are identical,
385279519Sbapt.Xr cmp
386279519Sbaptproduces no output. When the files differ, by default,
387279519Sbapt.Xr cmp
388279519Sbaptoutputs the byte and line number where the first difference occurs, or reports
389279519Sbaptthat one file is a prefix of the other. You can use the
390279519Sbapt.Op -s ,
391279519Sbapt.Op --quiet ,
392279519Sbaptor
393279519Sbapt.Op --silent
394279519Sbaptoption to suppress that information, so that
395279519Sbapt.Xr cmp
396279519Sbaptproduces no output and reports whether the files differ using only its exit
397279519Sbaptstatus (see Section
398279519Sbapt.Dq Invoking cmp ) .
399279519Sbapt.Pp
400279519SbaptUnlike
401279519Sbapt.Xr diff ,
402279519Sbapt.Xr cmp
403279519Sbaptcannot compare directories; it can only compare two files.
404279519Sbapt.Pp
405279519Sbapt.Ss  Binary Files and Forcing Text Comparisons
406279519SbaptIf
407279519Sbapt.Xr diff
408279519Sbaptthinks that either of the two files it is comparing is binary (a non-text
409279519Sbaptfile), it normally treats that pair of files much as if the summary output
410279519Sbaptformat had been selected (see Section
411279519Sbapt.Dq Brief ) ,
412279519Sbaptand reports only that the binary files are different. This is because line
413279519Sbaptby line comparisons are usually not meaningful for binary files.
414279519Sbapt.Pp
415279519Sbapt.Xr diff
416279519Sbaptdetermines whether a file is text or binary by checking the first few bytes
417279519Sbaptin the file; the exact number of bytes is system dependent, but it is typically
418279519Sbaptseveral thousand. If every byte in that part of the file is non-null,
419279519Sbapt.Xr diff
420279519Sbaptconsiders the file to be text; otherwise it considers the file to be binary.
421279519Sbapt.Pp
422279519SbaptSometimes you might want to force
423279519Sbapt.Xr diff
424279519Sbaptto consider files to be text. For example, you might be comparing text files
425279519Sbaptthat contain null characters;
426279519Sbapt.Xr diff
427279519Sbaptwould erroneously decide that those are non-text files. Or you might be comparing
428279519Sbaptdocuments that are in a format used by a word processing system that uses
429279519Sbaptnull characters to indicate special formatting. You can force
430279519Sbapt.Xr diff
431279519Sbaptto consider all files to be text files, and compare them line by line, by
432279519Sbaptusing the
433279519Sbapt.Op -a
434279519Sbaptor
435279519Sbapt.Op --text
436279519Sbaptoption. If the files you compare using this option do not in fact contain
437279519Sbapttext, they will probably contain few newline characters, and the
438279519Sbapt.Xr diff
439279519Sbaptoutput will consist of hunks showing differences between long lines of whatever
440279519Sbaptcharacters the files contain.
441279519Sbapt.Pp
442279519SbaptYou can also force
443279519Sbapt.Xr diff
444279519Sbaptto report only whether files differ (but not how). Use the
445279519Sbapt.Op -q
446279519Sbaptor
447279519Sbapt.Op --brief
448279519Sbaptoption for this.
449279519Sbapt.Pp
450279519SbaptNormally, differing binary files count as trouble because the resulting
451279519Sbapt.Xr diff
452279519Sbaptoutput does not capture all the differences. This trouble causes
453279519Sbapt.Xr diff
454279519Sbaptto exit with status 2. However, this trouble cannot occur with the
455279519Sbapt.Op -a
456279519Sbaptor
457279519Sbapt.Op --text
458279519Sbaptoption, or with the
459279519Sbapt.Op -q
460279519Sbaptor
461279519Sbapt.Op --brief
462279519Sbaptoption, as these options both cause
463279519Sbapt.Xr diff
464279519Sbaptto generate a form of output that represents differences as requested.
465279519Sbapt.Pp
466279519SbaptIn operating systems that distinguish between text and binary files,
467279519Sbapt.Xr diff
468279519Sbaptnormally reads and writes all data as text. Use the
469279519Sbapt.Op --binary
470279519Sbaptoption to force
471279519Sbapt.Xr diff
472279519Sbaptto read and write binary data instead. This option has no effect on a POSIX-compliant
473279519Sbaptsystem like GNU or traditional Unix. However, many personal computer operating
474279519Sbaptsystems represent the end of a line with a carriage return followed by a newline.
475279519SbaptOn such systems,
476279519Sbapt.Xr diff
477279519Sbaptnormally ignores these carriage returns on input and generates them at the
478279519Sbaptend of each output line, but with the
479279519Sbapt.Op --binary
480279519Sbaptoption
481279519Sbapt.Xr diff
482279519Sbapttreats each carriage return as just another input character, and does not
483279519Sbaptgenerate a carriage return at the end of each output line. This can be useful
484279519Sbaptwhen dealing with non-text files that are meant to be interchanged with POSIX-compliant
485279519Sbaptsystems.
486279519Sbapt.Pp
487279519SbaptThe
488279519Sbapt.Op --strip-trailing-cr
489279519Sbaptcauses
490279519Sbapt.Xr diff
491279519Sbaptto treat input lines that end in carriage return followed by newline as if
492279519Sbaptthey end in plain newline. This can be useful when comparing text that is
493279519Sbaptimperfectly imported from many personal computer operating systems. This option
494279519Sbaptaffects how lines are read, which in turn affects how they are compared and
495279519Sbaptoutput.
496279519Sbapt.Pp
497279519SbaptIf you want to compare two files byte by byte, you can use the
498279519Sbapt.Xr cmp
499279519Sbaptprogram with the
500279519Sbapt.Op -l
501279519Sbaptor
502279519Sbapt.Op --verbose
503279519Sbaptoption to show the values of each differing byte in the two files. With GNU
504279519Sbapt.Xr cmp ,
505279519Sbaptyou can also use the
506279519Sbapt.Op -b
507279519Sbaptor
508279519Sbapt.Op --print-bytes
509279519Sbaptoption to show the ASCII representation of those bytes.See Section
510279519Sbapt.Dq Invoking cmp ,
511279519Sbaptfor more information.
512279519Sbapt.Pp
513279519SbaptIf
514279519Sbapt.Xr diff3
515279519Sbaptthinks that any of the files it is comparing is binary (a non-text file),
516279519Sbaptit normally reports an error, because such comparisons are usually not useful.
517279519Sbapt.Xr diff3
518279519Sbaptuses the same test as
519279519Sbapt.Xr diff
520279519Sbaptto decide whether a file is binary. As with
521279519Sbapt.Xr diff ,
522279519Sbaptif the input files contain a few non-text bytes but otherwise are like text
523279519Sbaptfiles, you can force
524279519Sbapt.Xr diff3
525279519Sbaptto consider all files to be text files and compare them line by line by using
526279519Sbaptthe
527279519Sbapt.Op -a
528279519Sbaptor
529279519Sbapt.Op --text
530279519Sbaptoption.
531279519Sbapt.Pp
532279519Sbapt.Sh  Xr diff Output Formats
533279519Sbapt.Xr diff
534279519Sbapthas several mutually exclusive options for output format. The following sections
535279519Sbaptdescribe each format, illustrating how
536279519Sbapt.Xr diff
537279519Sbaptreports the differences between two sample input files.
538279519Sbapt.Pp
539279519Sbapt.Ss  Two Sample Input Files
540279519SbaptHere are two sample files that we will use in numerous examples to illustrate
541279519Sbaptthe output of
542279519Sbapt.Xr diff
543279519Sbaptand how various options can change it.
544279519Sbapt.Pp
545279519SbaptThis is the file
546279519Sbapt.Pa lao :
547279519Sbapt.Pp
548279519Sbapt.Bd -literal -offset indent
549279519SbaptThe Way that can be told of is not the eternal Way;
550279519SbaptThe name that can be named is not the eternal name.
551279519SbaptThe Nameless is the origin of Heaven and Earth;
552279519SbaptThe Named is the mother of all things.
553279519SbaptTherefore let there always be non-being,
554279519Sbapt  so we may see their subtlety,
555279519SbaptAnd let there always be being,
556279519Sbapt  so we may see their outcome.
557279519SbaptThe two are the same,
558279519SbaptBut after they are produced,
559279519Sbapt  they have different names.
560279519Sbapt.Ed
561279519Sbapt.Pp
562279519SbaptThis is the file
563279519Sbapt.Pa tzu :
564279519Sbapt.Pp
565279519Sbapt.Bd -literal -offset indent
566279519SbaptThe Nameless is the origin of Heaven and Earth;
567279519SbaptThe named is the mother of all things.
568279519Sbapt
569279519SbaptTherefore let there always be non-being,
570279519Sbapt  so we may see their subtlety,
571279519SbaptAnd let there always be being,
572279519Sbapt  so we may see their outcome.
573279519SbaptThe two are the same,
574279519SbaptBut after they are produced,
575279519Sbapt  they have different names.
576279519SbaptThey both may be called deep and profound.
577279519SbaptDeeper and more profound,
578279519SbaptThe door of all subtleties!
579279519Sbapt.Ed
580279519Sbapt.Pp
581279519SbaptIn this example, the first hunk contains just the first two lines of
582279519Sbapt.Pa lao ,
583279519Sbaptthe second hunk contains the fourth line of
584279519Sbapt.Pa lao
585279519Sbaptopposing the second and third lines of
586279519Sbapt.Pa tzu ,
587279519Sbaptand the last hunk contains just the last three lines of
588279519Sbapt.Pa tzu .
589279519Sbapt.Pp
590279519Sbapt.Ss  Showing Differences in Their Context
591279519SbaptUsually, when you are looking at the differences between files, you will also
592279519Sbaptwant to see the parts of the files near the lines that differ, to help you
593279519Sbaptunderstand exactly what has changed. These nearby parts of the files are called
594279519Sbaptthe
595279519Sbapt.Em context .
596279519Sbapt.Pp
597279519SbaptGNU
598279519Sbapt.Xr diff
599279519Sbaptprovides two output formats that show context around the differing lines:
600279519Sbapt.Em context format
601279519Sbaptand
602279519Sbapt.Em unified format .
603279519SbaptIt can optionally show in which function or section of the file the differing
604279519Sbaptlines are found.
605279519Sbapt.Pp
606279519SbaptIf you are distributing new versions of files to other people in the form
607279519Sbaptof
608279519Sbapt.Xr diff
609279519Sbaptoutput, you should use one of the output formats that show context so that
610279519Sbaptthey can apply the diffs even if they have made small changes of their own
611279519Sbaptto the files.
612279519Sbapt.Xr patch
613279519Sbaptcan apply the diffs in this case by searching in the files for the lines of
614279519Sbaptcontext around the differing lines; if those lines are actually a few lines
615279519Sbaptaway from where the diff says they are,
616279519Sbapt.Xr patch
617279519Sbaptcan adjust the line numbers accordingly and still apply the diff correctly.See Section
618279519Sbapt.Dq Imperfect ,
619279519Sbaptfor more information on using
620279519Sbapt.Xr patch
621279519Sbaptto apply imperfect diffs.
622279519Sbapt.Pp
623279519Sbapt.Em  Context Format
624279519Sbapt.Pp
625279519SbaptThe context output format shows several lines of context around the lines
626279519Sbaptthat differ. It is the standard format for distributing updates to source
627279519Sbaptcode.
628279519Sbapt.Pp
629279519SbaptTo select this output format, use the
630279519Sbapt.Op -C Va lines ,
631279519Sbapt.Op --context[= Va lines] ,
632279519Sbaptor
633279519Sbapt.Op -c
634279519Sbaptoption. The argument
635279519Sbapt.Va lines
636279519Sbaptthat some of these options take is the number of lines of context to show.
637279519SbaptIf you do not specify
638279519Sbapt.Va lines ,
639279519Sbaptit defaults to three. For proper operation,
640279519Sbapt.Xr patch
641279519Sbapttypically needs at least two lines of context.
642279519Sbapt.Pp
643279519Sbapt.No  An Example of Context Format
644279519Sbapt.Pp
645279519SbaptHere is the output of
646279519Sbapt.Li diff -c lao tzu
647279519Sbapt(see Section
648279519Sbapt.Dq Sample diff Input ,
649279519Sbaptfor the complete contents of the two files). Notice that up to three lines
650279519Sbaptthat are not different are shown around each line that is different; they
651279519Sbaptare the context lines. Also notice that the first two hunks have run together,
652279519Sbaptbecause their contents overlap.
653279519Sbapt.Pp
654279519Sbapt.Bd -literal -offset indent
655279519Sbapt*** lao	2002-02-21 23:30:39.942229878 -0800
656279519Sbapt--- tzu	2002-02-21 23:30:50.442260588 -0800
657279519Sbapt***************
658279519Sbapt*** 1,7 ****
659279519Sbapt- The Way that can be told of is not the eternal Way;
660279519Sbapt- The name that can be named is not the eternal name.
661279519Sbapt  The Nameless is the origin of Heaven and Earth;
662279519Sbapt! The Named is the mother of all things.
663279519Sbapt  Therefore let there always be non-being,
664279519Sbapt    so we may see their subtlety,
665279519Sbapt  And let there always be being,
666279519Sbapt--- 1,6 ----
667279519Sbapt  The Nameless is the origin of Heaven and Earth;
668279519Sbapt! The named is the mother of all things.
669279519Sbapt! 
670279519Sbapt  Therefore let there always be non-being,
671279519Sbapt    so we may see their subtlety,
672279519Sbapt  And let there always be being,
673279519Sbapt***************
674279519Sbapt*** 9,11 ****
675279519Sbapt--- 8,13 ----
676279519Sbapt  The two are the same,
677279519Sbapt  But after they are produced,
678279519Sbapt    they have different names.
679279519Sbapt+ They both may be called deep and profound.
680279519Sbapt+ Deeper and more profound,
681279519Sbapt+ The door of all subtleties!
682279519Sbapt.Ed
683279519Sbapt.Pp
684279519Sbapt.No  An Example of Context Format with Less Context
685279519Sbapt.Pp
686279519SbaptHere is the output of
687279519Sbapt.Li diff -C 1 lao tzu
688279519Sbapt(see Section
689279519Sbapt.Dq Sample diff Input ,
690279519Sbaptfor the complete contents of the two files). Notice that at most one context
691279519Sbaptline is reported here.
692279519Sbapt.Pp
693279519Sbapt.Bd -literal -offset indent
694279519Sbapt*** lao	2002-02-21 23:30:39.942229878 -0800
695279519Sbapt--- tzu	2002-02-21 23:30:50.442260588 -0800
696279519Sbapt***************
697279519Sbapt*** 1,5 ****
698279519Sbapt- The Way that can be told of is not the eternal Way;
699279519Sbapt- The name that can be named is not the eternal name.
700279519Sbapt  The Nameless is the origin of Heaven and Earth;
701279519Sbapt! The Named is the mother of all things.
702279519Sbapt  Therefore let there always be non-being,
703279519Sbapt--- 1,4 ----
704279519Sbapt  The Nameless is the origin of Heaven and Earth;
705279519Sbapt! The named is the mother of all things.
706279519Sbapt! 
707279519Sbapt  Therefore let there always be non-being,
708279519Sbapt***************
709279519Sbapt*** 11 ****
710279519Sbapt--- 10,13 ----
711279519Sbapt    they have different names.
712279519Sbapt+ They both may be called deep and profound.
713279519Sbapt+ Deeper and more profound,
714279519Sbapt+ The door of all subtleties!
715279519Sbapt.Ed
716279519Sbapt.Pp
717279519Sbapt.No  Detailed Description of Context Format
718279519Sbapt.Pp
719279519SbaptThe context output format starts with a two-line header, which looks like
720279519Sbaptthis:
721279519Sbapt.Pp
722279519Sbapt.Bd -literal -offset indent
723279519Sbapt*** from-file from-file-modification-time
724279519Sbapt--- to-file to-file-modification time
725279519Sbapt.Ed
726279519Sbapt.Pp
727279519SbaptThe time stamp normally looks like
728279519Sbapt.Li 2002-02-21 23:30:39.942229878 -0800
729279519Sbaptto indicate the date, time with fractional seconds, and time zone in
730279519Sbapt.Lk ftp://ftp.isi.edu/in-notes/rfc2822.txt .
731279519Sbapt(The fractional seconds are omitted on hosts that do not support fractional
732279519Sbapttime stamps.) However, a traditional time stamp like
733279519Sbapt.Li Thu Feb 21 23:30:39 2002
734279519Sbaptis used if the
735279519Sbapt.Ev LC_TIME
736279519Sbaptlocale category is either
737279519Sbapt.Li C
738279519Sbaptor
739279519Sbapt.Li POSIX .
740279519Sbapt.Pp
741279519SbaptYou can change the header's content with the
742279519Sbapt.Op --label= Va label
743279519Sbaptoption; see Alternate Names.
744279519Sbapt.Pp
745279519SbaptNext come one or more hunks of differences; each hunk shows one area where
746279519Sbaptthe files differ. Context format hunks look like this:
747279519Sbapt.Pp
748279519Sbapt.Bd -literal -offset indent
749279519Sbapt***************
750279519Sbapt*** from-file-line-numbers ****
751279519Sbapt  from-file-line
752279519Sbapt  from-file-line...
753279519Sbapt--- to-file-line-numbers ----
754279519Sbapt  to-file-line
755279519Sbapt  to-file-line...
756279519Sbapt.Ed
757279519Sbapt.Pp
758279519SbaptIf a hunk contains two or more lines, its line numbers look like
759279519Sbapt.Li  Va start, Va end .
760279519SbaptOtherwise only its end line number appears. An empty hunk is considered to
761279519Sbaptend at the line that precedes the hunk.
762279519Sbapt.Pp
763279519SbaptThe lines of context around the lines that differ start with two space characters.
764279519SbaptThe lines that differ between the two files start with one of the following
765279519Sbaptindicator characters, followed by a space character:
766279519Sbapt.Pp
767279519Sbapt.Bl -tag -width Ds
768279519Sbapt.It  !
769279519SbaptA line that is part of a group of one or more lines that changed between the
770279519Sbapttwo files. There is a corresponding group of lines marked with
771279519Sbapt.Li !
772279519Sbaptin the part of this hunk for the other file.
773279519Sbapt.Pp
774279519Sbapt.It  +
775279519SbaptAn \(lqinserted\(rq line in the second file that corresponds to nothing in the first
776279519Sbaptfile.
777279519Sbapt.Pp
778279519Sbapt.It  -
779279519SbaptA \(lqdeleted\(rq line in the first file that corresponds to nothing in the second
780279519Sbaptfile.
781279519Sbapt.El
782279519Sbapt.Pp
783279519SbaptIf all of the changes in a hunk are insertions, the lines of
784279519Sbapt.Va from-file
785279519Sbaptare omitted. If all of the changes are deletions, the lines of
786279519Sbapt.Va to-file
787279519Sbaptare omitted.
788279519Sbapt.Pp
789279519Sbapt.Em  Unified Format
790279519Sbapt.Pp
791279519SbaptThe unified output format is a variation on the context format that is more
792279519Sbaptcompact because it omits redundant context lines. To select this output format,
793279519Sbaptuse the
794279519Sbapt.Op -U Va lines ,
795279519Sbapt.Op --unified[= Va lines] ,
796279519Sbaptor
797279519Sbapt.Op -u
798279519Sbaptoption. The argument
799279519Sbapt.Va lines
800279519Sbaptis the number of lines of context to show. When it is not given, it defaults
801279519Sbaptto three.
802279519Sbapt.Pp
803279519SbaptAt present, only GNU
804279519Sbapt.Xr diff
805279519Sbaptcan produce this format and only GNU
806279519Sbapt.Xr patch
807279519Sbaptcan automatically apply diffs in this format. For proper operation,
808279519Sbapt.Xr patch
809279519Sbapttypically needs at least three lines of context.
810279519Sbapt.Pp
811279519Sbapt.No  An Example of Unified Format
812279519Sbapt.Pp
813279519SbaptHere is the output of the command
814279519Sbapt.Li diff -u lao tzu
815279519Sbapt(see Section
816279519Sbapt.Dq Sample diff Input ,
817279519Sbaptfor the complete contents of the two files):
818279519Sbapt.Pp
819279519Sbapt.Bd -literal -offset indent
820279519Sbapt--- lao	2002-02-21 23:30:39.942229878 -0800
821279519Sbapt+++ tzu	2002-02-21 23:30:50.442260588 -0800
822279519Sbapt@@ -1,7 +1,6 @@
823279519Sbapt-The Way that can be told of is not the eternal Way;
824279519Sbapt-The name that can be named is not the eternal name.
825279519Sbapt The Nameless is the origin of Heaven and Earth;
826279519Sbapt-The Named is the mother of all things.
827279519Sbapt+The named is the mother of all things.
828279519Sbapt+
829279519Sbapt Therefore let there always be non-being,
830279519Sbapt   so we may see their subtlety,
831279519Sbapt And let there always be being,
832279519Sbapt@@ -9,3 +8,6 @@
833279519Sbapt The two are the same,
834279519Sbapt But after they are produced,
835279519Sbapt   they have different names.
836279519Sbapt+They both may be called deep and profound.
837279519Sbapt+Deeper and more profound,
838279519Sbapt+The door of all subtleties!
839279519Sbapt.Ed
840279519Sbapt.Pp
841279519Sbapt.No  Detailed Description of Unified Format
842279519Sbapt.Pp
843279519SbaptThe unified output format starts with a two-line header, which looks like
844279519Sbaptthis:
845279519Sbapt.Pp
846279519Sbapt.Bd -literal -offset indent
847279519Sbapt--- from-file from-file-modification-time
848279519Sbapt+++ to-file to-file-modification-time
849279519Sbapt.Ed
850279519Sbapt.Pp
851279519SbaptThe time stamp looks like
852279519Sbapt.Li 2002-02-21 23:30:39.942229878 -0800
853279519Sbaptto indicate the date, time with fractional seconds, and time zone. The fractional
854279519Sbaptseconds are omitted on hosts that do not support fractional time stamps.
855279519Sbapt.Pp
856279519SbaptYou can change the header's content with the
857279519Sbapt.Op --label= Va label
858279519Sbaptoption; seeSee Section
859279519Sbapt.Dq Alternate Names .
860279519Sbapt.Pp
861279519SbaptNext come one or more hunks of differences; each hunk shows one area where
862279519Sbaptthe files differ. Unified format hunks look like this:
863279519Sbapt.Pp
864279519Sbapt.Bd -literal -offset indent
865279519Sbapt@@ from-file-line-numbers to-file-line-numbers @@
866279519Sbapt line-from-either-file
867279519Sbapt line-from-either-file...
868279519Sbapt.Ed
869279519Sbapt.Pp
870279519SbaptIf a hunk contains just one line, only its start line number appears. Otherwise
871279519Sbaptits line numbers look like
872279519Sbapt.Li  Va start, Va count .
873279519SbaptAn empty hunk is considered to start at the line that follows the hunk.
874279519Sbapt.Pp
875279519SbaptIf a hunk and its context contain two or more lines, its line numbers look
876279519Sbaptlike
877279519Sbapt.Li  Va start, Va count .
878279519SbaptOtherwise only its end line number appears. An empty hunk is considered to
879279519Sbaptend at the line that precedes the hunk.
880279519Sbapt.Pp
881279519SbaptThe lines common to both files begin with a space character. The lines that
882279519Sbaptactually differ between the two files have one of the following indicator
883279519Sbaptcharacters in the left print column:
884279519Sbapt.Pp
885279519Sbapt.Bl -tag -width Ds
886279519Sbapt.It  +
887279519SbaptA line was added here to the first file.
888279519Sbapt.Pp
889279519Sbapt.It  -
890279519SbaptA line was removed here from the first file.
891279519Sbapt.El
892279519Sbapt.Pp
893279519Sbapt.Em  Showing Which Sections Differences Are in
894279519Sbapt.Pp
895279519SbaptSometimes you might want to know which part of the files each change falls
896279519Sbaptin. If the files are source code, this could mean which function was changed.
897279519SbaptIf the files are documents, it could mean which chapter or appendix was changed.
898279519SbaptGNU
899279519Sbapt.Xr diff
900279519Sbaptcan show this by displaying the nearest section heading line that precedes
901279519Sbaptthe differing lines. Which lines are \(lqsection headings\(rq is determined by a regular
902279519Sbaptexpression.
903279519Sbapt.Pp
904279519Sbapt.No  Showing Lines That Match Regular Expressions
905279519Sbapt.Pp
906279519SbaptTo show in which sections differences occur for files that are not source
907279519Sbaptcode for C or similar languages, use the
908279519Sbapt.Op -F Va regexp
909279519Sbaptor
910279519Sbapt.Op --show-function-line= Va regexp
911279519Sbaptoption.
912279519Sbapt.Xr diff
913279519Sbaptconsiders lines that match the
914279519Sbapt.Xr grep
915279519Sbapt-style regular expression
916279519Sbapt.Va regexp
917279519Sbaptto be the beginning of a section of the file. Here are suggested regular expressions
918279519Sbaptfor some common languages:
919279519Sbapt.Pp
920279519Sbapt.Bl -tag -width Ds
921279519Sbapt.It  ^[[:alpha:]$_]
922279519SbaptC, C++, Prolog
923279519Sbapt.It  ^(
924279519SbaptLisp
925279519Sbapt.It  ^@node
926279519SbaptTexinfo
927279519Sbapt.El
928279519Sbapt.Pp
929279519SbaptThis option does not automatically select an output format; in order to use
930279519Sbaptit, you must select the context format (see Section
931279519Sbapt.Dq Context Format )
932279519Sbaptor unified format (see Section
933279519Sbapt.Dq Unified Format ) .
934279519SbaptIn other output formats it has no effect.
935279519Sbapt.Pp
936279519SbaptThe
937279519Sbapt.Op -F
938279519Sbaptor
939279519Sbapt.Op --show-function-line
940279519Sbaptoption finds the nearest unchanged line that precedes each hunk of differences
941279519Sbaptand matches the given regular expression. Then it adds that line to the end
942279519Sbaptof the line of asterisks in the context format, or to the
943279519Sbapt.Li @@
944279519Sbaptline in unified format. If no matching line exists, this option leaves the
945279519Sbaptoutput for that hunk unchanged. If that line is more than 40 characters long,
946279519Sbaptit outputs only the first 40 characters. You can specify more than one regular
947279519Sbaptexpression for such lines;
948279519Sbapt.Xr diff
949279519Sbapttries to match each line against each regular expression, starting with the
950279519Sbaptlast one given. This means that you can use
951279519Sbapt.Op -p
952279519Sbaptand
953279519Sbapt.Op -F
954279519Sbapttogether, if you wish.
955279519Sbapt.Pp
956279519Sbapt.No  Showing C Function Headings
957279519Sbapt.Pp
958279519SbaptTo show in which functions differences occur for C and similar languages,
959279519Sbaptyou can use the
960279519Sbapt.Op -p
961279519Sbaptor
962279519Sbapt.Op --show-c-function
963279519Sbaptoption. This option automatically defaults to the context output format (see Section
964279519Sbapt.Dq Context Format ) ,
965279519Sbaptwith the default number of lines of context. You can override that number
966279519Sbaptwith
967279519Sbapt.Op -C Va lines
968279519Sbaptelsewhere in the command line. You can override both the format and the number
969279519Sbaptwith
970279519Sbapt.Op -U Va lines
971279519Sbaptelsewhere in the command line.
972279519Sbapt.Pp
973279519SbaptThe
974279519Sbapt.Op -p
975279519Sbaptor
976279519Sbapt.Op --show-c-function
977279519Sbaptoption is equivalent to
978279519Sbapt.Op -F '^[[:alpha:]$_]'
979279519Sbaptif the unified format is specified, otherwise
980279519Sbapt.Op -c -F '^[[:alpha:]$_]'
981279519Sbapt(see Section
982279519Sbapt.Dq Specified Headings ) .
983279519SbaptGNU
984279519Sbapt.Xr diff
985279519Sbaptprovides this option for the sake of convenience.
986279519Sbapt.Pp
987279519Sbapt.Em  Showing Alternate File Names
988279519Sbapt.Pp
989279519SbaptIf you are comparing two files that have meaningless or uninformative names,
990279519Sbaptyou might want
991279519Sbapt.Xr diff
992279519Sbaptto show alternate names in the header of the context and unified output formats.
993279519SbaptTo do this, use the
994279519Sbapt.Op --label= Va label
995279519Sbaptoption. The first time you give this option, its argument replaces the name
996279519Sbaptand date of the first file in the header; the second time, its argument replaces
997279519Sbaptthe name and date of the second file. If you give this option more than twice,
998279519Sbapt.Xr diff
999279519Sbaptreports an error. The
1000279519Sbapt.Op --label
1001279519Sbaptoption does not affect the file names in the
1002279519Sbapt.Xr pr
1003279519Sbaptheader when the
1004279519Sbapt.Op -l
1005279519Sbaptor
1006279519Sbapt.Op --paginate
1007279519Sbaptoption is used (see Section
1008279519Sbapt.Dq Pagination ) .
1009279519Sbapt.Pp
1010279519SbaptHere are the first two lines of the output from
1011279519Sbapt.Li diff -C 2 --label=original --label=modified lao tzu :
1012279519Sbapt.Pp
1013279519Sbapt.Bd -literal -offset indent
1014279519Sbapt*** original
1015279519Sbapt--- modified
1016279519Sbapt.Ed
1017279519Sbapt.Pp
1018279519Sbapt.Ss  Showing Differences Side by Side
1019279519Sbapt.Xr diff
1020279519Sbaptcan produce a side by side difference listing of two files. The files are
1021279519Sbaptlisted in two columns with a gutter between them. The gutter contains one
1022279519Sbaptof the following markers:
1023279519Sbapt.Pp
1024279519Sbapt.Bl -tag -width Ds
1025279519Sbapt.It  white space
1026279519SbaptThe corresponding lines are in common. That is, either the lines are identical,
1027279519Sbaptor the difference is ignored because of one of the
1028279519Sbapt.Op --ignore
1029279519Sbaptoptions (see Section
1030279519Sbapt.Dq White Space ) .
1031279519Sbapt.Pp
1032279519Sbapt.It  Li |
1033279519SbaptThe corresponding lines differ, and they are either both complete or both
1034279519Sbaptincomplete.
1035279519Sbapt.Pp
1036279519Sbapt.It  Li <
1037279519SbaptThe files differ and only the first file contains the line.
1038279519Sbapt.Pp
1039279519Sbapt.It  Li >
1040279519SbaptThe files differ and only the second file contains the line.
1041279519Sbapt.Pp
1042279519Sbapt.It  Li (
1043279519SbaptOnly the first file contains the line, but the difference is ignored.
1044279519Sbapt.Pp
1045279519Sbapt.It  Li )
1046279519SbaptOnly the second file contains the line, but the difference is ignored.
1047279519Sbapt.Pp
1048279519Sbapt.It  Li \e
1049279519SbaptThe corresponding lines differ, and only the first line is incomplete.
1050279519Sbapt.Pp
1051279519Sbapt.It  Li /
1052279519SbaptThe corresponding lines differ, and only the second line is incomplete.
1053279519Sbapt.El
1054279519Sbapt.Pp
1055279519SbaptNormally, an output line is incomplete if and only if the lines that it contains
1056279519Sbaptare incomplete;See Section
1057279519Sbapt.Dq Incomplete Lines .
1058279519SbaptHowever, when an output line represents two differing lines, one might be
1059279519Sbaptincomplete while the other is not. In this case, the output line is complete,
1060279519Sbaptbut its the gutter is marked
1061279519Sbapt.Li \e
1062279519Sbaptif the first line is incomplete,
1063279519Sbapt.Li /
1064279519Sbaptif the second line is.
1065279519Sbapt.Pp
1066279519SbaptSide by side format is sometimes easiest to read, but it has limitations.
1067279519SbaptIt generates much wider output than usual, and truncates lines that are too
1068279519Sbaptlong to fit. Also, it relies on lining up output more heavily than usual,
1069279519Sbaptso its output looks particularly bad if you use varying width fonts, nonstandard
1070279519Sbapttab stops, or nonprinting characters.
1071279519Sbapt.Pp
1072279519SbaptYou can use the
1073279519Sbapt.Xr sdiff
1074279519Sbaptcommand to interactively merge side by side differences.See Section
1075279519Sbapt.Dq Interactive Merging ,
1076279519Sbaptfor more information on merging files.
1077279519Sbapt.Pp
1078279519Sbapt.Em  Controlling Side by Side Format
1079279519Sbapt.Pp
1080279519SbaptThe
1081279519Sbapt.Op -y
1082279519Sbaptor
1083279519Sbapt.Op --side-by-side
1084279519Sbaptoption selects side by side format. Because side by side output lines contain
1085279519Sbapttwo input lines, the output is wider than usual: normally 130 print columns,
1086279519Sbaptwhich can fit onto a traditional printer line. You can set the width of the
1087279519Sbaptoutput with the
1088279519Sbapt.Op -W Va columns
1089279519Sbaptor
1090279519Sbapt.Op --width= Va columns
1091279519Sbaptoption. The output is split into two halves of equal width, separated by a
1092279519Sbaptsmall gutter to mark differences; the right half is aligned to a tab stop
1093279519Sbaptso that tabs line up. Input lines that are too long to fit in half of an output
1094279519Sbaptline are truncated for output.
1095279519Sbapt.Pp
1096279519SbaptThe
1097279519Sbapt.Op --left-column
1098279519Sbaptoption prints only the left column of two common lines. The
1099279519Sbapt.Op --suppress-common-lines
1100279519Sbaptoption suppresses common lines entirely.
1101279519Sbapt.Pp
1102279519Sbapt.Em  An Example of Side by Side Format
1103279519Sbapt.Pp
1104279519SbaptHere is the output of the command
1105279519Sbapt.Li diff -y -W 72 lao tzu
1106279519Sbapt(see Section
1107279519Sbapt.Dq Sample diff Input ,
1108279519Sbaptfor the complete contents of the two files).
1109279519Sbapt.Pp
1110279519Sbapt.Bd -literal -offset indent
1111279519SbaptThe Way that can be told of is n   <
1112279519SbaptThe name that can be named is no   <
1113279519SbaptThe Nameless is the origin of He        The Nameless is the origin of He
1114279519SbaptThe Named is the mother of all t   |    The named is the mother of all t
1115279519Sbapt                                   >
1116279519SbaptTherefore let there always be no        Therefore let there always be no
1117279519Sbapt  so we may see their subtlety,           so we may see their subtlety,
1118279519SbaptAnd let there always be being,          And let there always be being,
1119279519Sbapt  so we may see their outcome.            so we may see their outcome.
1120279519SbaptThe two are the same,                   The two are the same,
1121279519SbaptBut after they are produced,            But after they are produced,
1122279519Sbapt  they have different names.              they have different names.
1123279519Sbapt                                   >    They both may be called deep and
1124279519Sbapt                                   >    Deeper and more profound,
1125279519Sbapt                                   >    The door of all subtleties!
1126279519Sbapt.Ed
1127279519Sbapt.Pp
1128279519Sbapt.Ss  Showing Differences Without Context
1129279519SbaptThe \(lqnormal\(rq
1130279519Sbapt.Xr diff
1131279519Sbaptoutput format shows each hunk of differences without any surrounding context.
1132279519SbaptSometimes such output is the clearest way to see how lines have changed, without
1133279519Sbaptthe clutter of nearby unchanged lines (although you can get similar results
1134279519Sbaptwith the context or unified formats by using 0 lines of context). However,
1135279519Sbaptthis format is no longer widely used for sending out patches; for that purpose,
1136279519Sbaptthe context format (see Section
1137279519Sbapt.Dq Context Format )
1138279519Sbaptand the unified format (see Section
1139279519Sbapt.Dq Unified Format )
1140279519Sbaptare superior. Normal format is the default for compatibility with older versions
1141279519Sbaptof
1142279519Sbapt.Xr diff
1143279519Sbaptand the POSIX standard. Use the
1144279519Sbapt.Op --normal
1145279519Sbaptoption to select this output format explicitly.
1146279519Sbapt.Pp
1147279519Sbapt.Em  An Example of Normal Format
1148279519Sbapt.Pp
1149279519SbaptHere is the output of the command
1150279519Sbapt.Li diff lao tzu
1151279519Sbapt(see Section
1152279519Sbapt.Dq Sample diff Input ,
1153279519Sbaptfor the complete contents of the two files). Notice that it shows only the
1154279519Sbaptlines that are different between the two files.
1155279519Sbapt.Pp
1156279519Sbapt.Bd -literal -offset indent
1157279519Sbapt1,2d0
1158279519Sbapt< The Way that can be told of is not the eternal Way;
1159279519Sbapt< The name that can be named is not the eternal name.
1160279519Sbapt4c2,3
1161279519Sbapt< The Named is the mother of all things.
1162279519Sbapt---
1163279519Sbapt> The named is the mother of all things.
1164279519Sbapt> 
1165279519Sbapt11a11,13
1166279519Sbapt> They both may be called deep and profound.
1167279519Sbapt> Deeper and more profound,
1168279519Sbapt> The door of all subtleties!
1169279519Sbapt.Ed
1170279519Sbapt.Pp
1171279519Sbapt.Em  Detailed Description of Normal Format
1172279519Sbapt.Pp
1173279519SbaptThe normal output format consists of one or more hunks of differences; each
1174279519Sbapthunk shows one area where the files differ. Normal format hunks look like
1175279519Sbaptthis:
1176279519Sbapt.Pp
1177279519Sbapt.Bd -literal -offset indent
1178279519Sbaptchange-command
1179279519Sbapt< from-file-line
1180279519Sbapt< from-file-line...
1181279519Sbapt---
1182279519Sbapt> to-file-line
1183279519Sbapt> to-file-line...
1184279519Sbapt.Ed
1185279519Sbapt.Pp
1186279519SbaptThere are three types of change commands. Each consists of a line number or
1187279519Sbaptcomma-separated range of lines in the first file, a single character indicating
1188279519Sbaptthe kind of change to make, and a line number or comma-separated range of
1189279519Sbaptlines in the second file. All line numbers are the original line numbers in
1190279519Sbapteach file. The types of change commands are:
1191279519Sbapt.Pp
1192279519Sbapt.Bl -tag -width Ds
1193279519Sbapt.It  Va la Va r
1194279519SbaptAdd the lines in range
1195279519Sbapt.Va r
1196279519Sbaptof the second file after line
1197279519Sbapt.Va l
1198279519Sbaptof the first file. For example,
1199279519Sbapt.Li 8a12,15
1200279519Sbaptmeans append lines 12--15 of file 2 after line 8 of file 1; or, if changing
1201279519Sbaptfile 2 into file 1, delete lines 12--15 of file 2.
1202279519Sbapt.Pp
1203279519Sbapt.It  Va fc Va t
1204279519SbaptReplace the lines in range
1205279519Sbapt.Va f
1206279519Sbaptof the first file with lines in range
1207279519Sbapt.Va t
1208279519Sbaptof the second file. This is like a combined add and delete, but more compact.
1209279519SbaptFor example,
1210279519Sbapt.Li 5,7c8,10
1211279519Sbaptmeans change lines 5--7 of file 1 to read as lines 8--10 of file 2; or, if
1212279519Sbaptchanging file 2 into file 1, change lines 8--10 of file 2 to read as lines
1213279519Sbapt5--7 of file 1.
1214279519Sbapt.Pp
1215279519Sbapt.It  Va rd Va l
1216279519SbaptDelete the lines in range
1217279519Sbapt.Va r
1218279519Sbaptfrom the first file; line
1219279519Sbapt.Va l
1220279519Sbaptis where they would have appeared in the second file had they not been deleted.
1221279519SbaptFor example,
1222279519Sbapt.Li 5,7d3
1223279519Sbaptmeans delete lines 5--7 of file 1; or, if changing file 2 into file 1, append
1224279519Sbaptlines 5--7 of file 1 after line 3 of file 2.
1225279519Sbapt.El
1226279519Sbapt.Pp
1227279519Sbapt.Ss  Making Edit Scripts
1228279519SbaptSeveral output modes produce command scripts for editing
1229279519Sbapt.Va from-file
1230279519Sbaptto produce
1231279519Sbapt.Va to-file .
1232279519Sbapt.Pp
1233279519Sbapt.Em  Xr ed Scripts
1234279519Sbapt.Pp
1235279519Sbapt.Xr diff
1236279519Sbaptcan produce commands that direct the
1237279519Sbapt.Xr ed
1238279519Sbapttext editor to change the first file into the second file. Long ago, this
1239279519Sbaptwas the only output mode that was suitable for editing one file into another
1240279519Sbaptautomatically; today, with
1241279519Sbapt.Xr patch ,
1242279519Sbaptit is almost obsolete. Use the
1243279519Sbapt.Op -e
1244279519Sbaptor
1245279519Sbapt.Op --ed
1246279519Sbaptoption to select this output format.
1247279519Sbapt.Pp
1248279519SbaptLike the normal format (see Section
1249279519Sbapt.Dq Normal ) ,
1250279519Sbaptthis output format does not show any context; unlike the normal format, it
1251279519Sbaptdoes not include the information necessary to apply the diff in reverse (to
1252279519Sbaptproduce the first file if all you have is the second file and the diff).
1253279519Sbapt.Pp
1254279519SbaptIf the file
1255279519Sbapt.Pa d
1256279519Sbaptcontains the output of
1257279519Sbapt.Li diff -e old new ,
1258279519Sbaptthen the command
1259279519Sbapt.Li (cat d && echo w) | ed - old
1260279519Sbaptedits
1261279519Sbapt.Pa old
1262279519Sbaptto make it a copy of
1263279519Sbapt.Pa new .
1264279519SbaptMore generally, if
1265279519Sbapt.Pa d1 ,
1266279519Sbapt.Pa d2 ,
1267279519Sbapt\&...,
1268279519Sbapt.Pa dN
1269279519Sbaptcontain the outputs of
1270279519Sbapt.Li diff -e old new1 ,
1271279519Sbapt.Li diff -e new1 new2 ,
1272279519Sbapt\&...,
1273279519Sbapt.Li diff -e newN-1 newN ,
1274279519Sbaptrespectively, then the command
1275279519Sbapt.Li (cat d1 d2 ... dN && echo w) | ed - old
1276279519Sbaptedits
1277279519Sbapt.Pa old
1278279519Sbaptto make it a copy of
1279279519Sbapt.Pa newN .
1280279519Sbapt.Pp
1281279519Sbapt.No  Example Xr ed Script
1282279519Sbapt.Pp
1283279519SbaptHere is the output of
1284279519Sbapt.Li diff -e lao tzu
1285279519Sbapt(see Section
1286279519Sbapt.Dq Sample diff Input ,
1287279519Sbaptfor the complete contents of the two files):
1288279519Sbapt.Pp
1289279519Sbapt.Bd -literal -offset indent
1290279519Sbapt11a
1291279519SbaptThey both may be called deep and profound.
1292279519SbaptDeeper and more profound,
1293279519SbaptThe door of all subtleties!
1294279519Sbapt\&.
1295279519Sbapt4c
1296279519SbaptThe named is the mother of all things.
1297279519Sbapt
1298279519Sbapt\&.
1299279519Sbapt1,2d
1300279519Sbapt.Ed
1301279519Sbapt.Pp
1302279519Sbapt.No  Detailed Description of Xr ed Format
1303279519Sbapt.Pp
1304279519SbaptThe
1305279519Sbapt.Xr ed
1306279519Sbaptoutput format consists of one or more hunks of differences. The changes closest
1307279519Sbaptto the ends of the files come first so that commands that change the number
1308279519Sbaptof lines do not affect how
1309279519Sbapt.Xr ed
1310279519Sbaptinterprets line numbers in succeeding commands.
1311279519Sbapt.Xr ed
1312279519Sbaptformat hunks look like this:
1313279519Sbapt.Pp
1314279519Sbapt.Bd -literal -offset indent
1315279519Sbaptchange-command
1316279519Sbaptto-file-line
1317279519Sbaptto-file-line...
1318279519Sbapt\&.
1319279519Sbapt.Ed
1320279519Sbapt.Pp
1321279519SbaptBecause
1322279519Sbapt.Xr ed
1323279519Sbaptuses a single period on a line to indicate the end of input, GNU
1324279519Sbapt.Xr diff
1325279519Sbaptprotects lines of changes that contain a single period on a line by writing
1326279519Sbapttwo periods instead, then writing a subsequent
1327279519Sbapt.Xr ed
1328279519Sbaptcommand to change the two periods into one. The
1329279519Sbapt.Xr ed
1330279519Sbaptformat cannot represent an incomplete line, so if the second file ends in
1331279519Sbapta changed incomplete line,
1332279519Sbapt.Xr diff
1333279519Sbaptreports an error and then pretends that a newline was appended.
1334279519Sbapt.Pp
1335279519SbaptThere are three types of change commands. Each consists of a line number or
1336279519Sbaptcomma-separated range of lines in the first file and a single character indicating
1337279519Sbaptthe kind of change to make. All line numbers are the original line numbers
1338279519Sbaptin the file. The types of change commands are:
1339279519Sbapt.Pp
1340279519Sbapt.Bl -tag -width Ds
1341279519Sbapt.It  Va la
1342279519SbaptAdd text from the second file after line
1343279519Sbapt.Va l
1344279519Sbaptin the first file. For example,
1345279519Sbapt.Li 8a
1346279519Sbaptmeans to add the following lines after line 8 of file 1.
1347279519Sbapt.Pp
1348279519Sbapt.It  Va rc
1349279519SbaptReplace the lines in range
1350279519Sbapt.Va r
1351279519Sbaptin the first file with the following lines. Like a combined add and delete,
1352279519Sbaptbut more compact. For example,
1353279519Sbapt.Li 5,7c
1354279519Sbaptmeans change lines 5--7 of file 1 to read as the text file 2.
1355279519Sbapt.Pp
1356279519Sbapt.It  Va rd
1357279519SbaptDelete the lines in range
1358279519Sbapt.Va r
1359279519Sbaptfrom the first file. For example,
1360279519Sbapt.Li 5,7d
1361279519Sbaptmeans delete lines 5--7 of file 1.
1362279519Sbapt.El
1363279519Sbapt.Pp
1364279519Sbapt.Em  Forward Xr ed Scripts
1365279519Sbapt.Pp
1366279519Sbapt.Xr diff
1367279519Sbaptcan produce output that is like an
1368279519Sbapt.Xr ed
1369279519Sbaptscript, but with hunks in forward (front to back) order. The format of the
1370279519Sbaptcommands is also changed slightly: command characters precede the lines they
1371279519Sbaptmodify, spaces separate line numbers in ranges, and no attempt is made to
1372279519Sbaptdisambiguate hunk lines consisting of a single period. Like
1373279519Sbapt.Xr ed
1374279519Sbaptformat, forward
1375279519Sbapt.Xr ed
1376279519Sbaptformat cannot represent incomplete lines.
1377279519Sbapt.Pp
1378279519SbaptForward
1379279519Sbapt.Xr ed
1380279519Sbaptformat is not very useful, because neither
1381279519Sbapt.Xr ed
1382279519Sbaptnor
1383279519Sbapt.Xr patch
1384279519Sbaptcan apply diffs in this format. It exists mainly for compatibility with older
1385279519Sbaptversions of
1386279519Sbapt.Xr diff .
1387279519SbaptUse the
1388279519Sbapt.Op -f
1389279519Sbaptor
1390279519Sbapt.Op --forward-ed
1391279519Sbaptoption to select it.
1392279519Sbapt.Pp
1393279519Sbapt.Em  RCS Scripts
1394279519Sbapt.Pp
1395279519SbaptThe RCS output format is designed specifically for use by the Revision Control
1396279519SbaptSystem, which is a set of free programs used for organizing different versions
1397279519Sbaptand systems of files. Use the
1398279519Sbapt.Op -n
1399279519Sbaptor
1400279519Sbapt.Op --rcs
1401279519Sbaptoption to select this output format. It is like the forward
1402279519Sbapt.Xr ed
1403279519Sbaptformat (see Section
1404279519Sbapt.Dq Forward ed ) ,
1405279519Sbaptbut it can represent arbitrary changes to the contents of a file because it
1406279519Sbaptavoids the forward
1407279519Sbapt.Xr ed
1408279519Sbaptformat's problems with lines consisting of a single period and with incomplete
1409279519Sbaptlines. Instead of ending text sections with a line consisting of a single
1410279519Sbaptperiod, each command specifies the number of lines it affects; a combination
1411279519Sbaptof the
1412279519Sbapt.Li a
1413279519Sbaptand
1414279519Sbapt.Li d
1415279519Sbaptcommands are used instead of
1416279519Sbapt.Li c .
1417279519SbaptAlso, if the second file ends in a changed incomplete line, then the output
1418279519Sbaptalso ends in an incomplete line.
1419279519Sbapt.Pp
1420279519SbaptHere is the output of
1421279519Sbapt.Li diff -n lao tzu
1422279519Sbapt(see Section
1423279519Sbapt.Dq Sample diff Input ,
1424279519Sbaptfor the complete contents of the two files):
1425279519Sbapt.Pp
1426279519Sbapt.Bd -literal -offset indent
1427279519Sbaptd1 2
1428279519Sbaptd4 1
1429279519Sbapta4 2
1430279519SbaptThe named is the mother of all things.
1431279519Sbapt
1432279519Sbapta11 3
1433279519SbaptThey both may be called deep and profound.
1434279519SbaptDeeper and more profound,
1435279519SbaptThe door of all subtleties!
1436279519Sbapt.Ed
1437279519Sbapt.Pp
1438279519Sbapt.Ss  Merging Files with If-then-else
1439279519SbaptYou can use
1440279519Sbapt.Xr diff
1441279519Sbaptto merge two files of C source code. The output of
1442279519Sbapt.Xr diff
1443279519Sbaptin this format contains all the lines of both files. Lines common to both
1444279519Sbaptfiles are output just once; the differing parts are separated by the C preprocessor
1445279519Sbaptdirectives
1446279519Sbapt.Li #ifdef Va name
1447279519Sbaptor
1448279519Sbapt.Li #ifndef Va name ,
1449279519Sbapt.Li #else ,
1450279519Sbaptand
1451279519Sbapt.Li #endif .
1452279519SbaptWhen compiling the output, you select which version to use by either defining
1453279519Sbaptor leaving undefined the macro
1454279519Sbapt.Va name .
1455279519Sbapt.Pp
1456279519SbaptTo merge two files, use
1457279519Sbapt.Xr diff
1458279519Sbaptwith the
1459279519Sbapt.Op -D Va name
1460279519Sbaptor
1461279519Sbapt.Op --ifdef= Va name
1462279519Sbaptoption. The argument
1463279519Sbapt.Va name
1464279519Sbaptis the C preprocessor identifier to use in the
1465279519Sbapt.Li #ifdef
1466279519Sbaptand
1467279519Sbapt.Li #ifndef
1468279519Sbaptdirectives.
1469279519Sbapt.Pp
1470279519SbaptFor example, if you change an instance of
1471279519Sbapt.Li wait (&s)
1472279519Sbaptto
1473279519Sbapt.Li waitpid (-1, &s, 0)
1474279519Sbaptand then merge the old and new files with the
1475279519Sbapt.Op --ifdef=HAVE_WAITPID
1476279519Sbaptoption, then the affected part of your code might look like this:
1477279519Sbapt.Pp
1478279519Sbapt.Bd -literal -offset indent
1479279519Sbapt    do {
1480279519Sbapt#ifndef HAVE_WAITPID
1481279519Sbapt        if ((w = wait (&s)) < 0  &&  errno != EINTR)
1482279519Sbapt#else /* HAVE_WAITPID */
1483279519Sbapt        if ((w = waitpid (-1, &s, 0)) < 0  &&  errno != EINTR)
1484279519Sbapt#endif /* HAVE_WAITPID */
1485279519Sbapt            return w;
1486279519Sbapt    } while (w != child);
1487279519Sbapt.Ed
1488279519Sbapt.Pp
1489279519SbaptYou can specify formats for languages other than C by using line group formats
1490279519Sbaptand line formats, as described in the next sections.
1491279519Sbapt.Pp
1492279519Sbapt.Em  Line Group Formats
1493279519Sbapt.Pp
1494279519SbaptLine group formats let you specify formats suitable for many applications
1495279519Sbaptthat allow if-then-else input, including programming languages and text formatting
1496279519Sbaptlanguages. A line group format specifies the output format for a contiguous
1497279519Sbaptgroup of similar lines.
1498279519Sbapt.Pp
1499279519SbaptFor example, the following command compares the TeX files
1500279519Sbapt.Pa old
1501279519Sbaptand
1502279519Sbapt.Pa new ,
1503279519Sbaptand outputs a merged file in which old regions are surrounded by
1504279519Sbapt.Li \ebegin{em}
1505279519Sbapt-
1506279519Sbapt.Li \eend{em}
1507279519Sbaptlines, and new regions are surrounded by
1508279519Sbapt.Li \ebegin{bf}
1509279519Sbapt-
1510279519Sbapt.Li \eend{bf}
1511279519Sbaptlines.
1512279519Sbapt.Pp
1513279519Sbapt.Bd -literal -offset indent
1514279519Sbaptdiff \e
1515279519Sbapt   --old-group-format='\ebegin{em}
1516279519Sbapt%<\eend{em}
1517279519Sbapt\&' \e
1518279519Sbapt   --new-group-format='\ebegin{bf}
1519279519Sbapt%>\eend{bf}
1520279519Sbapt\&' \e
1521279519Sbapt   old new
1522279519Sbapt.Ed
1523279519Sbapt.Pp
1524279519SbaptThe following command is equivalent to the above example, but it is a little
1525279519Sbaptmore verbose, because it spells out the default line group formats.
1526279519Sbapt.Pp
1527279519Sbapt.Bd -literal -offset indent
1528279519Sbaptdiff \e
1529279519Sbapt   --old-group-format='\ebegin{em}
1530279519Sbapt%<\eend{em}
1531279519Sbapt\&' \e
1532279519Sbapt   --new-group-format='\ebegin{bf}
1533279519Sbapt%>\eend{bf}
1534279519Sbapt\&' \e
1535279519Sbapt   --unchanged-group-format='%=' \e
1536279519Sbapt   --changed-group-format='\ebegin{em}
1537279519Sbapt%<\eend{em}
1538279519Sbapt\ebegin{bf}
1539279519Sbapt%>\eend{bf}
1540279519Sbapt\&' \e
1541279519Sbapt   old new
1542279519Sbapt.Ed
1543279519Sbapt.Pp
1544279519SbaptHere is a more advanced example, which outputs a diff listing with headers
1545279519Sbaptcontaining line numbers in a \(lqplain English\(rq style.
1546279519Sbapt.Pp
1547279519Sbapt.Bd -literal -offset indent
1548279519Sbaptdiff \e
1549279519Sbapt   --unchanged-group-format=\(rq \e
1550279519Sbapt   --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
1551279519Sbapt%<' \e
1552279519Sbapt   --new-group-format='-------- %dN line%(N=1?:s) added after %de:
1553279519Sbapt%>' \e
1554279519Sbapt   --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
1555279519Sbapt%<-------- to:
1556279519Sbapt%>' \e
1557279519Sbapt   old new
1558279519Sbapt.Ed
1559279519Sbapt.Pp
1560279519SbaptTo specify a line group format, use
1561279519Sbapt.Xr diff
1562279519Sbaptwith one of the options listed below. You can specify up to four line group
1563279519Sbaptformats, one for each kind of line group. You should quote
1564279519Sbapt.Va format ,
1565279519Sbaptbecause it typically contains shell metacharacters.
1566279519Sbapt.Pp
1567279519Sbapt.Bl -tag -width Ds
1568279519Sbapt.It  --old-group-format= Va format
1569279519SbaptThese line groups are hunks containing only lines from the first file. The
1570279519Sbaptdefault old group format is the same as the changed group format if it is
1571279519Sbaptspecified; otherwise it is a format that outputs the line group as-is.
1572279519Sbapt.Pp
1573279519Sbapt.It  --new-group-format= Va format
1574279519SbaptThese line groups are hunks containing only lines from the second file. The
1575279519Sbaptdefault new group format is same as the changed group format if it is specified;
1576279519Sbaptotherwise it is a format that outputs the line group as-is.
1577279519Sbapt.Pp
1578279519Sbapt.It  --changed-group-format= Va format
1579279519SbaptThese line groups are hunks containing lines from both files. The default
1580279519Sbaptchanged group format is the concatenation of the old and new group formats.
1581279519Sbapt.Pp
1582279519Sbapt.It  --unchanged-group-format= Va format
1583279519SbaptThese line groups contain lines common to both files. The default unchanged
1584279519Sbaptgroup format is a format that outputs the line group as-is.
1585279519Sbapt.El
1586279519Sbapt.Pp
1587279519SbaptIn a line group format, ordinary characters represent themselves; conversion
1588279519Sbaptspecifications start with
1589279519Sbapt.Li %
1590279519Sbaptand have one of the following forms.
1591279519Sbapt.Pp
1592279519Sbapt.Bl -tag -width Ds
1593279519Sbapt.It  %<
1594279519Sbaptstands for the lines from the first file, including the trailing newline.
1595279519SbaptEach line is formatted according to the old line format (see Section
1596279519Sbapt.Dq Line Formats ) .
1597279519Sbapt.Pp
1598279519Sbapt.It  %>
1599279519Sbaptstands for the lines from the second file, including the trailing newline.
1600279519SbaptEach line is formatted according to the new line format.
1601279519Sbapt.Pp
1602279519Sbapt.It  %=
1603279519Sbaptstands for the lines common to both files, including the trailing newline.
1604279519SbaptEach line is formatted according to the unchanged line format.
1605279519Sbapt.Pp
1606279519Sbapt.It  %%
1607279519Sbaptstands for
1608279519Sbapt.Li % .
1609279519Sbapt.Pp
1610279519Sbapt.It  %c' Va C'
1611279519Sbaptwhere
1612279519Sbapt.Va C
1613279519Sbaptis a single character, stands for
1614279519Sbapt.Va C .
1615279519Sbapt.Va C
1616279519Sbaptmay not be a backslash or an apostrophe. For example,
1617279519Sbapt.Li %c':'
1618279519Sbaptstands for a colon, even inside the then-part of an if-then-else format, which
1619279519Sbapta colon would normally terminate.
1620279519Sbapt.Pp
1621279519Sbapt.It  %c'\e Va O'
1622279519Sbaptwhere
1623279519Sbapt.Va O
1624279519Sbaptis a string of 1, 2, or 3 octal digits, stands for the character with octal
1625279519Sbaptcode
1626279519Sbapt.Va O .
1627279519SbaptFor example,
1628279519Sbapt.Li %c'\e0'
1629279519Sbaptstands for a null character.
1630279519Sbapt.Pp
1631279519Sbapt.It  Va F Va n
1632279519Sbaptwhere
1633279519Sbapt.Va F
1634279519Sbaptis a
1635279519Sbapt.Li printf
1636279519Sbaptconversion specification and
1637279519Sbapt.Va n
1638279519Sbaptis one of the following letters, stands for
1639279519Sbapt.Va n
1640279519Sbapt\&'s value formatted with
1641279519Sbapt.Va F .
1642279519Sbapt.Pp
1643279519Sbapt.Bl -tag -width Ds
1644279519Sbapt.It  e
1645279519SbaptThe line number of the line just before the group in the old file.
1646279519Sbapt.Pp
1647279519Sbapt.It  f
1648279519SbaptThe line number of the first line in the group in the old file; equals
1649279519Sbapt.Va e
1650279519Sbapt+ 1.
1651279519Sbapt.Pp
1652279519Sbapt.It  l
1653279519SbaptThe line number of the last line in the group in the old file.
1654279519Sbapt.Pp
1655279519Sbapt.It  m
1656279519SbaptThe line number of the line just after the group in the old file; equals
1657279519Sbapt.Va l
1658279519Sbapt+ 1.
1659279519Sbapt.Pp
1660279519Sbapt.It  n
1661279519SbaptThe number of lines in the group in the old file; equals
1662279519Sbapt.Va l
1663279519Sbapt-
1664279519Sbapt.Va f
1665279519Sbapt+ 1.
1666279519Sbapt.Pp
1667279519Sbapt.It  E, F, L, M, N
1668279519SbaptLikewise, for lines in the new file.
1669279519Sbapt.Pp
1670279519Sbapt.El
1671279519SbaptThe
1672279519Sbapt.Li printf
1673279519Sbaptconversion specification can be
1674279519Sbapt.Li %d ,
1675279519Sbapt.Li %o ,
1676279519Sbapt.Li %x ,
1677279519Sbaptor
1678279519Sbapt.Li %X ,
1679279519Sbaptspecifying decimal, octal, lower case hexadecimal, or upper case hexadecimal
1680279519Sbaptoutput respectively. After the
1681279519Sbapt.Li %
1682279519Sbaptthe following options can appear in sequence: a series of zero or more flags;
1683279519Sbaptan integer specifying the minimum field width; and a period followed by an
1684279519Sbaptoptional integer specifying the minimum number of digits. The flags are
1685279519Sbapt.Li -
1686279519Sbaptfor left-justification,
1687279519Sbapt.Li '
1688279519Sbaptfor separating the digit into groups as specified by the
1689279519Sbapt.Ev LC_NUMERIC
1690279519Sbaptlocale category, and
1691279519Sbapt.Li 0
1692279519Sbaptfor padding with zeros instead of spaces. For example,
1693279519Sbapt.Li %5dN
1694279519Sbaptprints the number of new lines in the group in a field of width 5 characters,
1695279519Sbaptusing the
1696279519Sbapt.Li printf
1697279519Sbaptformat
1698279519Sbapt.Li "%5d" .
1699279519Sbapt.Pp
1700279519Sbapt.It  ( Va A= Va B? Va T: Va E)
1701279519SbaptIf
1702279519Sbapt.Va A
1703279519Sbaptequals
1704279519Sbapt.Va B
1705279519Sbaptthen
1706279519Sbapt.Va T
1707279519Sbaptelse
1708279519Sbapt.Va E .
1709279519Sbapt.Va A
1710279519Sbaptand
1711279519Sbapt.Va B
1712279519Sbaptare each either a decimal constant or a single letter interpreted as above.
1713279519SbaptThis format spec is equivalent to
1714279519Sbapt.Va T
1715279519Sbaptif
1716279519Sbapt.Va A
1717279519Sbapt\&'s value equals
1718279519Sbapt.Va B
1719279519Sbapt\&'s; otherwise it is equivalent to
1720279519Sbapt.Va E .
1721279519Sbapt.Pp
1722279519SbaptFor example,
1723279519Sbapt.Li %(N=0?no:%dN) line%(N=1?:s)
1724279519Sbaptis equivalent to
1725279519Sbapt.Li no lines
1726279519Sbaptif
1727279519Sbapt.Va N
1728279519Sbapt(the number of lines in the group in the new file) is 0, to
1729279519Sbapt.Li 1 line
1730279519Sbaptif
1731279519Sbapt.Va N
1732279519Sbaptis 1, and to
1733279519Sbapt.Li %dN lines
1734279519Sbaptotherwise.
1735279519Sbapt.El
1736279519Sbapt.Pp
1737279519Sbapt.Em  Line Formats
1738279519Sbapt.Pp
1739279519SbaptLine formats control how each line taken from an input file is output as part
1740279519Sbaptof a line group in if-then-else format.
1741279519Sbapt.Pp
1742279519SbaptFor example, the following command outputs text with a one-character change
1743279519Sbaptindicator to the left of the text. The first character of output is
1744279519Sbapt.Li -
1745279519Sbaptfor deleted lines,
1746279519Sbapt.Li |
1747279519Sbaptfor added lines, and a space for unchanged lines. The formats contain newline
1748279519Sbaptcharacters where newlines are desired on output.
1749279519Sbapt.Pp
1750279519Sbapt.Bd -literal -offset indent
1751279519Sbaptdiff \e
1752279519Sbapt   --old-line-format='-%l
1753279519Sbapt\&' \e
1754279519Sbapt   --new-line-format='|%l
1755279519Sbapt\&' \e
1756279519Sbapt   --unchanged-line-format=' %l
1757279519Sbapt\&' \e
1758279519Sbapt   old new
1759279519Sbapt.Ed
1760279519Sbapt.Pp
1761279519SbaptTo specify a line format, use one of the following options. You should quote
1762279519Sbapt.Va format ,
1763279519Sbaptsince it often contains shell metacharacters.
1764279519Sbapt.Pp
1765279519Sbapt.Bl -tag -width Ds
1766279519Sbapt.It  --old-line-format= Va format
1767279519Sbaptformats lines just from the first file.
1768279519Sbapt.Pp
1769279519Sbapt.It  --new-line-format= Va format
1770279519Sbaptformats lines just from the second file.
1771279519Sbapt.Pp
1772279519Sbapt.It  --unchanged-line-format= Va format
1773279519Sbaptformats lines common to both files.
1774279519Sbapt.Pp
1775279519Sbapt.It  --line-format= Va format
1776279519Sbaptformats all lines; in effect, it sets all three above options simultaneously.
1777279519Sbapt.El
1778279519Sbapt.Pp
1779279519SbaptIn a line format, ordinary characters represent themselves; conversion specifications
1780279519Sbaptstart with
1781279519Sbapt.Li %
1782279519Sbaptand have one of the following forms.
1783279519Sbapt.Pp
1784279519Sbapt.Bl -tag -width Ds
1785279519Sbapt.It  %l
1786279519Sbaptstands for the contents of the line, not counting its trailing newline (if
1787279519Sbaptany). This format ignores whether the line is incomplete;See Section
1788279519Sbapt.Dq Incomplete Lines .
1789279519Sbapt.Pp
1790279519Sbapt.It  %L
1791279519Sbaptstands for the contents of the line, including its trailing newline (if any).
1792279519SbaptIf a line is incomplete, this format preserves its incompleteness.
1793279519Sbapt.Pp
1794279519Sbapt.It  %%
1795279519Sbaptstands for
1796279519Sbapt.Li % .
1797279519Sbapt.Pp
1798279519Sbapt.It  %c' Va C'
1799279519Sbaptwhere
1800279519Sbapt.Va C
1801279519Sbaptis a single character, stands for
1802279519Sbapt.Va C .
1803279519Sbapt.Va C
1804279519Sbaptmay not be a backslash or an apostrophe. For example,
1805279519Sbapt.Li %c':'
1806279519Sbaptstands for a colon.
1807279519Sbapt.Pp
1808279519Sbapt.It  %c'\e Va O'
1809279519Sbaptwhere
1810279519Sbapt.Va O
1811279519Sbaptis a string of 1, 2, or 3 octal digits, stands for the character with octal
1812279519Sbaptcode
1813279519Sbapt.Va O .
1814279519SbaptFor example,
1815279519Sbapt.Li %c'\e0'
1816279519Sbaptstands for a null character.
1817279519Sbapt.Pp
1818279519Sbapt.It  Va Fn
1819279519Sbaptwhere
1820279519Sbapt.Va F
1821279519Sbaptis a
1822279519Sbapt.Li printf
1823279519Sbaptconversion specification, stands for the line number formatted with
1824279519Sbapt.Va F .
1825279519SbaptFor example,
1826279519Sbapt.Li %.5dn
1827279519Sbaptprints the line number using the
1828279519Sbapt.Li printf
1829279519Sbaptformat
1830279519Sbapt.Li "%.5d" .
1831279519SbaptSee Section.Dq Line Group Formats ,
1832279519Sbaptfor more about printf conversion specifications.
1833279519Sbapt.Pp
1834279519Sbapt.El
1835279519SbaptThe default line format is
1836279519Sbapt.Li %l
1837279519Sbaptfollowed by a newline character.
1838279519Sbapt.Pp
1839279519SbaptIf the input contains tab characters and it is important that they line up
1840279519Sbapton output, you should ensure that
1841279519Sbapt.Li %l
1842279519Sbaptor
1843279519Sbapt.Li %L
1844279519Sbaptin a line format is just after a tab stop (e.g. by preceding
1845279519Sbapt.Li %l
1846279519Sbaptor
1847279519Sbapt.Li %L
1848279519Sbaptwith a tab character), or you should use the
1849279519Sbapt.Op -t
1850279519Sbaptor
1851279519Sbapt.Op --expand-tabs
1852279519Sbaptoption.
1853279519Sbapt.Pp
1854279519SbaptTaken together, the line and line group formats let you specify many different
1855279519Sbaptformats. For example, the following command uses a format similar to normal
1856279519Sbapt.Xr diff
1857279519Sbaptformat. You can tailor this command to get fine control over
1858279519Sbapt.Xr diff
1859279519Sbaptoutput.
1860279519Sbapt.Pp
1861279519Sbapt.Bd -literal -offset indent
1862279519Sbaptdiff \e
1863279519Sbapt   --old-line-format='< %l
1864279519Sbapt\&' \e
1865279519Sbapt   --new-line-format='> %l
1866279519Sbapt\&' \e
1867279519Sbapt   --old-group-format='%df%(f=l?:,%dl)d%dE
1868279519Sbapt%<' \e
1869279519Sbapt   --new-group-format='%dea%dF%(F=L?:,%dL)
1870279519Sbapt%>' \e
1871279519Sbapt   --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)
1872279519Sbapt%<---
1873279519Sbapt%>' \e
1874279519Sbapt   --unchanged-group-format=\(rq \e
1875279519Sbapt   old new
1876279519Sbapt.Ed
1877279519Sbapt.Pp
1878279519Sbapt.Em  An Example of If-then-else Format
1879279519Sbapt.Pp
1880279519SbaptHere is the output of
1881279519Sbapt.Li diff -DTWO lao tzu
1882279519Sbapt(see Section
1883279519Sbapt.Dq Sample diff Input ,
1884279519Sbaptfor the complete contents of the two files):
1885279519Sbapt.Pp
1886279519Sbapt.Bd -literal -offset indent
1887279519Sbapt#ifndef TWO
1888279519SbaptThe Way that can be told of is not the eternal Way;
1889279519SbaptThe name that can be named is not the eternal name.
1890279519Sbapt#endif /* ! TWO */
1891279519SbaptThe Nameless is the origin of Heaven and Earth;
1892279519Sbapt#ifndef TWO
1893279519SbaptThe Named is the mother of all things.
1894279519Sbapt#else /* TWO */
1895279519SbaptThe named is the mother of all things.
1896279519Sbapt
1897279519Sbapt#endif /* TWO */
1898279519SbaptTherefore let there always be non-being,
1899279519Sbapt  so we may see their subtlety,
1900279519SbaptAnd let there always be being,
1901279519Sbapt  so we may see their outcome.
1902279519SbaptThe two are the same,
1903279519SbaptBut after they are produced,
1904279519Sbapt  they have different names.
1905279519Sbapt#ifdef TWO
1906279519SbaptThey both may be called deep and profound.
1907279519SbaptDeeper and more profound,
1908279519SbaptThe door of all subtleties!
1909279519Sbapt#endif /* TWO */
1910279519Sbapt.Ed
1911279519Sbapt.Pp
1912279519Sbapt.Em  Detailed Description of If-then-else Format
1913279519Sbapt.Pp
1914279519SbaptFor lines common to both files,
1915279519Sbapt.Xr diff
1916279519Sbaptuses the unchanged line group format. For each hunk of differences in the
1917279519Sbaptmerged output format, if the hunk contains only lines from the first file,
1918279519Sbapt.Xr diff
1919279519Sbaptuses the old line group format; if the hunk contains only lines from the second
1920279519Sbaptfile,
1921279519Sbapt.Xr diff
1922279519Sbaptuses the new group format; otherwise,
1923279519Sbapt.Xr diff
1924279519Sbaptuses the changed group format.
1925279519Sbapt.Pp
1926279519SbaptThe old, new, and unchanged line formats specify the output format of lines
1927279519Sbaptfrom the first file, lines from the second file, and lines common to both
1928279519Sbaptfiles, respectively.
1929279519Sbapt.Pp
1930279519SbaptThe option
1931279519Sbapt.Op --ifdef= Va name
1932279519Sbaptis equivalent to the following sequence of options using shell syntax:
1933279519Sbapt.Pp
1934279519Sbapt.Bd -literal -offset indent
1935279519Sbapt--old-group-format='#ifndef name
1936279519Sbapt%<#endif /* ! name */
1937279519Sbapt\&' \e
1938279519Sbapt--new-group-format='#ifdef name
1939279519Sbapt%>#endif /* name */
1940279519Sbapt\&' \e
1941279519Sbapt--unchanged-group-format='%=' \e
1942279519Sbapt--changed-group-format='#ifndef name
1943279519Sbapt%<#else /* name */
1944279519Sbapt%>#endif /* name */
1945279519Sbapt\&'
1946279519Sbapt.Ed
1947279519Sbapt.Pp
1948279519SbaptYou should carefully check the
1949279519Sbapt.Xr diff
1950279519Sbaptoutput for proper nesting. For example, when using the
1951279519Sbapt.Op -D Va name
1952279519Sbaptor
1953279519Sbapt.Op --ifdef= Va name
1954279519Sbaptoption, you should check that if the differing lines contain any of the C
1955279519Sbaptpreprocessor directives
1956279519Sbapt.Li #ifdef ,
1957279519Sbapt.Li #ifndef ,
1958279519Sbapt.Li #else ,
1959279519Sbapt.Li #elif ,
1960279519Sbaptor
1961279519Sbapt.Li #endif ,
1962279519Sbaptthey are nested properly and match. If they don't, you must make corrections
1963279519Sbaptmanually. It is a good idea to carefully check the resulting code anyway to
1964279519Sbaptmake sure that it really does what you want it to; depending on how the input
1965279519Sbaptfiles were produced, the output might contain duplicate or otherwise incorrect
1966279519Sbaptcode.
1967279519Sbapt.Pp
1968279519SbaptThe
1969279519Sbapt.Xr patch
1970279519Sbapt.Op -D Va name
1971279519Sbaptoption behaves like the
1972279519Sbapt.Xr diff
1973279519Sbapt.Op -D Va name
1974279519Sbaptoption, except it operates on a file and a diff to produce a merged file;See Section
1975279519Sbapt.Dq patch Options .
1976279519Sbapt.Pp
1977279519Sbapt.Sh  Incomplete Lines
1978279519SbaptWhen an input file ends in a non-newline character, its last line is called
1979279519Sbaptan
1980279519Sbapt.Em incomplete line
1981279519Sbaptbecause its last character is not a newline. All other lines are called
1982279519Sbapt.Em full lines
1983279519Sbaptand end in a newline character. Incomplete lines do not match full lines unless
1984279519Sbaptdifferences in white space are ignored (see Section
1985279519Sbapt.Dq White Space ) .
1986279519Sbapt.Pp
1987279519SbaptAn incomplete line is normally distinguished on output from a full line by
1988279519Sbapta following line that starts with
1989279519Sbapt.Li \e .
1990279519SbaptHowever, the RCS format (see Section
1991279519Sbapt.Dq RCS )
1992279519Sbaptoutputs the incomplete line as-is, without any trailing newline or following
1993279519Sbaptline. The side by side format normally represents incomplete lines as-is,
1994279519Sbaptbut in some cases uses a
1995279519Sbapt.Li \e
1996279519Sbaptor
1997279519Sbapt.Li /
1998279519Sbaptgutter marker;See Section
1999279519Sbapt.Dq Side by Side .
2000279519SbaptThe if-then-else line format preserves a line's incompleteness with
2001279519Sbapt.Li %L ,
2002279519Sbaptand discards the newline with
2003279519Sbapt.Li %l
2004279519Sbapt;See Section
2005279519Sbapt.Dq Line Formats .
2006279519SbaptFinally, with the
2007279519Sbapt.Xr ed
2008279519Sbaptand forward
2009279519Sbapt.Xr ed
2010279519Sbaptoutput formats (see Section
2011279519Sbapt.Dq Output Formats )
2012279519Sbapt.Xr diff
2013279519Sbaptcannot represent an incomplete line, so it pretends there was a newline and
2014279519Sbaptreports an error.
2015279519Sbapt.Pp
2016279519SbaptFor example, suppose
2017279519Sbapt.Pa F
2018279519Sbaptand
2019279519Sbapt.Pa G
2020279519Sbaptare one-byte files that contain just
2021279519Sbapt.Li f
2022279519Sbaptand
2023279519Sbapt.Li g ,
2024279519Sbaptrespectively. Then
2025279519Sbapt.Li diff F G
2026279519Sbaptoutputs
2027279519Sbapt.Pp
2028279519Sbapt.Bd -literal -offset indent
2029279519Sbapt1c1
2030279519Sbapt< f
2031279519Sbapt\e No newline at end of file
2032279519Sbapt---
2033279519Sbapt> g
2034279519Sbapt\e No newline at end of file
2035279519Sbapt.Ed
2036279519Sbapt.Pp
2037279519Sbapt(The exact message may differ in non-English locales.)
2038279519Sbapt.Li diff -n F G
2039279519Sbaptoutputs the following without a trailing newline:
2040279519Sbapt.Pp
2041279519Sbapt.Bd -literal -offset indent
2042279519Sbaptd1 1
2043279519Sbapta1 1
2044279519Sbaptg
2045279519Sbapt.Ed
2046279519Sbapt.Pp
2047279519Sbapt.Li diff -e F G
2048279519Sbaptreports two errors and outputs the following:
2049279519Sbapt.Pp
2050279519Sbapt.Bd -literal -offset indent
2051279519Sbapt1c
2052279519Sbaptg
2053279519Sbapt\&.
2054279519Sbapt.Ed
2055279519Sbapt.Pp
2056279519Sbapt.Sh  Comparing Directories
2057279519SbaptYou can use
2058279519Sbapt.Xr diff
2059279519Sbaptto compare some or all of the files in two directory trees. When both file
2060279519Sbaptname arguments to
2061279519Sbapt.Xr diff
2062279519Sbaptare directories, it compares each file that is contained in both directories,
2063279519Sbaptexamining file names in alphabetical order as specified by the
2064279519Sbapt.Ev LC_COLLATE
2065279519Sbaptlocale category. Normally
2066279519Sbapt.Xr diff
2067279519Sbaptis silent about pairs of files that contain no differences, but if you use
2068279519Sbaptthe
2069279519Sbapt.Op -s
2070279519Sbaptor
2071279519Sbapt.Op --report-identical-files
2072279519Sbaptoption, it reports pairs of identical files. Normally
2073279519Sbapt.Xr diff
2074279519Sbaptreports subdirectories common to both directories without comparing subdirectories'
2075279519Sbaptfiles, but if you use the
2076279519Sbapt.Op -r
2077279519Sbaptor
2078279519Sbapt.Op --recursive
2079279519Sbaptoption, it compares every corresponding pair of files in the directory trees,
2080279519Sbaptas many levels deep as they go.
2081279519Sbapt.Pp
2082279519SbaptFor file names that are in only one of the directories,
2083279519Sbapt.Xr diff
2084279519Sbaptnormally does not show the contents of the file that exists; it reports only
2085279519Sbaptthat the file exists in that directory and not in the other. You can make
2086279519Sbapt.Xr diff
2087279519Sbaptact as though the file existed but was empty in the other directory, so that
2088279519Sbaptit outputs the entire contents of the file that actually exists. (It is output
2089279519Sbaptas either an insertion or a deletion, depending on whether it is in the first
2090279519Sbaptor the second directory given.) To do this, use the
2091279519Sbapt.Op -N
2092279519Sbaptor
2093279519Sbapt.Op --new-file
2094279519Sbaptoption.
2095279519Sbapt.Pp
2096279519SbaptIf the older directory contains one or more large files that are not in the
2097279519Sbaptnewer directory, you can make the patch smaller by using the
2098279519Sbapt.Op --unidirectional-new-file
2099279519Sbaptoption instead of
2100279519Sbapt.Op -N .
2101279519SbaptThis option is like
2102279519Sbapt.Op -N
2103279519Sbaptexcept that it only inserts the contents of files that appear in the second
2104279519Sbaptdirectory but not the first (that is, files that were added). At the top of
2105279519Sbaptthe patch, write instructions for the user applying the patch to remove the
2106279519Sbaptfiles that were deleted before applying the patch.See Section
2107279519Sbapt.Dq Making Patches ,
2108279519Sbaptfor more discussion of making patches for distribution.
2109279519Sbapt.Pp
2110279519SbaptTo ignore some files while comparing directories, use the
2111279519Sbapt.Op -x Va pattern
2112279519Sbaptor
2113279519Sbapt.Op --exclude= Va pattern
2114279519Sbaptoption. This option ignores any files or subdirectories whose base names match
2115279519Sbaptthe shell pattern
2116279519Sbapt.Va pattern .
2117279519SbaptUnlike in the shell, a period at the start of the base of a file name matches
2118279519Sbapta wildcard at the start of a pattern. You should enclose
2119279519Sbapt.Va pattern
2120279519Sbaptin quotes so that the shell does not expand it. For example, the option
2121279519Sbapt.Op -x '*.[ao]'
2122279519Sbaptignores any file whose name ends with
2123279519Sbapt.Li .a
2124279519Sbaptor
2125279519Sbapt.Li .o .
2126279519Sbapt.Pp
2127279519SbaptThis option accumulates if you specify it more than once. For example, using
2128279519Sbaptthe options
2129279519Sbapt.Op -x 'RCS' -x '*,v'
2130279519Sbaptignores any file or subdirectory whose base name is
2131279519Sbapt.Li RCS
2132279519Sbaptor ends with
2133279519Sbapt.Li ,v .
2134279519Sbapt.Pp
2135279519SbaptIf you need to give this option many times, you can instead put the patterns
2136279519Sbaptin a file, one pattern per line, and use the
2137279519Sbapt.Op -X Va file
2138279519Sbaptor
2139279519Sbapt.Op --exclude-from= Va file
2140279519Sbaptoption. Trailing white space and empty lines are ignored in the pattern file.
2141279519Sbapt.Pp
2142279519SbaptIf you have been comparing two directories and stopped partway through, later
2143279519Sbaptyou might want to continue where you left off. You can do this by using the
2144279519Sbapt.Op -S Va file
2145279519Sbaptor
2146279519Sbapt.Op --starting-file= Va file
2147279519Sbaptoption. This compares only the file
2148279519Sbapt.Va file
2149279519Sbaptand all alphabetically later files in the topmost directory level.
2150279519Sbapt.Pp
2151279519SbaptIf two directories differ only in that file names are lower case in one directory
2152279519Sbaptand upper case in the upper,
2153279519Sbapt.Xr diff
2154279519Sbaptnormally reports many differences because it compares file names in a case
2155279519Sbaptsensitive way. With the
2156279519Sbapt.Op --ignore-file-name-case
2157279519Sbaptoption,
2158279519Sbapt.Xr diff
2159279519Sbaptignores case differences in file names, so that for example the contents of
2160279519Sbaptthe file
2161279519Sbapt.Pa Tao
2162279519Sbaptin one directory are compared to the contents of the file
2163279519Sbapt.Pa TAO
2164279519Sbaptin the other. The
2165279519Sbapt.Op --no-ignore-file-name-case
2166279519Sbaptoption cancels the effect of the
2167279519Sbapt.Op --ignore-file-name-case
2168279519Sbaptoption, reverting to the default behavior.
2169279519Sbapt.Pp
2170279519SbaptIf an
2171279519Sbapt.Op -x Va pattern
2172279519Sbaptor
2173279519Sbapt.Op --exclude= Va pattern
2174279519Sbaptoption, or an
2175279519Sbapt.Op -X Va file
2176279519Sbaptor
2177279519Sbapt.Op --exclude-from= Va file
2178279519Sbaptoption, is specified while the
2179279519Sbapt.Op --ignore-file-name-case
2180279519Sbaptoption is in effect, case is ignored when excluding file names matching the
2181279519Sbaptspecified patterns.
2182279519Sbapt.Pp
2183279519Sbapt.Sh  Making Xr diff Output Prettier
2184279519Sbapt.Xr diff
2185279519Sbaptprovides several ways to adjust the appearance of its output. These adjustments
2186279519Sbaptcan be applied to any output format.
2187279519Sbapt.Pp
2188279519Sbapt.Ss  Preserving Tab Stop Alignment
2189279519SbaptThe lines of text in some of the
2190279519Sbapt.Xr diff
2191279519Sbaptoutput formats are preceded by one or two characters that indicate whether
2192279519Sbaptthe text is inserted, deleted, or changed. The addition of those characters
2193279519Sbaptcan cause tabs to move to the next tab stop, throwing off the alignment of
2194279519Sbaptcolumns in the line. GNU
2195279519Sbapt.Xr diff
2196279519Sbaptprovides two ways to make tab-aligned columns line up correctly.
2197279519Sbapt.Pp
2198279519SbaptThe first way is to have
2199279519Sbapt.Xr diff
2200279519Sbaptconvert all tabs into the correct number of spaces before outputting them;
2201279519Sbaptselect this method with the
2202279519Sbapt.Op -t
2203279519Sbaptor
2204279519Sbapt.Op --expand-tabs
2205279519Sbaptoption. To use this form of output with
2206279519Sbapt.Xr patch ,
2207279519Sbaptyou must give
2208279519Sbapt.Xr patch
2209279519Sbaptthe
2210279519Sbapt.Op -l
2211279519Sbaptor
2212279519Sbapt.Op --ignore-white-space
2213279519Sbaptoption (see Section
2214279519Sbapt.Dq Changed White Space ,
2215279519Sbaptfor more information).
2216279519Sbapt.Xr diff
2217279519Sbaptnormally assumes that tab stops are set every 8 print columns, but this can
2218279519Sbaptbe altered by the
2219279519Sbapt.Op --tabsize= Va columns
2220279519Sbaptoption.
2221279519Sbapt.Pp
2222279519SbaptThe other method for making tabs line up correctly is to add a tab character
2223279519Sbaptinstead of a space after the indicator character at the beginning of the line.
2224279519SbaptThis ensures that all following tab characters are in the same position relative
2225279519Sbaptto tab stops that they were in the original files, so that the output is aligned
2226279519Sbaptcorrectly. Its disadvantage is that it can make long lines too long to fit
2227279519Sbapton one line of the screen or the paper. It also does not work with the unified
2228279519Sbaptoutput format, which does not have a space character after the change type
2229279519Sbaptindicator character. Select this method with the
2230279519Sbapt.Op -T
2231279519Sbaptor
2232279519Sbapt.Op --initial-tab
2233279519Sbaptoption.
2234279519Sbapt.Pp
2235279519Sbapt.Ss  Paginating Xr diff Output
2236279519SbaptIt can be convenient to have long output page-numbered and time-stamped. The
2237279519Sbapt.Op -l
2238279519Sbaptor
2239279519Sbapt.Op --paginate
2240279519Sbaptoption does this by sending the
2241279519Sbapt.Xr diff
2242279519Sbaptoutput through the
2243279519Sbapt.Xr pr
2244279519Sbaptprogram. Here is what the page header might look like for
2245279519Sbapt.Li diff -lc lao tzu :
2246279519Sbapt.Pp
2247279519Sbapt.Bd -literal -offset indent
2248279519Sbapt2002-02-22 14:20                 diff -lc lao tzu                 Page 1
2249279519Sbapt.Ed
2250279519Sbapt.Pp
2251279519Sbapt.Sh  Xr diff Performance Tradeoffs
2252279519SbaptGNU
2253279519Sbapt.Xr diff
2254279519Sbaptruns quite efficiently; however, in some circumstances you can cause it to
2255279519Sbaptrun faster or produce a more compact set of changes.
2256279519Sbapt.Pp
2257279519SbaptOne way to improve
2258279519Sbapt.Xr diff
2259279519Sbaptperformance is to use hard or symbolic links to files instead of copies. This
2260279519Sbaptimproves performance because
2261279519Sbapt.Xr diff
2262279519Sbaptnormally does not need to read two hard or symbolic links to the same file,
2263279519Sbaptsince their contents must be identical. For example, suppose you copy a large
2264279519Sbaptdirectory hierarchy, make a few changes to the copy, and then often use
2265279519Sbapt.Li diff -r
2266279519Sbaptto compare the original to the copy. If the original files are read-only,
2267279519Sbaptyou can greatly improve performance by creating the copy using hard or symbolic
2268279519Sbaptlinks (e.g., with GNU
2269279519Sbapt.Li cp -lR
2270279519Sbaptor
2271279519Sbapt.Li cp -sR ) .
2272279519SbaptBefore editing a file in the copy for the first time, you should break the
2273279519Sbaptlink and replace it with a regular copy.
2274279519Sbapt.Pp
2275279519SbaptYou can also affect the performance of GNU
2276279519Sbapt.Xr diff
2277279519Sbaptby giving it options that change the way it compares files. Performance has
2278279519Sbaptmore than one dimension. These options improve one aspect of performance at
2279279519Sbaptthe cost of another, or they improve performance in some cases while hurting
2280279519Sbaptit in others.
2281279519Sbapt.Pp
2282279519SbaptThe way that GNU
2283279519Sbapt.Xr diff
2284279519Sbaptdetermines which lines have changed always comes up with a near-minimal set
2285279519Sbaptof differences. Usually it is good enough for practical purposes. If the
2286279519Sbapt.Xr diff
2287279519Sbaptoutput is large, you might want
2288279519Sbapt.Xr diff
2289279519Sbaptto use a modified algorithm that sometimes produces a smaller set of differences.
2290279519SbaptThe
2291279519Sbapt.Op -d
2292279519Sbaptor
2293279519Sbapt.Op --minimal
2294279519Sbaptoption does this; however, it can also cause
2295279519Sbapt.Xr diff
2296279519Sbaptto run more slowly than usual, so it is not the default behavior.
2297279519Sbapt.Pp
2298279519SbaptWhen the files you are comparing are large and have small groups of changes
2299279519Sbaptscattered throughout them, you can use the
2300279519Sbapt.Op --speed-large-files
2301279519Sbaptoption to make a different modification to the algorithm that
2302279519Sbapt.Xr diff
2303279519Sbaptuses. If the input files have a constant small density of changes, this option
2304279519Sbaptspeeds up the comparisons without changing the output. If not,
2305279519Sbapt.Xr diff
2306279519Sbaptmight produce a larger set of differences; however, the output will still
2307279519Sbaptbe correct.
2308279519Sbapt.Pp
2309279519SbaptNormally
2310279519Sbapt.Xr diff
2311279519Sbaptdiscards the prefix and suffix that is common to both files before it attempts
2312279519Sbaptto find a minimal set of differences. This makes
2313279519Sbapt.Xr diff
2314279519Sbaptrun faster, but occasionally it may produce non-minimal output. The
2315279519Sbapt.Op --horizon-lines= Va lines
2316279519Sbaptoption prevents
2317279519Sbapt.Xr diff
2318279519Sbaptfrom discarding the last
2319279519Sbapt.Va lines
2320279519Sbaptlines of the prefix and the first
2321279519Sbapt.Va lines
2322279519Sbaptlines of the suffix. This gives
2323279519Sbapt.Xr diff
2324279519Sbaptfurther opportunities to find a minimal output.
2325279519Sbapt.Pp
2326279519SbaptSuppose a run of changed lines includes a sequence of lines at one end and
2327279519Sbaptthere is an identical sequence of lines just outside the other end. The
2328279519Sbapt.Xr diff
2329279519Sbaptcommand is free to choose which identical sequence is included in the hunk.
2330279519SbaptIn this case,
2331279519Sbapt.Xr diff
2332279519Sbaptnormally shifts the hunk's boundaries when this merges adjacent hunks, or
2333279519Sbaptshifts a hunk's lines towards the end of the file. Merging hunks can make
2334279519Sbaptthe output look nicer in some cases.
2335279519Sbapt.Pp
2336279519Sbapt.Sh  Comparing Three Files
2337279519SbaptUse the program
2338279519Sbapt.Xr diff3
2339279519Sbaptto compare three files and show any differences among them. (
2340279519Sbapt.Xr diff3
2341279519Sbaptcan also merge files; see diff3 Merging).
2342279519Sbapt.Pp
2343279519SbaptThe \(lqnormal\(rq
2344279519Sbapt.Xr diff3
2345279519Sbaptoutput format shows each hunk of differences without surrounding context.
2346279519SbaptHunks are labeled depending on whether they are two-way or three-way, and
2347279519Sbaptlines are annotated by their location in the input files.
2348279519Sbapt.Pp
2349279519SbaptSee Section.Dq Invoking diff3 ,
2350279519Sbaptfor more information on how to run
2351279519Sbapt.Xr diff3 .
2352279519Sbapt.Pp
2353279519Sbapt.Ss  A Third Sample Input File
2354279519SbaptHere is a third sample file that will be used in examples to illustrate the
2355279519Sbaptoutput of
2356279519Sbapt.Xr diff3
2357279519Sbaptand how various options can change it. The first two files are the same that
2358279519Sbaptwe used for
2359279519Sbapt.Xr diff
2360279519Sbapt(see Section
2361279519Sbapt.Dq Sample diff Input ) .
2362279519SbaptThis is the third sample file, called
2363279519Sbapt.Pa tao :
2364279519Sbapt.Pp
2365279519Sbapt.Bd -literal -offset indent
2366279519SbaptThe Way that can be told of is not the eternal Way;
2367279519SbaptThe name that can be named is not the eternal name.
2368279519SbaptThe Nameless is the origin of Heaven and Earth;
2369279519SbaptThe named is the mother of all things.
2370279519Sbapt
2371279519SbaptTherefore let there always be non-being,
2372279519Sbapt  so we may see their subtlety,
2373279519SbaptAnd let there always be being,
2374279519Sbapt  so we may see their result.
2375279519SbaptThe two are the same,
2376279519SbaptBut after they are produced,
2377279519Sbapt  they have different names.
2378279519Sbapt
2379279519Sbapt  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2380279519Sbapt.Ed
2381279519Sbapt.Pp
2382279519Sbapt.Ss  An Example of Xr diff3 Normal Format
2383279519SbaptHere is the output of the command
2384279519Sbapt.Li diff3 lao tzu tao
2385279519Sbapt(see Section
2386279519Sbapt.Dq Sample diff3 Input ,
2387279519Sbaptfor the complete contents of the files). Notice that it shows only the lines
2388279519Sbaptthat are different among the three files.
2389279519Sbapt.Pp
2390279519Sbapt.Bd -literal -offset indent
2391279519Sbapt====2
2392279519Sbapt1:1,2c
2393279519Sbapt3:1,2c
2394279519Sbapt  The Way that can be told of is not the eternal Way;
2395279519Sbapt  The name that can be named is not the eternal name.
2396279519Sbapt2:0a
2397279519Sbapt====1
2398279519Sbapt1:4c
2399279519Sbapt  The Named is the mother of all things.
2400279519Sbapt2:2,3c
2401279519Sbapt3:4,5c
2402279519Sbapt  The named is the mother of all things.
2403279519Sbapt  
2404279519Sbapt====3
2405279519Sbapt1:8c
2406279519Sbapt2:7c
2407279519Sbapt    so we may see their outcome.
2408279519Sbapt3:9c
2409279519Sbapt    so we may see their result.
2410279519Sbapt====
2411279519Sbapt1:11a
2412279519Sbapt2:11,13c
2413279519Sbapt  They both may be called deep and profound.
2414279519Sbapt  Deeper and more profound,
2415279519Sbapt  The door of all subtleties!
2416279519Sbapt3:13,14c
2417279519Sbapt  
2418279519Sbapt    -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2419279519Sbapt.Ed
2420279519Sbapt.Pp
2421279519Sbapt.Ss  Detailed Description of Xr diff3 Normal Format
2422279519SbaptEach hunk begins with a line marked
2423279519Sbapt.Li ==== .
2424279519SbaptThree-way hunks have plain
2425279519Sbapt.Li ====
2426279519Sbaptlines, and two-way hunks have
2427279519Sbapt.Li 1 ,
2428279519Sbapt.Li 2 ,
2429279519Sbaptor
2430279519Sbapt.Li 3
2431279519Sbaptappended to specify which of the three input files differ in that hunk. The
2432279519Sbapthunks contain copies of two or three sets of input lines each preceded by
2433279519Sbaptone or two commands identifying where the lines came from.
2434279519Sbapt.Pp
2435279519SbaptNormally, two spaces precede each copy of an input line to distinguish it
2436279519Sbaptfrom the commands. But with the
2437279519Sbapt.Op -T
2438279519Sbaptor
2439279519Sbapt.Op --initial-tab
2440279519Sbaptoption,
2441279519Sbapt.Xr diff3
2442279519Sbaptuses a tab instead of two spaces; this lines up tabs correctly.See Section
2443279519Sbapt.Dq Tabs ,
2444279519Sbaptfor more information.
2445279519Sbapt.Pp
2446279519SbaptCommands take the following forms:
2447279519Sbapt.Pp
2448279519Sbapt.Bl -tag -width Ds
2449279519Sbapt.It  Va file: Va la
2450279519SbaptThis hunk appears after line
2451279519Sbapt.Va l
2452279519Sbaptof file
2453279519Sbapt.Va file ,
2454279519Sbaptand contains no lines in that file. To edit this file to yield the other files,
2455279519Sbaptone must append hunk lines taken from the other files. For example,
2456279519Sbapt.Li 1:11a
2457279519Sbaptmeans that the hunk follows line 11 in the first file and contains no lines
2458279519Sbaptfrom that file.
2459279519Sbapt.Pp
2460279519Sbapt.It  Va file: Va rc
2461279519SbaptThis hunk contains the lines in the range
2462279519Sbapt.Va r
2463279519Sbaptof file
2464279519Sbapt.Va file .
2465279519SbaptThe range
2466279519Sbapt.Va r
2467279519Sbaptis a comma-separated pair of line numbers, or just one number if the range
2468279519Sbaptis a singleton. To edit this file to yield the other files, one must change
2469279519Sbaptthe specified lines to be the lines taken from the other files. For example,
2470279519Sbapt.Li 2:11,13c
2471279519Sbaptmeans that the hunk contains lines 11 through 13 from the second file.
2472279519Sbapt.El
2473279519Sbapt.Pp
2474279519SbaptIf the last line in a set of input lines is incomplete (see Section
2475279519Sbapt.Dq Incomplete Lines ) ,
2476279519Sbaptit is distinguished on output from a full line by a following line that starts
2477279519Sbaptwith
2478279519Sbapt.Li \e .
2479279519Sbapt.Pp
2480279519Sbapt.Ss  Xr diff3 Hunks
2481279519SbaptGroups of lines that differ in two or three of the input files are called
2482279519Sbapt.Em diff3 hunks ,
2483279519Sbaptby analogy with
2484279519Sbapt.Xr diff
2485279519Sbapthunks (see Section
2486279519Sbapt.Dq Hunks ) .
2487279519SbaptIf all three input files differ in a
2488279519Sbapt.Xr diff3
2489279519Sbapthunk, the hunk is called a
2490279519Sbapt.Em three-way hunk
2491279519Sbapt; if just two input files differ, it is a
2492279519Sbapt.Em two-way hunk .
2493279519Sbapt.Pp
2494279519SbaptAs with
2495279519Sbapt.Xr diff ,
2496279519Sbaptseveral solutions are possible. When comparing the files
2497279519Sbapt.Li A ,
2498279519Sbapt.Li B ,
2499279519Sbaptand
2500279519Sbapt.Li C ,
2501279519Sbapt.Xr diff3
2502279519Sbaptnormally finds
2503279519Sbapt.Xr diff3
2504279519Sbapthunks by merging the two-way hunks output by the two commands
2505279519Sbapt.Li diff A B
2506279519Sbaptand
2507279519Sbapt.Li diff A C .
2508279519SbaptThis does not necessarily minimize the size of the output, but exceptions
2509279519Sbaptshould be rare.
2510279519Sbapt.Pp
2511279519SbaptFor example, suppose
2512279519Sbapt.Pa F
2513279519Sbaptcontains the three lines
2514279519Sbapt.Li a ,
2515279519Sbapt.Li b ,
2516279519Sbapt.Li f ,
2517279519Sbapt.Pa G
2518279519Sbaptcontains the lines
2519279519Sbapt.Li g ,
2520279519Sbapt.Li b ,
2521279519Sbapt.Li g ,
2522279519Sbaptand
2523279519Sbapt.Pa H
2524279519Sbaptcontains the lines
2525279519Sbapt.Li a ,
2526279519Sbapt.Li b ,
2527279519Sbapt.Li h .
2528279519Sbapt.Li diff3 F G H
2529279519Sbaptmight output the following:
2530279519Sbapt.Pp
2531279519Sbapt.Bd -literal -offset indent
2532279519Sbapt====2
2533279519Sbapt1:1c
2534279519Sbapt3:1c
2535279519Sbapt  a
2536279519Sbapt2:1c
2537279519Sbapt  g
2538279519Sbapt====
2539279519Sbapt1:3c
2540279519Sbapt  f
2541279519Sbapt2:3c
2542279519Sbapt  g
2543279519Sbapt3:3c
2544279519Sbapt  h
2545279519Sbapt.Ed
2546279519Sbapt.Pp
2547279519Sbaptbecause it found a two-way hunk containing
2548279519Sbapt.Li a
2549279519Sbaptin the first and third files and
2550279519Sbapt.Li g
2551279519Sbaptin the second file, then the single line
2552279519Sbapt.Li b
2553279519Sbaptcommon to all three files, then a three-way hunk containing the last line
2554279519Sbaptof each file.
2555279519Sbapt.Pp
2556279519Sbapt.Sh  Merging From a Common Ancestor
2557279519SbaptWhen two people have made changes to copies of the same file,
2558279519Sbapt.Xr diff3
2559279519Sbaptcan produce a merged output that contains both sets of changes together with
2560279519Sbaptwarnings about conflicts.
2561279519Sbapt.Pp
2562279519SbaptOne might imagine programs with names like
2563279519Sbapt.Xr diff4
2564279519Sbaptand
2565279519Sbapt.Xr diff5
2566279519Sbaptto compare more than three files simultaneously, but in practice the need
2567279519Sbaptrarely arises. You can use
2568279519Sbapt.Xr diff3
2569279519Sbaptto merge three or more sets of changes to a file by merging two change sets
2570279519Sbaptat a time.
2571279519Sbapt.Pp
2572279519Sbapt.Xr diff3
2573279519Sbaptcan incorporate changes from two modified versions into a common preceding
2574279519Sbaptversion. This lets you merge the sets of changes represented by the two newer
2575279519Sbaptfiles. Specify the common ancestor version as the second argument and the
2576279519Sbapttwo newer versions as the first and third arguments, like this:
2577279519Sbapt.Pp
2578279519Sbapt.Bd -literal -offset indent
2579279519Sbaptdiff3 mine older yours
2580279519Sbapt.Ed
2581279519Sbapt.Pp
2582279519SbaptYou can remember the order of the arguments by noting that they are in alphabetical
2583279519Sbaptorder.
2584279519Sbapt.Pp
2585279519SbaptYou can think of this as subtracting
2586279519Sbapt.Va older
2587279519Sbaptfrom
2588279519Sbapt.Va yours
2589279519Sbaptand adding the result to
2590279519Sbapt.Va mine ,
2591279519Sbaptor as merging into
2592279519Sbapt.Va mine
2593279519Sbaptthe changes that would turn
2594279519Sbapt.Va older
2595279519Sbaptinto
2596279519Sbapt.Va yours .
2597279519SbaptThis merging is well-defined as long as
2598279519Sbapt.Va mine
2599279519Sbaptand
2600279519Sbapt.Va older
2601279519Sbaptmatch in the neighborhood of each such change. This fails to be true when
2602279519Sbaptall three input files differ or when only
2603279519Sbapt.Va older
2604279519Sbaptdiffers; we call this a
2605279519Sbapt.Em conflict .
2606279519SbaptWhen all three input files differ, we call the conflict an
2607279519Sbapt.Em overlap .
2608279519Sbapt.Pp
2609279519Sbapt.Xr diff3
2610279519Sbaptgives you several ways to handle overlaps and conflicts. You can omit overlaps
2611279519Sbaptor conflicts, or select only overlaps, or mark conflicts with special
2612279519Sbapt.Li <<<<<<<
2613279519Sbaptand
2614279519Sbapt.Li >>>>>>>
2615279519Sbaptlines.
2616279519Sbapt.Pp
2617279519Sbapt.Xr diff3
2618279519Sbaptcan output the merge results as an
2619279519Sbapt.Xr ed
2620279519Sbaptscript that that can be applied to the first file to yield the merged output.
2621279519SbaptHowever, it is usually better to have
2622279519Sbapt.Xr diff3
2623279519Sbaptgenerate the merged output directly; this bypasses some problems with
2624279519Sbapt.Xr ed .
2625279519Sbapt.Pp
2626279519Sbapt.Ss  Selecting Which Changes to Incorporate
2627279519SbaptYou can select all unmerged changes from
2628279519Sbapt.Va older
2629279519Sbaptto
2630279519Sbapt.Va yours
2631279519Sbaptfor merging into
2632279519Sbapt.Va mine
2633279519Sbaptwith the
2634279519Sbapt.Op -e
2635279519Sbaptor
2636279519Sbapt.Op --ed
2637279519Sbaptoption. You can select only the nonoverlapping unmerged changes with
2638279519Sbapt.Op -3
2639279519Sbaptor
2640279519Sbapt.Op --easy-only ,
2641279519Sbaptand you can select only the overlapping changes with
2642279519Sbapt.Op -x
2643279519Sbaptor
2644279519Sbapt.Op --overlap-only .
2645279519Sbapt.Pp
2646279519SbaptThe
2647279519Sbapt.Op -e ,
2648279519Sbapt.Op -3
2649279519Sbaptand
2650279519Sbapt.Op -x
2651279519Sbaptoptions select only
2652279519Sbapt.Em unmerged changes ,
2653279519Sbapti.e. changes where
2654279519Sbapt.Va mine
2655279519Sbaptand
2656279519Sbapt.Va yours
2657279519Sbaptdiffer; they ignore changes from
2658279519Sbapt.Va older
2659279519Sbaptto
2660279519Sbapt.Va yours
2661279519Sbaptwhere
2662279519Sbapt.Va mine
2663279519Sbaptand
2664279519Sbapt.Va yours
2665279519Sbaptare identical, because they assume that such changes have already been merged.
2666279519SbaptIf this assumption is not a safe one, you can use the
2667279519Sbapt.Op -A
2668279519Sbaptor
2669279519Sbapt.Op --show-all
2670279519Sbaptoption (see Section
2671279519Sbapt.Dq Marking Conflicts ) .
2672279519Sbapt.Pp
2673279519SbaptHere is the output of the command
2674279519Sbapt.Xr diff3
2675279519Sbaptwith each of these three options (see Section
2676279519Sbapt.Dq Sample diff3 Input ,
2677279519Sbaptfor the complete contents of the files). Notice that
2678279519Sbapt.Op -e
2679279519Sbaptoutputs the union of the disjoint sets of changes output by
2680279519Sbapt.Op -3
2681279519Sbaptand
2682279519Sbapt.Op -x .
2683279519Sbapt.Pp
2684279519SbaptOutput of
2685279519Sbapt.Li diff3 -e lao tzu tao :
2686279519Sbapt.Bd -literal -offset indent
2687279519Sbapt11a
2688279519Sbapt
2689279519Sbapt  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2690279519Sbapt\&.
2691279519Sbapt8c
2692279519Sbapt  so we may see their result.
2693279519Sbapt\&.
2694279519Sbapt.Ed
2695279519Sbapt.Pp
2696279519SbaptOutput of
2697279519Sbapt.Li diff3 -3 lao tzu tao :
2698279519Sbapt.Bd -literal -offset indent
2699279519Sbapt8c
2700279519Sbapt  so we may see their result.
2701279519Sbapt\&.
2702279519Sbapt.Ed
2703279519Sbapt.Pp
2704279519SbaptOutput of
2705279519Sbapt.Li diff3 -x lao tzu tao :
2706279519Sbapt.Bd -literal -offset indent
2707279519Sbapt11a
2708279519Sbapt
2709279519Sbapt  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2710279519Sbapt\&.
2711279519Sbapt.Ed
2712279519Sbapt.Pp
2713279519Sbapt.Ss  Marking Conflicts
2714279519Sbapt.Xr diff3
2715279519Sbaptcan mark conflicts in the merged output by bracketing them with special marker
2716279519Sbaptlines. A conflict that comes from two files
2717279519Sbapt.Va A
2718279519Sbaptand
2719279519Sbapt.Va B
2720279519Sbaptis marked as follows:
2721279519Sbapt.Pp
2722279519Sbapt.Bd -literal -offset indent
2723279519Sbapt<<<<<<< A
2724279519Sbaptlines from A
2725279519Sbapt=======
2726279519Sbaptlines from B
2727279519Sbapt>>>>>>> B
2728279519Sbapt.Ed
2729279519Sbapt.Pp
2730279519SbaptA conflict that comes from three files
2731279519Sbapt.Va A ,
2732279519Sbapt.Va B
2733279519Sbaptand
2734279519Sbapt.Va C
2735279519Sbaptis marked as follows:
2736279519Sbapt.Pp
2737279519Sbapt.Bd -literal -offset indent
2738279519Sbapt<<<<<<< A
2739279519Sbaptlines from A
2740279519Sbapt||||||| B
2741279519Sbaptlines from B
2742279519Sbapt=======
2743279519Sbaptlines from C
2744279519Sbapt>>>>>>> C
2745279519Sbapt.Ed
2746279519Sbapt.Pp
2747279519SbaptThe
2748279519Sbapt.Op -A
2749279519Sbaptor
2750279519Sbapt.Op --show-all
2751279519Sbaptoption acts like the
2752279519Sbapt.Op -e
2753279519Sbaptoption, except that it brackets conflicts, and it outputs all changes from
2754279519Sbapt.Va older
2755279519Sbaptto
2756279519Sbapt.Va yours ,
2757279519Sbaptnot just the unmerged changes. Thus, given the sample input files (see Section
2758279519Sbapt.Dq Sample diff3 Input ) ,
2759279519Sbapt.Li diff3 -A lao tzu tao
2760279519Sbaptputs brackets around the conflict where only
2761279519Sbapt.Pa tzu
2762279519Sbaptdiffers:
2763279519Sbapt.Pp
2764279519Sbapt.Bd -literal -offset indent
2765279519Sbapt<<<<<<< tzu
2766279519Sbapt=======
2767279519SbaptThe Way that can be told of is not the eternal Way;
2768279519SbaptThe name that can be named is not the eternal name.
2769279519Sbapt>>>>>>> tao
2770279519Sbapt.Ed
2771279519Sbapt.Pp
2772279519SbaptAnd it outputs the three-way conflict as follows:
2773279519Sbapt.Pp
2774279519Sbapt.Bd -literal -offset indent
2775279519Sbapt<<<<<<< lao
2776279519Sbapt||||||| tzu
2777279519SbaptThey both may be called deep and profound.
2778279519SbaptDeeper and more profound,
2779279519SbaptThe door of all subtleties!
2780279519Sbapt=======
2781279519Sbapt
2782279519Sbapt  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2783279519Sbapt>>>>>>> tao
2784279519Sbapt.Ed
2785279519Sbapt.Pp
2786279519SbaptThe
2787279519Sbapt.Op -E
2788279519Sbaptor
2789279519Sbapt.Op --show-overlap
2790279519Sbaptoption outputs less information than the
2791279519Sbapt.Op -A
2792279519Sbaptor
2793279519Sbapt.Op --show-all
2794279519Sbaptoption, because it outputs only unmerged changes, and it never outputs the
2795279519Sbaptcontents of the second file. Thus the
2796279519Sbapt.Op -E
2797279519Sbaptoption acts like the
2798279519Sbapt.Op -e
2799279519Sbaptoption, except that it brackets the first and third files from three-way overlapping
2800279519Sbaptchanges. Similarly,
2801279519Sbapt.Op -X
2802279519Sbaptacts like
2803279519Sbapt.Op -x ,
2804279519Sbaptexcept it brackets all its (necessarily overlapping) changes. For example,
2805279519Sbaptfor the three-way overlapping change above, the
2806279519Sbapt.Op -E
2807279519Sbaptand
2808279519Sbapt.Op -X
2809279519Sbaptoptions output the following:
2810279519Sbapt.Pp
2811279519Sbapt.Bd -literal -offset indent
2812279519Sbapt<<<<<<< lao
2813279519Sbapt=======
2814279519Sbapt
2815279519Sbapt  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2816279519Sbapt>>>>>>> tao
2817279519Sbapt.Ed
2818279519Sbapt.Pp
2819279519SbaptIf you are comparing files that have meaningless or uninformative names, you
2820279519Sbaptcan use the
2821279519Sbapt.Op --label= Va label
2822279519Sbaptoption to show alternate names in the
2823279519Sbapt.Li <<<<<<< ,
2824279519Sbapt.Li |||||||
2825279519Sbaptand
2826279519Sbapt.Li >>>>>>>
2827279519Sbaptbrackets. This option can be given up to three times, once for each input
2828279519Sbaptfile. Thus
2829279519Sbapt.Li diff3 -A --label X --label Y --label Z A B C
2830279519Sbaptacts like
2831279519Sbapt.Li diff3 -A A B C ,
2832279519Sbaptexcept that the output looks like it came from files named
2833279519Sbapt.Li X ,
2834279519Sbapt.Li Y
2835279519Sbaptand
2836279519Sbapt.Li Z
2837279519Sbaptrather than from files named
2838279519Sbapt.Li A ,
2839279519Sbapt.Li B
2840279519Sbaptand
2841279519Sbapt.Li C .
2842279519Sbapt.Pp
2843279519Sbapt.Ss  Generating the Merged Output Directly
2844279519SbaptWith the
2845279519Sbapt.Op -m
2846279519Sbaptor
2847279519Sbapt.Op --merge
2848279519Sbaptoption,
2849279519Sbapt.Xr diff3
2850279519Sbaptoutputs the merged file directly. This is more efficient than using
2851279519Sbapt.Xr ed
2852279519Sbaptto generate it, and works even with non-text files that
2853279519Sbapt.Xr ed
2854279519Sbaptwould reject. If you specify
2855279519Sbapt.Op -m
2856279519Sbaptwithout an
2857279519Sbapt.Xr ed
2858279519Sbaptscript option,
2859279519Sbapt.Op -A
2860279519Sbaptis assumed.
2861279519Sbapt.Pp
2862279519SbaptFor example, the command
2863279519Sbapt.Li diff3 -m lao tzu tao
2864279519Sbapt(see Section
2865279519Sbapt.Dq Sample diff3 Input
2866279519Sbaptfor a copy of the input files) would output the following:
2867279519Sbapt.Pp
2868279519Sbapt.Bd -literal -offset indent
2869279519Sbapt<<<<<<< tzu
2870279519Sbapt=======
2871279519SbaptThe Way that can be told of is not the eternal Way;
2872279519SbaptThe name that can be named is not the eternal name.
2873279519Sbapt>>>>>>> tao
2874279519SbaptThe Nameless is the origin of Heaven and Earth;
2875279519SbaptThe Named is the mother of all things.
2876279519SbaptTherefore let there always be non-being,
2877279519Sbapt  so we may see their subtlety,
2878279519SbaptAnd let there always be being,
2879279519Sbapt  so we may see their result.
2880279519SbaptThe two are the same,
2881279519SbaptBut after they are produced,
2882279519Sbapt  they have different names.
2883279519Sbapt<<<<<<< lao
2884279519Sbapt||||||| tzu
2885279519SbaptThey both may be called deep and profound.
2886279519SbaptDeeper and more profound,
2887279519SbaptThe door of all subtleties!
2888279519Sbapt=======
2889279519Sbapt
2890279519Sbapt  -- The Way of Lao-Tzu, tr. Wing-tsit Chan
2891279519Sbapt>>>>>>> tao
2892279519Sbapt.Ed
2893279519Sbapt.Pp
2894279519Sbapt.Ss  How Xr diff3 Merges Incomplete Lines
2895279519SbaptWith
2896279519Sbapt.Op -m ,
2897279519Sbaptincomplete lines (see Section
2898279519Sbapt.Dq Incomplete Lines )
2899279519Sbaptare simply copied to the output as they are found; if the merged output ends
2900279519Sbaptin an conflict and one of the input files ends in an incomplete line, succeeding
2901279519Sbapt.Li ||||||| ,
2902279519Sbapt.Li =======
2903279519Sbaptor
2904279519Sbapt.Li >>>>>>>
2905279519Sbaptbrackets appear somewhere other than the start of a line because they are
2906279519Sbaptappended to the incomplete line.
2907279519Sbapt.Pp
2908279519SbaptWithout
2909279519Sbapt.Op -m ,
2910279519Sbaptif an
2911279519Sbapt.Xr ed
2912279519Sbaptscript option is specified and an incomplete line is found,
2913279519Sbapt.Xr diff3
2914279519Sbaptgenerates a warning and acts as if a newline had been present.
2915279519Sbapt.Pp
2916279519Sbapt.Ss  Saving the Changed File
2917279519SbaptTraditional Unix
2918279519Sbapt.Xr diff3
2919279519Sbaptgenerates an
2920279519Sbapt.Xr ed
2921279519Sbaptscript without the trailing
2922279519Sbapt.Li w
2923279519Sbaptand
2924279519Sbapt.Li q
2925279519Sbaptcommands that save the changes. System V
2926279519Sbapt.Xr diff3
2927279519Sbaptgenerates these extra commands. GNU
2928279519Sbapt.Xr diff3
2929279519Sbaptnormally behaves like traditional Unix
2930279519Sbapt.Xr diff3 ,
2931279519Sbaptbut with the
2932279519Sbapt.Op -i
2933279519Sbaptoption it behaves like System V
2934279519Sbapt.Xr diff3
2935279519Sbaptand appends the
2936279519Sbapt.Li w
2937279519Sbaptand
2938279519Sbapt.Li q
2939279519Sbaptcommands.
2940279519Sbapt.Pp
2941279519SbaptThe
2942279519Sbapt.Op -i
2943279519Sbaptoption requires one of the
2944279519Sbapt.Xr ed
2945279519Sbaptscript options
2946279519Sbapt.Op -AeExX3 ,
2947279519Sbaptand is incompatible with the merged output option
2948279519Sbapt.Op -m .
2949279519Sbapt.Pp
2950279519Sbapt.Sh  Interactive Merging with Xr sdiff
2951279519SbaptWith
2952279519Sbapt.Xr sdiff ,
2953279519Sbaptyou can merge two files interactively based on a side-by-side
2954279519Sbapt.Op -y
2955279519Sbaptformat comparison (see Section
2956279519Sbapt.Dq Side by Side ) .
2957279519SbaptUse
2958279519Sbapt.Op -o Va file
2959279519Sbaptor
2960279519Sbapt.Op --output= Va file
2961279519Sbaptto specify where to put the merged text.See Section
2962279519Sbapt.Dq Invoking sdiff ,
2963279519Sbaptfor more details on the options to
2964279519Sbapt.Xr sdiff .
2965279519Sbapt.Pp
2966279519SbaptAnother way to merge files interactively is to use the Emacs Lisp package
2967279519Sbapt.Xr emerge .
2968279519SbaptSee Section.Dq emerge ,
2969279519Sbaptfor more information.
2970279519Sbapt.Pp
2971279519Sbapt.Ss  Specifying Xr diff Options to Xr sdiff
2972279519SbaptThe following
2973279519Sbapt.Xr sdiff
2974279519Sbaptoptions have the same meaning as for
2975279519Sbapt.Xr diff .
2976279519SbaptSee Section.Dq diff Options ,
2977279519Sbaptfor the use of these options.
2978279519Sbapt.Pp
2979279519Sbapt.Bd -literal -offset indent
2980279519Sbapt-a -b -d -i -t -v
2981279519Sbapt-B -E -I regexp
2982279519Sbapt
2983279519Sbapt--expand-tabs
2984279519Sbapt--ignore-blank-lines  --ignore-case
2985279519Sbapt--ignore-matching-lines=regexp  --ignore-space-change
2986279519Sbapt--ignore-tab-expansion
2987279519Sbapt--left-column  --minimal  --speed-large-files
2988279519Sbapt--strip-trailing-cr  --suppress-common-lines
2989279519Sbapt--tabsize=columns  --text  --version  --width=columns
2990279519Sbapt.Ed
2991279519Sbapt.Pp
2992279519SbaptFor historical reasons,
2993279519Sbapt.Xr sdiff
2994279519Sbapthas alternate names for some options. The
2995279519Sbapt.Op -l
2996279519Sbaptoption is equivalent to the
2997279519Sbapt.Op --left-column
2998279519Sbaptoption, and similarly
2999279519Sbapt.Op -s
3000279519Sbaptis equivalent to
3001279519Sbapt.Op --suppress-common-lines .
3002279519SbaptThe meaning of the
3003279519Sbapt.Xr sdiff
3004279519Sbapt.Op -w
3005279519Sbaptand
3006279519Sbapt.Op -W
3007279519Sbaptoptions is interchanged from that of
3008279519Sbapt.Xr diff :
3009279519Sbaptwith
3010279519Sbapt.Xr sdiff ,
3011279519Sbapt.Op -w Va columns
3012279519Sbaptis equivalent to
3013279519Sbapt.Op --width= Va columns ,
3014279519Sbaptand
3015279519Sbapt.Op -W
3016279519Sbaptis equivalent to
3017279519Sbapt.Op --ignore-all-space .
3018279519Sbapt.Xr sdiff
3019279519Sbaptwithout the
3020279519Sbapt.Op -o
3021279519Sbaptoption is equivalent to
3022279519Sbapt.Xr diff
3023279519Sbaptwith the
3024279519Sbapt.Op -y
3025279519Sbaptor
3026279519Sbapt.Op --side-by-side
3027279519Sbaptoption (see Section
3028279519Sbapt.Dq Side by Side ) .
3029279519Sbapt.Pp
3030279519Sbapt.Ss  Merge Commands
3031279519SbaptGroups of common lines, with a blank gutter, are copied from the first file
3032279519Sbaptto the output. After each group of differing lines,
3033279519Sbapt.Xr sdiff
3034279519Sbaptprompts with
3035279519Sbapt.Li %
3036279519Sbaptand pauses, waiting for one of the following commands. Follow each command
3037279519Sbaptwith RET.
3038279519Sbapt.Pp
3039279519Sbapt.Bl -tag -width Ds
3040279519Sbapt.It  e
3041279519SbaptDiscard both versions. Invoke a text editor on an empty temporary file, then
3042279519Sbaptcopy the resulting file to the output.
3043279519Sbapt.Pp
3044279519Sbapt.It  eb
3045279519SbaptConcatenate the two versions, edit the result in a temporary file, then copy
3046279519Sbaptthe edited result to the output.
3047279519Sbapt.Pp
3048279519Sbapt.It  ed
3049279519SbaptLike
3050279519Sbapt.Li eb ,
3051279519Sbaptexcept precede each version with a header that shows what file and lines the
3052279519Sbaptversion came from.
3053279519Sbapt.Pp
3054279519Sbapt.It  el
3055279519Sbapt.It  e1
3056279519SbaptEdit a copy of the left version, then copy the result to the output.
3057279519Sbapt.Pp
3058279519Sbapt.It  er
3059279519Sbapt.It  e2
3060279519SbaptEdit a copy of the right version, then copy the result to the output.
3061279519Sbapt.Pp
3062279519Sbapt.It  l
3063279519Sbapt.It  1
3064279519SbaptCopy the left version to the output.
3065279519Sbapt.Pp
3066279519Sbapt.It  q
3067279519SbaptQuit.
3068279519Sbapt.Pp
3069279519Sbapt.It  r
3070279519Sbapt.It  2
3071279519SbaptCopy the right version to the output.
3072279519Sbapt.Pp
3073279519Sbapt.It  s
3074279519SbaptSilently copy common lines.
3075279519Sbapt.Pp
3076279519Sbapt.It  v
3077279519SbaptVerbosely copy common lines. This is the default.
3078279519Sbapt.El
3079279519Sbapt.Pp
3080279519SbaptThe text editor invoked is specified by the
3081279519Sbapt.Ev EDITOR
3082279519Sbaptenvironment variable if it is set. The default is system-dependent.
3083279519Sbapt.Pp
3084279519Sbapt.Sh  Merging with Xr patch
3085279519Sbapt.Xr patch
3086279519Sbapttakes comparison output produced by
3087279519Sbapt.Xr diff
3088279519Sbaptand applies the differences to a copy of the original file, producing a patched
3089279519Sbaptversion. With
3090279519Sbapt.Xr patch ,
3091279519Sbaptyou can distribute just the changes to a set of files instead of distributing
3092279519Sbaptthe entire file set; your correspondents can apply
3093279519Sbapt.Xr patch
3094279519Sbaptto update their copy of the files with your changes.
3095279519Sbapt.Xr patch
3096279519Sbaptautomatically determines the diff format, skips any leading or trailing headers,
3097279519Sbaptand uses the headers to determine which file to patch. This lets your correspondents
3098279519Sbaptfeed a mail message containing a difference listing directly to
3099279519Sbapt.Xr patch .
3100279519Sbapt.Pp
3101279519Sbapt.Xr patch
3102279519Sbaptdetects and warns about common problems like forward patches. It saves any
3103279519Sbaptpatches that it could not apply. It can also maintain a
3104279519Sbapt.Li patchlevel.h
3105279519Sbaptfile to ensure that your correspondents apply diffs in the proper order.
3106279519Sbapt.Pp
3107279519Sbapt.Xr patch
3108279519Sbaptaccepts a series of diffs in its standard input, usually separated by headers
3109279519Sbaptthat specify which file to patch. It applies
3110279519Sbapt.Xr diff
3111279519Sbapthunks (see Section
3112279519Sbapt.Dq Hunks )
3113279519Sbaptone by one. If a hunk does not exactly match the original file,
3114279519Sbapt.Xr patch
3115279519Sbaptuses heuristics to try to patch the file as well as it can. If no approximate
3116279519Sbaptmatch can be found,
3117279519Sbapt.Xr patch
3118279519Sbaptrejects the hunk and skips to the next hunk.
3119279519Sbapt.Xr patch
3120279519Sbaptnormally replaces each file
3121279519Sbapt.Va f
3122279519Sbaptwith its new version, putting reject hunks (if any) into
3123279519Sbapt.Li  Va f.rej .
3124279519Sbapt.Pp
3125279519SbaptSee Section.Dq Invoking patch ,
3126279519Sbaptfor detailed information on the options to
3127279519Sbapt.Xr patch .
3128279519Sbapt.Pp
3129279519Sbapt.Ss  Selecting the Xr patch Input Format
3130279519Sbapt.Xr patch
3131279519Sbaptnormally determines which
3132279519Sbapt.Xr diff
3133279519Sbaptformat the patch file uses by examining its contents. For patch files that
3134279519Sbaptcontain particularly confusing leading text, you might need to use one of
3135279519Sbaptthe following options to force
3136279519Sbapt.Xr patch
3137279519Sbaptto interpret the patch file as a certain format of diff. The output formats
3138279519Sbaptlisted here are the only ones that
3139279519Sbapt.Xr patch
3140279519Sbaptcan understand.
3141279519Sbapt.Pp
3142279519Sbapt.Bl -tag -width Ds
3143279519Sbapt.It  -c
3144279519Sbapt.It  --context
3145279519Sbaptcontext diff.
3146279519Sbapt.Pp
3147279519Sbapt.It  -e
3148279519Sbapt.It  --ed
3149279519Sbapt.Xr ed
3150279519Sbaptscript.
3151279519Sbapt.Pp
3152279519Sbapt.It  -n
3153279519Sbapt.It  --normal
3154279519Sbaptnormal diff.
3155279519Sbapt.Pp
3156279519Sbapt.It  -u
3157279519Sbapt.It  --unified
3158279519Sbaptunified diff.
3159279519Sbapt.El
3160279519Sbapt.Pp
3161279519Sbapt.Ss  Revision Control
3162279519SbaptIf a nonexistent input file is under a revision control system supported by
3163279519Sbapt.Xr patch ,
3164279519Sbapt.Xr patch
3165279519Sbaptnormally asks the user whether to get (or check out) the file from the revision
3166279519Sbaptcontrol system. Patch currently supports RCS, ClearCase and SCCS. Under RCS
3167279519Sbaptand SCCS,
3168279519Sbapt.Xr patch
3169279519Sbaptalso asks when the input file is read-only and matches the default version
3170279519Sbaptin the revision control system.
3171279519Sbapt.Pp
3172279519SbaptThe
3173279519Sbapt.Op -g Va num
3174279519Sbaptor
3175279519Sbapt.Op --get= Va num
3176279519Sbaptoption affects access to files under supported revision control systems. If
3177279519Sbapt.Va num
3178279519Sbaptis positive,
3179279519Sbapt.Xr patch
3180279519Sbaptgets the file without asking the user; if zero,
3181279519Sbapt.Xr patch
3182279519Sbaptneither asks the user nor gets the file; and if negative,
3183279519Sbapt.Xr patch
3184279519Sbaptasks the user before getting the file. The default value of
3185279519Sbapt.Va num
3186279519Sbaptis given by the value of the
3187279519Sbapt.Ev PATCH_GET
3188279519Sbaptenvironment variable if it is set; if not, the default value is zero if
3189279519Sbapt.Xr patch
3190279519Sbaptis conforming to POSIX, negative otherwise.See Section
3191279519Sbapt.Dq patch and POSIX .
3192279519Sbapt.Pp
3193279519SbaptThe choice of revision control system is unaffected by the
3194279519Sbapt.Ev VERSION_CONTROL
3195279519Sbaptenvironment variable (see Section
3196279519Sbapt.Dq Backup Names ) .
3197279519Sbapt.Pp
3198279519Sbapt.Ss  Applying Imperfect Patches
3199279519Sbapt.Xr patch
3200279519Sbapttries to skip any leading text in the patch file, apply the diff, and then
3201279519Sbaptskip any trailing text. Thus you can feed a mail message directly to
3202279519Sbapt.Xr patch ,
3203279519Sbaptand it should work. If the entire diff is indented by a constant amount of
3204279519Sbaptwhite space,
3205279519Sbapt.Xr patch
3206279519Sbaptautomatically ignores the indentation. If a context diff contains trailing
3207279519Sbaptcarriage return on each line,
3208279519Sbapt.Xr patch
3209279519Sbaptautomatically ignores the carriage return. If a context diff has been encapsulated
3210279519Sbaptby prepending
3211279519Sbapt.Li -
3212279519Sbaptto lines beginning with
3213279519Sbapt.Li -
3214279519Sbaptas per
3215279519Sbapt.Lk ftp://ftp.isi.edu/in-notes/rfc934.txt ,
3216279519Sbapt.Xr patch
3217279519Sbaptautomatically unencapsulates the input.
3218279519Sbapt.Pp
3219279519SbaptHowever, certain other types of imperfect input require user intervention
3220279519Sbaptor testing.
3221279519Sbapt.Pp
3222279519Sbapt.Em  Applying Patches with Changed White Space
3223279519Sbapt.Pp
3224279519SbaptSometimes mailers, editors, or other programs change spaces into tabs, or
3225279519Sbaptvice versa. If this happens to a patch file or an input file, the files might
3226279519Sbaptlook the same, but
3227279519Sbapt.Xr patch
3228279519Sbaptwill not be able to match them properly. If this problem occurs, use the
3229279519Sbapt.Op -l
3230279519Sbaptor
3231279519Sbapt.Op --ignore-white-space
3232279519Sbaptoption, which makes
3233279519Sbapt.Xr patch
3234279519Sbaptcompare blank characters (i.e. spaces and tabs) loosely so that any nonempty
3235279519Sbaptsequence of blanks in the patch file matches any nonempty sequence of blanks
3236279519Sbaptin the input files. Non-blank characters must still match exactly. Each line
3237279519Sbaptof the context must still match a line in the input file.
3238279519Sbapt.Pp
3239279519Sbapt.Em  Applying Reversed Patches
3240279519Sbapt.Pp
3241279519SbaptSometimes people run
3242279519Sbapt.Xr diff
3243279519Sbaptwith the new file first instead of second. This creates a diff that is \(lqreversed\(rq.
3244279519SbaptTo apply such patches, give
3245279519Sbapt.Xr patch
3246279519Sbaptthe
3247279519Sbapt.Op -R
3248279519Sbaptor
3249279519Sbapt.Op --reverse
3250279519Sbaptoption.
3251279519Sbapt.Xr patch
3252279519Sbaptthen attempts to swap each hunk around before applying it. Rejects come out
3253279519Sbaptin the swapped format.
3254279519Sbapt.Pp
3255279519SbaptOften
3256279519Sbapt.Xr patch
3257279519Sbaptcan guess that the patch is reversed. If the first hunk of a patch fails,
3258279519Sbapt.Xr patch
3259279519Sbaptreverses the hunk to see if it can apply it that way. If it can,
3260279519Sbapt.Xr patch
3261279519Sbaptasks you if you want to have the
3262279519Sbapt.Op -R
3263279519Sbaptoption set; if it can't,
3264279519Sbapt.Xr patch
3265279519Sbaptcontinues to apply the patch normally. This method cannot detect a reversed
3266279519Sbaptpatch if it is a normal diff and the first command is an append (which should
3267279519Sbapthave been a delete) since appends always succeed, because a null context matches
3268279519Sbaptanywhere. But most patches add or change lines rather than delete them, so
3269279519Sbaptmost reversed normal diffs begin with a delete, which fails, and
3270279519Sbapt.Xr patch
3271279519Sbaptnotices.
3272279519Sbapt.Pp
3273279519SbaptIf you apply a patch that you have already applied,
3274279519Sbapt.Xr patch
3275279519Sbaptthinks it is a reversed patch and offers to un-apply the patch. This could
3276279519Sbaptbe construed as a feature. If you did this inadvertently and you don't want
3277279519Sbaptto un-apply the patch, just answer
3278279519Sbapt.Li n
3279279519Sbaptto this offer and to the subsequent \(lqapply anyway\(rq question---or type
3280279519Sbapt.Li C-c
3281279519Sbaptto kill the
3282279519Sbapt.Xr patch
3283279519Sbaptprocess.
3284279519Sbapt.Pp
3285279519Sbapt.Em  Helping Xr patch Find Inexact Matches
3286279519Sbapt.Pp
3287279519SbaptFor context diffs, and to a lesser extent normal diffs,
3288279519Sbapt.Xr patch
3289279519Sbaptcan detect when the line numbers mentioned in the patch are incorrect, and
3290279519Sbaptit attempts to find the correct place to apply each hunk of the patch. As
3291279519Sbapta first guess, it takes the line number mentioned in the hunk, plus or minus
3292279519Sbaptany offset used in applying the previous hunk. If that is not the correct
3293279519Sbaptplace,
3294279519Sbapt.Xr patch
3295279519Sbaptscans both forward and backward for a set of lines matching the context given
3296279519Sbaptin the hunk.
3297279519Sbapt.Pp
3298279519SbaptFirst
3299279519Sbapt.Xr patch
3300279519Sbaptlooks for a place where all lines of the context match. If it cannot find
3301279519Sbaptsuch a place, and it is reading a context or unified diff, and the maximum
3302279519Sbaptfuzz factor is set to 1 or more, then
3303279519Sbapt.Xr patch
3304279519Sbaptmakes another scan, ignoring the first and last line of context. If that fails,
3305279519Sbaptand the maximum fuzz factor is set to 2 or more, it makes another scan, ignoring
3306279519Sbaptthe first two and last two lines of context are ignored. It continues similarly
3307279519Sbaptif the maximum fuzz factor is larger.
3308279519Sbapt.Pp
3309279519SbaptThe
3310279519Sbapt.Op -F Va lines
3311279519Sbaptor
3312279519Sbapt.Op --fuzz= Va lines
3313279519Sbaptoption sets the maximum fuzz factor to
3314279519Sbapt.Va lines .
3315279519SbaptThis option only applies to context and unified diffs; it ignores up to
3316279519Sbapt.Va lines
3317279519Sbaptlines while looking for the place to install a hunk. Note that a larger fuzz
3318279519Sbaptfactor increases the odds of making a faulty patch. The default fuzz factor
3319279519Sbaptis 2; there is no point to setting it to more than the number of lines of
3320279519Sbaptcontext in the diff, ordinarily 3.
3321279519Sbapt.Pp
3322279519SbaptIf
3323279519Sbapt.Xr patch
3324279519Sbaptcannot find a place to install a hunk of the patch, it writes the hunk out
3325279519Sbaptto a reject file (see Section
3326279519Sbapt.Dq Reject Names ,
3327279519Sbaptfor information on how reject files are named). It writes out rejected hunks
3328279519Sbaptin context format no matter what form the input patch is in. If the input
3329279519Sbaptis a normal or
3330279519Sbapt.Xr ed
3331279519Sbaptdiff, many of the contexts are simply null. The line numbers on the hunks
3332279519Sbaptin the reject file may be different from those in the patch file: they show
3333279519Sbaptthe approximate location where
3334279519Sbapt.Xr patch
3335279519Sbaptthinks the failed hunks belong in the new file rather than in the old one.
3336279519Sbapt.Pp
3337279519SbaptIf the
3338279519Sbapt.Op --verbose
3339279519Sbaptoption is given, then as it completes each hunk
3340279519Sbapt.Xr patch
3341279519Sbapttells you whether the hunk succeeded or failed, and if it failed, on which
3342279519Sbaptline (in the new file)
3343279519Sbapt.Xr patch
3344279519Sbaptthinks the hunk should go. If this is different from the line number specified
3345279519Sbaptin the diff, it tells you the offset. A single large offset
3346279519Sbapt.Em may
3347279519Sbaptindicate that
3348279519Sbapt.Xr patch
3349279519Sbaptinstalled a hunk in the wrong place.
3350279519Sbapt.Xr patch
3351279519Sbaptalso tells you if it used a fuzz factor to make the match, in which case you
3352279519Sbaptshould also be slightly suspicious.
3353279519Sbapt.Pp
3354279519Sbapt.Xr patch
3355279519Sbaptcannot tell if the line numbers are off in an
3356279519Sbapt.Xr ed
3357279519Sbaptscript, and can only detect wrong line numbers in a normal diff when it finds
3358279519Sbapta change or delete command. It may have the same problem with a context diff
3359279519Sbaptusing a fuzz factor equal to or greater than the number of lines of context
3360279519Sbaptshown in the diff (typically 3). In these cases, you should probably look
3361279519Sbaptat a context diff between your original and patched input files to see if
3362279519Sbaptthe changes make sense. Compiling without errors is a pretty good indication
3363279519Sbaptthat the patch worked, but not a guarantee.
3364279519Sbapt.Pp
3365279519SbaptA patch against an empty file applies to a nonexistent file, and vice versa.See Section
3366279519Sbapt.Dq Creating and Removing .
3367279519Sbapt.Pp
3368279519Sbapt.Xr patch
3369279519Sbaptusually produces the correct results, even when it must make many guesses.
3370279519SbaptHowever, the results are guaranteed only when the patch is applied to an exact
3371279519Sbaptcopy of the file that the patch was generated from.
3372279519Sbapt.Pp
3373279519Sbapt.Em  Predicting what Xr patch will do
3374279519Sbapt.Pp
3375279519SbaptIt may not be obvious in advance what
3376279519Sbapt.Xr patch
3377279519Sbaptwill do with a complicated or poorly formatted patch. If you are concerned
3378279519Sbaptthat the input might cause
3379279519Sbapt.Xr patch
3380279519Sbaptto modify the wrong files, you can use the
3381279519Sbapt.Op --dry-run
3382279519Sbaptoption, which causes
3383279519Sbapt.Xr patch
3384279519Sbaptto print the results of applying patches without actually changing any files.
3385279519SbaptYou can then inspect the diagnostics generated by the dry run to see whether
3386279519Sbapt.Xr patch
3387279519Sbaptwill modify the files that you expect. If the patch does not do what you want,
3388279519Sbaptyou can modify the patch (or the other options to
3389279519Sbapt.Xr patch )
3390279519Sbaptand try another dry run. Once you are satisfied with the proposed patch you
3391279519Sbaptcan apply it by invoking
3392279519Sbapt.Xr patch
3393279519Sbaptas before, but this time without the
3394279519Sbapt.Op --dry-run
3395279519Sbaptoption.
3396279519Sbapt.Pp
3397279519Sbapt.Ss  Creating and Removing Files
3398279519SbaptSometimes when comparing two directories, a file may exist in one directory
3399279519Sbaptbut not the other. If you give
3400279519Sbapt.Xr diff
3401279519Sbaptthe
3402279519Sbapt.Op -N
3403279519Sbaptor
3404279519Sbapt.Op --new-file
3405279519Sbaptoption, or if you supply an old or new file that is named
3406279519Sbapt.Pa /dev/null
3407279519Sbaptor is empty and is dated the Epoch (1970-01-01 00:00:00 UTC),
3408279519Sbapt.Xr diff
3409279519Sbaptoutputs a patch that adds or deletes the contents of this file. When given
3410279519Sbaptsuch a patch,
3411279519Sbapt.Xr patch
3412279519Sbaptnormally creates a new file or removes the old file. However, when conforming
3413279519Sbaptto POSIX (see Section
3414279519Sbapt.Dq patch and POSIX ) ,
3415279519Sbapt.Xr patch
3416279519Sbaptdoes not remove the old file, but leaves it empty. The
3417279519Sbapt.Op -E
3418279519Sbaptor
3419279519Sbapt.Op --remove-empty-files
3420279519Sbaptoption causes
3421279519Sbapt.Xr patch
3422279519Sbaptto remove output files that are empty after applying a patch, even if the
3423279519Sbaptpatch does not appear to be one that removed the file.
3424279519Sbapt.Pp
3425279519SbaptIf the patch appears to create a file that already exists,
3426279519Sbapt.Xr patch
3427279519Sbaptasks for confirmation before applying the patch.
3428279519Sbapt.Pp
3429279519Sbapt.Ss  Updating Time Stamps on Patched Files
3430279519SbaptWhen
3431279519Sbapt.Xr patch
3432279519Sbaptupdates a file, it normally sets the file's last-modified time stamp to the
3433279519Sbaptcurrent time of day. If you are using
3434279519Sbapt.Xr patch
3435279519Sbaptto track a software distribution, this can cause
3436279519Sbapt.Xr make
3437279519Sbaptto incorrectly conclude that a patched file is out of date. For example, if
3438279519Sbapt.Pa syntax.c
3439279519Sbaptdepends on
3440279519Sbapt.Pa syntax.y ,
3441279519Sbaptand
3442279519Sbapt.Xr patch
3443279519Sbaptupdates
3444279519Sbapt.Pa syntax.c
3445279519Sbaptand then
3446279519Sbapt.Pa syntax.y ,
3447279519Sbaptthen
3448279519Sbapt.Pa syntax.c
3449279519Sbaptwill normally appear to be out of date with respect to
3450279519Sbapt.Pa syntax.y
3451279519Sbapteven though its contents are actually up to date.
3452279519Sbapt.Pp
3453279519SbaptThe
3454279519Sbapt.Op -Z
3455279519Sbaptor
3456279519Sbapt.Op --set-utc
3457279519Sbaptoption causes
3458279519Sbapt.Xr patch
3459279519Sbaptto set a patched file's modification and access times to the time stamps given
3460279519Sbaptin context diff headers. If the context diff headers do not specify a time
3461279519Sbaptzone, they are assumed to use Coordinated Universal Time (UTC, often known
3462279519Sbaptas GMT).
3463279519Sbapt.Pp
3464279519SbaptThe
3465279519Sbapt.Op -T
3466279519Sbaptor
3467279519Sbapt.Op --set-time
3468279519Sbaptoption acts like
3469279519Sbapt.Op -Z
3470279519Sbaptor
3471279519Sbapt.Op --set-utc ,
3472279519Sbaptexcept that it assumes that the context diff headers' time stamps use local
3473279519Sbapttime instead of UTC. This option is not recommended, because patches using
3474279519Sbaptlocal time cannot easily be used by people in other time zones, and because
3475279519Sbaptlocal time stamps are ambiguous when local clocks move backwards during daylight-saving
3476279519Sbapttime adjustments. If the context diff headers specify a time zone, this option
3477279519Sbaptis equivalent to
3478279519Sbapt.Op -Z
3479279519Sbaptor
3480279519Sbapt.Op --set-utc .
3481279519Sbapt.Pp
3482279519Sbapt.Xr patch
3483279519Sbaptnormally refrains from setting a file's time stamps if the file's original
3484279519Sbaptlast-modified time stamp does not match the time given in the diff header,
3485279519Sbaptof if the file's contents do not exactly match the patch. However, if the
3486279519Sbapt.Op -f
3487279519Sbaptor
3488279519Sbapt.Op --force
3489279519Sbaptoption is given, the file's time stamps are set regardless.
3490279519Sbapt.Pp
3491279519SbaptDue to the limitations of the current
3492279519Sbapt.Xr diff
3493279519Sbaptformat,
3494279519Sbapt.Xr patch
3495279519Sbaptcannot update the times of files whose contents have not changed. Also, if
3496279519Sbaptyou set file time stamps to values other than the current time of day, you
3497279519Sbaptshould also remove (e.g., with
3498279519Sbapt.Li make clean )
3499279519Sbaptall files that depend on the patched files, so that later invocations of
3500279519Sbapt.Xr make
3501279519Sbaptdo not get confused by the patched files' times.
3502279519Sbapt.Pp
3503279519Sbapt.Ss  Multiple Patches in a File
3504279519SbaptIf the patch file contains more than one patch, and if you do not specify
3505279519Sbaptan input file on the command line,
3506279519Sbapt.Xr patch
3507279519Sbapttries to apply each patch as if they came from separate patch files. This
3508279519Sbaptmeans that it determines the name of the file to patch for each patch, and
3509279519Sbaptthat it examines the leading text before each patch for file names and prerequisite
3510279519Sbaptrevision level (see Section
3511279519Sbapt.Dq Making Patches ,
3512279519Sbaptfor more on that topic).
3513279519Sbapt.Pp
3514279519Sbapt.Xr patch
3515279519Sbaptuses the following rules to intuit a file name from the leading text before
3516279519Sbapta patch. First,
3517279519Sbapt.Xr patch
3518279519Sbapttakes an ordered list of candidate file names as follows:
3519279519Sbapt.Pp
3520279519Sbapt.Bl -bullet
3521279519Sbapt.It
3522279519SbaptIf the header is that of a context diff,
3523279519Sbapt.Xr patch
3524279519Sbapttakes the old and new file names in the header. A name is ignored if it does
3525279519Sbaptnot have enough slashes to satisfy the
3526279519Sbapt.Op -p Va num
3527279519Sbaptor
3528279519Sbapt.Op --strip= Va num
3529279519Sbaptoption. The name
3530279519Sbapt.Pa /dev/null
3531279519Sbaptis also ignored.
3532279519Sbapt.Pp
3533279519Sbapt.It
3534279519SbaptIf there is an
3535279519Sbapt.Li Index:
3536279519Sbaptline in the leading garbage and if either the old and new names are both absent
3537279519Sbaptor if
3538279519Sbapt.Xr patch
3539279519Sbaptis conforming to POSIX,
3540279519Sbapt.Xr patch
3541279519Sbapttakes the name in the
3542279519Sbapt.Li Index:
3543279519Sbaptline.
3544279519Sbapt.Pp
3545279519Sbapt.It
3546279519SbaptFor the purpose of the following rules, the candidate file names are considered
3547279519Sbaptto be in the order (old, new, index), regardless of the order that they appear
3548279519Sbaptin the header.
3549279519Sbapt.El
3550279519Sbapt.Pp
3551279519SbaptThen
3552279519Sbapt.Xr patch
3553279519Sbaptselects a file name from the candidate list as follows:
3554279519Sbapt.Pp
3555279519Sbapt.Bl -bullet
3556279519Sbapt.It
3557279519SbaptIf some of the named files exist,
3558279519Sbapt.Xr patch
3559279519Sbaptselects the first name if conforming to POSIX, and the best name otherwise.
3560279519Sbapt.Pp
3561279519Sbapt.It
3562279519SbaptIf
3563279519Sbapt.Xr patch
3564279519Sbaptis not ignoring RCS, ClearCase, and SCCS (see Section
3565279519Sbapt.Dq Revision Control ) ,
3566279519Sbaptand no named files exist but an RCS, ClearCase, or SCCS master is found,
3567279519Sbapt.Xr patch
3568279519Sbaptselects the first named file with an RCS, ClearCase, or SCCS master.
3569279519Sbapt.Pp
3570279519Sbapt.It
3571279519SbaptIf no named files exist, no RCS, ClearCase, or SCCS master was found, some
3572279519Sbaptnames are given,
3573279519Sbapt.Xr patch
3574279519Sbaptis not conforming to POSIX, and the patch appears to create a file,
3575279519Sbapt.Xr patch
3576279519Sbaptselects the best name requiring the creation of the fewest directories.
3577279519Sbapt.Pp
3578279519Sbapt.It
3579279519SbaptIf no file name results from the above heuristics, you are asked for the name
3580279519Sbaptof the file to patch, and
3581279519Sbapt.Xr patch
3582279519Sbaptselects that name.
3583279519Sbapt.El
3584279519Sbapt.Pp
3585279519SbaptTo determine the
3586279519Sbapt.Em best
3587279519Sbaptof a nonempty list of file names,
3588279519Sbapt.Xr patch
3589279519Sbaptfirst takes all the names with the fewest path name components; of those,
3590279519Sbaptit then takes all the names with the shortest basename; of those, it then
3591279519Sbapttakes all the shortest names; finally, it takes the first remaining name.
3592279519Sbapt.Pp
3593279519SbaptSee Section.Dq patch and POSIX ,
3594279519Sbaptto see whether
3595279519Sbapt.Xr patch
3596279519Sbaptis conforming to POSIX.
3597279519Sbapt.Pp
3598279519Sbapt.Ss  Applying Patches in Other Directories
3599279519SbaptThe
3600279519Sbapt.Op -d Va directory
3601279519Sbaptor
3602279519Sbapt.Op --directory= Va directory
3603279519Sbaptoption to
3604279519Sbapt.Xr patch
3605279519Sbaptmakes directory
3606279519Sbapt.Va directory
3607279519Sbaptthe current directory for interpreting both file names in the patch file,
3608279519Sbaptand file names given as arguments to other options (such as
3609279519Sbapt.Op -B
3610279519Sbaptand
3611279519Sbapt.Op -o ) .
3612279519SbaptFor example, while in a mail reading program, you can patch a file in the
3613279519Sbapt.Pa /usr/src/emacs
3614279519Sbaptdirectory directly from a message containing the patch like this:
3615279519Sbapt.Pp
3616279519Sbapt.Bd -literal -offset indent
3617279519Sbapt| patch -d /usr/src/emacs
3618279519Sbapt.Ed
3619279519Sbapt.Pp
3620279519SbaptSometimes the file names given in a patch contain leading directories, but
3621279519Sbaptyou keep your files in a directory different from the one given in the patch.
3622279519SbaptIn those cases, you can use the
3623279519Sbapt.Op -p Va number
3624279519Sbaptor
3625279519Sbapt.Op --strip= Va number
3626279519Sbaptoption to set the file name strip count to
3627279519Sbapt.Va number .
3628279519SbaptThe strip count tells
3629279519Sbapt.Xr patch
3630279519Sbapthow many slashes, along with the directory names between them, to strip from
3631279519Sbaptthe front of file names. A sequence of one or more adjacent slashes is counted
3632279519Sbaptas a single slash. By default,
3633279519Sbapt.Xr patch
3634279519Sbaptstrips off all leading directories, leaving just the base file names.
3635279519Sbapt.Pp
3636279519SbaptFor example, suppose the file name in the patch file is
3637279519Sbapt.Pa /gnu/src/emacs/etc/NEWS .
3638279519SbaptUsing
3639279519Sbapt.Op -p0
3640279519Sbaptgives the entire file name unmodified,
3641279519Sbapt.Op -p1
3642279519Sbaptgives
3643279519Sbapt.Pa gnu/src/emacs/etc/NEWS
3644279519Sbapt(no leading slash),
3645279519Sbapt.Op -p4
3646279519Sbaptgives
3647279519Sbapt.Pa etc/NEWS ,
3648279519Sbaptand not specifying
3649279519Sbapt.Op -p
3650279519Sbaptat all gives
3651279519Sbapt.Pa NEWS .
3652279519Sbapt.Pp
3653279519Sbapt.Xr patch
3654279519Sbaptlooks for each file (after any slashes have been stripped) in the current
3655279519Sbaptdirectory, or if you used the
3656279519Sbapt.Op -d Va directory
3657279519Sbaptoption, in that directory.
3658279519Sbapt.Pp
3659279519Sbapt.Ss  Backup Files
3660279519SbaptNormally,
3661279519Sbapt.Xr patch
3662279519Sbaptcreates a backup file if the patch does not exactly match the original input
3663279519Sbaptfile, because in that case the original data might not be recovered if you
3664279519Sbaptundo the patch with
3665279519Sbapt.Li patch -R
3666279519Sbapt(see Section
3667279519Sbapt.Dq Reversed Patches ) .
3668279519SbaptHowever, when conforming to POSIX,
3669279519Sbapt.Xr patch
3670279519Sbaptdoes not create backup files by default.See Section
3671279519Sbapt.Dq patch and POSIX .
3672279519Sbapt.Pp
3673279519SbaptThe
3674279519Sbapt.Op -b
3675279519Sbaptor
3676279519Sbapt.Op --backup
3677279519Sbaptoption causes
3678279519Sbapt.Xr patch
3679279519Sbaptto make a backup file regardless of whether the patch matches the original
3680279519Sbaptinput. The
3681279519Sbapt.Op --backup-if-mismatch
3682279519Sbaptoption causes
3683279519Sbapt.Xr patch
3684279519Sbaptto create backup files for mismatches files; this is the default when not
3685279519Sbaptconforming to POSIX. The
3686279519Sbapt.Op --no-backup-if-mismatch
3687279519Sbaptoption causes
3688279519Sbapt.Xr patch
3689279519Sbaptto not create backup files, even for mismatched patches; this is the default
3690279519Sbaptwhen conforming to POSIX.
3691279519Sbapt.Pp
3692279519SbaptWhen backing up a file that does not exist, an empty, unreadable backup file
3693279519Sbaptis created as a placeholder to represent the nonexistent file.
3694279519Sbapt.Pp
3695279519Sbapt.Ss  Backup File Names
3696279519SbaptNormally,
3697279519Sbapt.Xr patch
3698279519Sbaptrenames an original input file into a backup file by appending to its name
3699279519Sbaptthe extension
3700279519Sbapt.Li .orig ,
3701279519Sbaptor
3702279519Sbapt.Li ~
3703279519Sbaptif using
3704279519Sbapt.Li .orig
3705279519Sbaptwould make the backup file name too long. The
3706279519Sbapt.Op -z Va backup-suffix
3707279519Sbaptor
3708279519Sbapt.Op --suffix= Va backup-suffix
3709279519Sbaptoption causes
3710279519Sbapt.Xr patch
3711279519Sbaptto use
3712279519Sbapt.Va backup-suffix
3713279519Sbaptas the backup extension instead.
3714279519Sbapt.Pp
3715279519SbaptAlternately, you can specify the extension for backup files with the
3716279519Sbapt.Ev SIMPLE_BACKUP_SUFFIX
3717279519Sbaptenvironment variable, which the options override.
3718279519Sbapt.Pp
3719279519Sbapt.Xr patch
3720279519Sbaptcan also create numbered backup files the way GNU Emacs does. With this method,
3721279519Sbaptinstead of having a single backup of each file,
3722279519Sbapt.Xr patch
3723279519Sbaptmakes a new backup file name each time it patches a file. For example, the
3724279519Sbaptbackups of a file named
3725279519Sbapt.Pa sink
3726279519Sbaptwould be called, successively,
3727279519Sbapt.Pa sink.~1~ ,
3728279519Sbapt.Pa sink.~2~ ,
3729279519Sbapt.Pa sink.~3~ ,
3730279519Sbaptetc.
3731279519Sbapt.Pp
3732279519SbaptThe
3733279519Sbapt.Op -V Va backup-style
3734279519Sbaptor
3735279519Sbapt.Op --version-control= Va backup-style
3736279519Sbaptoption takes as an argument a method for creating backup file names. You can
3737279519Sbaptalternately control the type of backups that
3738279519Sbapt.Xr patch
3739279519Sbaptmakes with the
3740279519Sbapt.Ev PATCH_VERSION_CONTROL
3741279519Sbaptenvironment variable, which the
3742279519Sbapt.Op -V
3743279519Sbaptoption overrides. If
3744279519Sbapt.Ev PATCH_VERSION_CONTROL
3745279519Sbaptis not set, the
3746279519Sbapt.Ev VERSION_CONTROL
3747279519Sbaptenvironment variable is used instead. Please note that these options and variables
3748279519Sbaptcontrol backup file names; they do not affect the choice of revision control
3749279519Sbaptsystem (see Section
3750279519Sbapt.Dq Revision Control ) .
3751279519Sbapt.Pp
3752279519SbaptThe values of these environment variables and the argument to the
3753279519Sbapt.Op -V
3754279519Sbaptoption are like the GNU Emacs
3755279519Sbapt.Li version-control
3756279519Sbaptvariable (see Section
3757279519Sbapt.Dq Backup Names ,
3758279519Sbaptfor more information on backup versions in Emacs). They also recognize synonyms
3759279519Sbaptthat are more descriptive. The valid values are listed below; unique abbreviations
3760279519Sbaptare acceptable.
3761279519Sbapt.Pp
3762279519Sbapt.Bl -tag -width Ds
3763279519Sbapt.It  t
3764279519Sbapt.It  numbered
3765279519SbaptAlways make numbered backups.
3766279519Sbapt.Pp
3767279519Sbapt.It  nil
3768279519Sbapt.It  existing
3769279519SbaptMake numbered backups of files that already have them, simple backups of the
3770279519Sbaptothers. This is the default.
3771279519Sbapt.Pp
3772279519Sbapt.It  never
3773279519Sbapt.It  simple
3774279519SbaptAlways make simple backups.
3775279519Sbapt.El
3776279519Sbapt.Pp
3777279519SbaptYou can also tell
3778279519Sbapt.Xr patch
3779279519Sbaptto prepend a prefix, such as a directory name, to produce backup file names.
3780279519SbaptThe
3781279519Sbapt.Op -B Va prefix
3782279519Sbaptor
3783279519Sbapt.Op --prefix= Va prefix
3784279519Sbaptoption makes backup files by prepending
3785279519Sbapt.Va prefix
3786279519Sbaptto them. The
3787279519Sbapt.Op -Y Va prefix
3788279519Sbaptor
3789279519Sbapt.Op --basename-prefix= Va prefix
3790279519Sbaptprepends
3791279519Sbapt.Va prefix
3792279519Sbaptto the last file name component of backup file names instead; for example,
3793279519Sbapt.Op -Y ~
3794279519Sbaptcauses the backup name for
3795279519Sbapt.Pa dir/file.c
3796279519Sbaptto be
3797279519Sbapt.Pa dir/~file.c .
3798279519SbaptIf you use either of these prefix options, the suffix-based options are ignored.
3799279519Sbapt.Pp
3800279519SbaptIf you specify the output file with the
3801279519Sbapt.Op -o
3802279519Sbaptoption, that file is the one that is backed up, not the input file.
3803279519Sbapt.Pp
3804279519SbaptOptions that affect the names of backup files do not affect whether backups
3805279519Sbaptare made. For example, if you specify the
3806279519Sbapt.Op --no-backup-if-mismatch
3807279519Sbaptoption, none of the options described in this section have any affect, because
3808279519Sbaptno backups are made.
3809279519Sbapt.Pp
3810279519Sbapt.Ss  Reject File Names
3811279519SbaptThe names for reject files (files containing patches that
3812279519Sbapt.Xr patch
3813279519Sbaptcould not find a place to apply) are normally the name of the output file
3814279519Sbaptwith
3815279519Sbapt.Li .rej
3816279519Sbaptappended (or
3817279519Sbapt.Li #
3818279519Sbaptif using
3819279519Sbapt.Li .rej
3820279519Sbaptwould make the backup file name too long).
3821279519Sbapt.Pp
3822279519SbaptAlternatively, you can tell
3823279519Sbapt.Xr patch
3824279519Sbaptto place all of the rejected patches in a single file. The
3825279519Sbapt.Op -r Va reject-file
3826279519Sbaptor
3827279519Sbapt.Op --reject-file= Va reject-file
3828279519Sbaptoption uses
3829279519Sbapt.Va reject-file
3830279519Sbaptas the reject file name.
3831279519Sbapt.Pp
3832279519Sbapt.Ss  Messages and Questions from Xr patch
3833279519Sbapt.Xr patch
3834279519Sbaptcan produce a variety of messages, especially if it has trouble decoding its
3835279519Sbaptinput. In a few situations where it's not sure how to proceed,
3836279519Sbapt.Xr patch
3837279519Sbaptnormally prompts you for more information from the keyboard. There are options
3838279519Sbaptto produce more or fewer messages, to have it not ask for keyboard input,
3839279519Sbaptand to affect the way that file names are quoted in messages.
3840279519Sbapt.Pp
3841279519Sbapt.Xr patch
3842279519Sbaptexits with status 0 if all hunks are applied successfully, 1 if some hunks
3843279519Sbaptcannot be applied, and 2 if there is more serious trouble. When applying a
3844279519Sbaptset of patches in a loop, you should check the exit status, so you don't apply
3845279519Sbapta later patch to a partially patched file.
3846279519Sbapt.Pp
3847279519Sbapt.Em  Controlling the Verbosity of Xr patch
3848279519Sbapt.Pp
3849279519SbaptYou can cause
3850279519Sbapt.Xr patch
3851279519Sbaptto produce more messages by using the
3852279519Sbapt.Op --verbose
3853279519Sbaptoption. For example, when you give this option, the message
3854279519Sbapt.Li Hmm...
3855279519Sbaptindicates that
3856279519Sbapt.Xr patch
3857279519Sbaptis reading text in the patch file, attempting to determine whether there is
3858279519Sbapta patch in that text, and if so, what kind of patch it is.
3859279519Sbapt.Pp
3860279519SbaptYou can inhibit all terminal output from
3861279519Sbapt.Xr patch ,
3862279519Sbaptunless an error occurs, by using the
3863279519Sbapt.Op -s ,
3864279519Sbapt.Op --quiet ,
3865279519Sbaptor
3866279519Sbapt.Op --silent
3867279519Sbaptoption.
3868279519Sbapt.Pp
3869279519Sbapt.Em  Inhibiting Keyboard Input
3870279519Sbapt.Pp
3871279519SbaptThere are two ways you can prevent
3872279519Sbapt.Xr patch
3873279519Sbaptfrom asking you any questions. The
3874279519Sbapt.Op -f
3875279519Sbaptor
3876279519Sbapt.Op --force
3877279519Sbaptoption assumes that you know what you are doing. It causes
3878279519Sbapt.Xr patch
3879279519Sbaptto do the following:
3880279519Sbapt.Pp
3881279519Sbapt.Bl -bullet
3882279519Sbapt.It
3883279519SbaptSkip patches that do not contain file names in their headers.
3884279519Sbapt.Pp
3885279519Sbapt.It
3886279519SbaptPatch files even though they have the wrong version for the
3887279519Sbapt.Li Prereq:
3888279519Sbaptline in the patch;
3889279519Sbapt.Pp
3890279519Sbapt.It
3891279519SbaptAssume that patches are not reversed even if they look like they are.
3892279519Sbapt.El
3893279519Sbapt.Pp
3894279519SbaptThe
3895279519Sbapt.Op -t
3896279519Sbaptor
3897279519Sbapt.Op --batch
3898279519Sbaptoption is similar to
3899279519Sbapt.Op -f ,
3900279519Sbaptin that it suppresses questions, but it makes somewhat different assumptions:
3901279519Sbapt.Pp
3902279519Sbapt.Bl -bullet
3903279519Sbapt.It
3904279519SbaptSkip patches that do not contain file names in their headers (the same as
3905279519Sbapt.Op -f ) .
3906279519Sbapt.Pp
3907279519Sbapt.It
3908279519SbaptSkip patches for which the file has the wrong version for the
3909279519Sbapt.Li Prereq:
3910279519Sbaptline in the patch;
3911279519Sbapt.Pp
3912279519Sbapt.It
3913279519SbaptAssume that patches are reversed if they look like they are.
3914279519Sbapt.El
3915279519Sbapt.Pp
3916279519Sbapt.Em  Xr patch Quoting Style
3917279519Sbapt.Pp
3918279519SbaptWhen
3919279519Sbapt.Xr patch
3920279519Sbaptoutputs a file name in a diagnostic message, it can format the name in any
3921279519Sbaptof several ways. This can be useful to output file names unambiguously, even
3922279519Sbaptif they contain punctuation or special characters like newlines. The
3923279519Sbapt.Op --quoting-style= Va word
3924279519Sbaptoption controls how names are output. The
3925279519Sbapt.Va word
3926279519Sbaptshould be one of the following:
3927279519Sbapt.Pp
3928279519Sbapt.Bl -tag -width Ds
3929279519Sbapt.It  literal
3930279519SbaptOutput names as-is.
3931279519Sbapt.It  shell
3932279519SbaptQuote names for the shell if they contain shell metacharacters or would cause
3933279519Sbaptambiguous output.
3934279519Sbapt.It  shell-always
3935279519SbaptQuote names for the shell, even if they would normally not require quoting.
3936279519Sbapt.It  c
3937279519SbaptQuote names as for a C language string.
3938279519Sbapt.It  escape
3939279519SbaptQuote as with
3940279519Sbapt.Li c
3941279519Sbaptexcept omit the surrounding double-quote characters.
3942279519Sbapt.El
3943279519Sbapt.Pp
3944279519SbaptYou can specify the default value of the
3945279519Sbapt.Op --quoting-style
3946279519Sbaptoption with the environment variable
3947279519Sbapt.Ev QUOTING_STYLE .
3948279519SbaptIf that environment variable is not set, the default value is
3949279519Sbapt.Li shell ,
3950279519Sbaptbut this default may change in a future version of
3951279519Sbapt.Xr patch .
3952279519Sbapt.Pp
3953279519Sbapt.Ss  Xr patch and the POSIX Standard
3954279519SbaptIf you specify the
3955279519Sbapt.Op --posix
3956279519Sbaptoption, or set the
3957279519Sbapt.Ev POSIXLY_CORRECT
3958279519Sbaptenvironment variable,
3959279519Sbapt.Xr patch
3960279519Sbaptconforms more strictly to the POSIX standard, as follows:
3961279519Sbapt.Pp
3962279519Sbapt.Bl -bullet
3963279519Sbapt.It
3964279519SbaptTake the first existing file from the list (old, new, index) when intuiting
3965279519Sbaptfile names from diff headers.See Section
3966279519Sbapt.Dq Multiple Patches .
3967279519Sbapt.Pp
3968279519Sbapt.It
3969279519SbaptDo not remove files that are removed by a diff.See Section
3970279519Sbapt.Dq Creating and Removing .
3971279519Sbapt.Pp
3972279519Sbapt.It
3973279519SbaptDo not ask whether to get files from RCS, ClearCase, or SCCS.See Section
3974279519Sbapt.Dq Revision Control .
3975279519Sbapt.Pp
3976279519Sbapt.It
3977279519SbaptRequire that all options precede the files in the command line.
3978279519Sbapt.Pp
3979279519Sbapt.It
3980279519SbaptDo not backup files, even when there is a mismatch.See Section
3981279519Sbapt.Dq Backups .
3982279519Sbapt.Pp
3983279519Sbapt.El
3984279519Sbapt.Ss  GNU Xr patch and Traditional Xr patch
3985279519SbaptThe current version of GNU
3986279519Sbapt.Xr patch
3987279519Sbaptnormally follows the POSIX standard.See Section
3988279519Sbapt.Dq patch and POSIX ,
3989279519Sbaptfor the few exceptions to this general rule.
3990279519Sbapt.Pp
3991279519SbaptUnfortunately, POSIX redefined the behavior of
3992279519Sbapt.Xr patch
3993279519Sbaptin several important ways. You should be aware of the following differences
3994279519Sbaptif you must interoperate with traditional
3995279519Sbapt.Xr patch ,
3996279519Sbaptor with GNU
3997279519Sbapt.Xr patch
3998279519Sbaptversion 2.1 and earlier.
3999279519Sbapt.Pp
4000279519Sbapt.Bl -bullet
4001279519Sbapt.It
4002279519SbaptIn traditional
4003279519Sbapt.Xr patch ,
4004279519Sbaptthe
4005279519Sbapt.Op -p
4006279519Sbaptoption's operand was optional, and a bare
4007279519Sbapt.Op -p
4008279519Sbaptwas equivalent to
4009279519Sbapt.Op -p0 .
4010279519SbaptThe
4011279519Sbapt.Op -p
4012279519Sbaptoption now requires an operand, and
4013279519Sbapt.Op -p 0
4014279519Sbaptis now equivalent to
4015279519Sbapt.Op -p0 .
4016279519SbaptFor maximum compatibility, use options like
4017279519Sbapt.Op -p0
4018279519Sbaptand
4019279519Sbapt.Op -p1 .
4020279519Sbapt.Pp
4021279519SbaptAlso, traditional
4022279519Sbapt.Xr patch
4023279519Sbaptsimply counted slashes when stripping path prefixes;
4024279519Sbapt.Xr patch
4025279519Sbaptnow counts pathname components. That is, a sequence of one or more adjacent
4026279519Sbaptslashes now counts as a single slash. For maximum portability, avoid sending
4027279519Sbaptpatches containing
4028279519Sbapt.Pa //
4029279519Sbaptin file names.
4030279519Sbapt.Pp
4031279519Sbapt.It
4032279519SbaptIn traditional
4033279519Sbapt.Xr patch ,
4034279519Sbaptbackups were enabled by default. This behavior is now enabled with the
4035279519Sbapt.Op -b
4036279519Sbaptor
4037279519Sbapt.Op --backup
4038279519Sbaptoption.
4039279519Sbapt.Pp
4040279519SbaptConversely, in POSIX
4041279519Sbapt.Xr patch ,
4042279519Sbaptbackups are never made, even when there is a mismatch. In GNU
4043279519Sbapt.Xr patch ,
4044279519Sbaptthis behavior is enabled with the
4045279519Sbapt.Op --no-backup-if-mismatch
4046279519Sbaptoption, or by conforming to POSIX.
4047279519Sbapt.Pp
4048279519SbaptThe
4049279519Sbapt.Op -b  Va suffix
4050279519Sbaptoption of traditional
4051279519Sbapt.Xr patch
4052279519Sbaptis equivalent to the
4053279519Sbapt.Li -b -z  Va suffix
4054279519Sbaptoptions of GNU
4055279519Sbapt.Xr patch .
4056279519Sbapt.Pp
4057279519Sbapt.It
4058279519SbaptTraditional
4059279519Sbapt.Xr patch
4060279519Sbaptused a complicated (and incompletely documented) method to intuit the name
4061279519Sbaptof the file to be patched from the patch header. This method did not conform
4062279519Sbaptto POSIX, and had a few gotchas. Now
4063279519Sbapt.Xr patch
4064279519Sbaptuses a different, equally complicated (but better documented) method that
4065279519Sbaptis optionally POSIX-conforming; we hope it has fewer gotchas. The two methods
4066279519Sbaptare compatible if the file names in the context diff header and the
4067279519Sbapt.Li Index:
4068279519Sbaptline are all identical after prefix-stripping. Your patch is normally compatible
4069279519Sbaptif each header's file names all contain the same number of slashes.
4070279519Sbapt.Pp
4071279519Sbapt.It
4072279519SbaptWhen traditional
4073279519Sbapt.Xr patch
4074279519Sbaptasked the user a question, it sent the question to standard error and looked
4075279519Sbaptfor an answer from the first file in the following list that was a terminal:
4076279519Sbaptstandard error, standard output,
4077279519Sbapt.Pa /dev/tty ,
4078279519Sbaptand standard input. Now
4079279519Sbapt.Xr patch
4080279519Sbaptsends questions to standard output and gets answers from
4081279519Sbapt.Pa /dev/tty .
4082279519SbaptDefaults for some answers have been changed so that
4083279519Sbapt.Xr patch
4084279519Sbaptnever goes into an infinite loop when using default answers.
4085279519Sbapt.Pp
4086279519Sbapt.It
4087279519SbaptTraditional
4088279519Sbapt.Xr patch
4089279519Sbaptexited with a status value that counted the number of bad hunks, or with status
4090279519Sbapt1 if there was real trouble. Now
4091279519Sbapt.Xr patch
4092279519Sbaptexits with status 1 if some hunks failed, or with 2 if there was real trouble.
4093279519Sbapt.Pp
4094279519Sbapt.It
4095279519SbaptLimit yourself to the following options when sending instructions meant to
4096279519Sbaptbe executed by anyone running GNU
4097279519Sbapt.Xr patch ,
4098279519Sbapttraditional
4099279519Sbapt.Xr patch ,
4100279519Sbaptor a
4101279519Sbapt.Xr patch
4102279519Sbaptthat conforms to POSIX. Spaces are significant in the following list, and
4103279519Sbaptoperands are required.
4104279519Sbapt.Pp
4105279519Sbapt.Bd -literal -offset indent
4106279519Sbapt-c
4107279519Sbapt-d dir
4108279519Sbapt-D define
4109279519Sbapt-e
4110279519Sbapt-l
4111279519Sbapt-n
4112279519Sbapt-N
4113279519Sbapt-o outfile
4114279519Sbapt-pnum
4115279519Sbapt-R
4116279519Sbapt-r rejectfile
4117279519Sbapt.Ed
4118279519Sbapt.Pp
4119279519Sbapt.El
4120279519Sbapt.Sh  Tips for Making and Using Patches
4121279519SbaptUse some common sense when making and using patches. For example, when sending
4122279519Sbaptbug fixes to a program's maintainer, send several small patches, one per independent
4123279519Sbaptsubject, instead of one large, harder-to-digest patch that covers all the
4124279519Sbaptsubjects.
4125279519Sbapt.Pp
4126279519SbaptHere are some other things you should keep in mind if you are going to distribute
4127279519Sbaptpatches for updating a software package.
4128279519Sbapt.Pp
4129279519Sbapt.Ss  Tips for Patch Producers
4130279519SbaptTo create a patch that changes an older version of a package into a newer
4131279519Sbaptversion, first make a copy of the older and newer versions in adjacent subdirectories.
4132279519SbaptIt is common to do that by unpacking
4133279519Sbapt.Xr tar
4134279519Sbaptarchives of the two versions.
4135279519Sbapt.Pp
4136279519SbaptTo generate the patch, use the command
4137279519Sbapt.Li diff -Naur Va old Va new
4138279519Sbaptwhere
4139279519Sbapt.Va old
4140279519Sbaptand
4141279519Sbapt.Va new
4142279519Sbaptidentify the old and new directories. The names
4143279519Sbapt.Va old
4144279519Sbaptand
4145279519Sbapt.Va new
4146279519Sbaptshould not contain any slashes. The
4147279519Sbapt.Op -N
4148279519Sbaptoption lets the patch create and remove files;
4149279519Sbapt.Op -a
4150279519Sbaptlets the patch update non-text files;
4151279519Sbapt.Op -u
4152279519Sbaptgenerates useful time stamps and enough context; and
4153279519Sbapt.Op -r
4154279519Sbaptlets the patch update subdirectories. Here is an example command, using Bourne
4155279519Sbaptshell syntax:
4156279519Sbapt.Pp
4157279519Sbapt.Bd -literal -offset indent
4158279519Sbaptdiff -Naur gcc-3.0.3 gcc-3.0.4
4159279519Sbapt.Ed
4160279519Sbapt.Pp
4161279519SbaptTell your recipients how to apply the patches. This should include which working
4162279519Sbaptdirectory to use, and which
4163279519Sbapt.Xr patch
4164279519Sbaptoptions to use; the option
4165279519Sbapt.Li -p1
4166279519Sbaptis recommended. Test your procedure by pretending to be a recipient and applying
4167279519Sbaptyour patches to a copy of the original files.
4168279519Sbapt.Pp
4169279519SbaptSee Section.Dq Avoiding Common Mistakes ,
4170279519Sbaptfor how to avoid common mistakes when generating a patch.
4171279519Sbapt.Pp
4172279519Sbapt.Ss  Tips for Patch Consumers
4173279519SbaptA patch producer should tell recipients how to apply the patches, so the first
4174279519Sbaptrule of thumb for a patch consumer is to follow the instructions supplied
4175279519Sbaptwith the patch.
4176279519Sbapt.Pp
4177279519SbaptGNU
4178279519Sbapt.Xr diff
4179279519Sbaptcan analyze files with arbitrarily long lines and files that end in incomplete
4180279519Sbaptlines. However, older versions of
4181279519Sbapt.Xr patch
4182279519Sbaptcannot patch such files. If you are having trouble applying such patches,
4183279519Sbapttry upgrading to a recent version of GNU
4184279519Sbapt.Xr patch .
4185279519Sbapt.Pp
4186279519Sbapt.Ss  Avoiding Common Mistakes
4187279519SbaptWhen producing a patch for multiple files, apply
4188279519Sbapt.Xr diff
4189279519Sbaptto directories whose names do not have slashes. This reduces confusion when
4190279519Sbaptthe patch consumer specifies the
4191279519Sbapt.Op -p Va number
4192279519Sbaptoption, since this option can have surprising results when the old and new
4193279519Sbaptfile names have different numbers of slashes. For example, do not send a patch
4194279519Sbaptwith a header that looks like this:
4195279519Sbapt.Pp
4196279519Sbapt.Bd -literal -offset indent
4197279519Sbaptdiff -Naur v2.0.29/prog/README prog/README
4198279519Sbapt--- v2.0.29/prog/README	2002-03-10 23:30:39.942229878 -0800
4199279519Sbapt+++ prog/README	2002-03-17 20:49:32.442260588 -0800
4200279519Sbapt.Ed
4201279519Sbapt.Pp
4202279519Sbaptbecause the two file names have different numbers of slashes, and different
4203279519Sbaptversions of
4204279519Sbapt.Xr patch
4205279519Sbaptinterpret the file names differently. To avoid confusion, send output that
4206279519Sbaptlooks like this instead:
4207279519Sbapt.Pp
4208279519Sbapt.Bd -literal -offset indent
4209279519Sbaptdiff -Naur v2.0.29/prog/README v2.0.30/prog/README
4210279519Sbapt--- v2.0.29/prog/README	2002-03-10 23:30:39.942229878 -0800
4211279519Sbapt+++ v2.0.30/prog/README	2002-03-17 20:49:32.442260588 -0800
4212279519Sbapt.Ed
4213279519Sbapt.Pp
4214279519SbaptMake sure you have specified the file names correctly, either in a context
4215279519Sbaptdiff header or with an
4216279519Sbapt.Li Index:
4217279519Sbaptline. Take care to not send out reversed patches, since these make people
4218279519Sbaptwonder whether they have already applied the patch.
4219279519Sbapt.Pp
4220279519SbaptAvoid sending patches that compare backup file names like
4221279519Sbapt.Pa README.orig
4222279519Sbaptor
4223279519Sbapt.Pa README~ ,
4224279519Sbaptsince this might confuse
4225279519Sbapt.Xr patch
4226279519Sbaptinto patching a backup file instead of the real file. Instead, send patches
4227279519Sbaptthat compare the same base file names in different directories, e.g.
4228279519Sbapt.Pa old/README
4229279519Sbaptand
4230279519Sbapt.Pa new/README .
4231279519Sbapt.Pp
4232279519SbaptTo save people from partially applying a patch before other patches that should
4233279519Sbapthave gone before it, you can make the first patch in the patch file update
4234279519Sbapta file with a name like
4235279519Sbapt.Pa patchlevel.h
4236279519Sbaptor
4237279519Sbapt.Pa version.c ,
4238279519Sbaptwhich contains a patch level or version number. If the input file contains
4239279519Sbaptthe wrong version number,
4240279519Sbapt.Xr patch
4241279519Sbaptwill complain immediately.
4242279519Sbapt.Pp
4243279519SbaptAn even clearer way to prevent this problem is to put a
4244279519Sbapt.Li Prereq:
4245279519Sbaptline before the patch. If the leading text in the patch file contains a line
4246279519Sbaptthat starts with
4247279519Sbapt.Li Prereq: ,
4248279519Sbapt.Xr patch
4249279519Sbapttakes the next word from that line (normally a version number) and checks
4250279519Sbaptwhether the next input file contains that word, preceded and followed by either
4251279519Sbaptwhite space or a newline. If not,
4252279519Sbapt.Xr patch
4253279519Sbaptprompts you for confirmation before proceeding. This makes it difficult to
4254279519Sbaptaccidentally apply patches in the wrong order.
4255279519Sbapt.Pp
4256279519Sbapt.Ss  Generating Smaller Patches
4257279519SbaptThe simplest way to generate a patch is to use
4258279519Sbapt.Li diff -Naur
4259279519Sbapt(see Section
4260279519Sbapt.Dq Tips for Patch Producers ) ,
4261279519Sbaptbut you might be able to reduce the size of the patch by renaming or removing
4262279519Sbaptsome files before making the patch. If the older version of the package contains
4263279519Sbaptany files that the newer version does not, or if any files have been renamed
4264279519Sbaptbetween the two versions, make a list of
4265279519Sbapt.Xr rm
4266279519Sbaptand
4267279519Sbapt.Xr mv
4268279519Sbaptcommands for the user to execute in the old version directory before applying
4269279519Sbaptthe patch. Then run those commands yourself in the scratch directory.
4270279519Sbapt.Pp
4271279519SbaptIf there are any files that you don't need to include in the patch because
4272279519Sbaptthey can easily be rebuilt from other files (for example,
4273279519Sbapt.Pa TAGS
4274279519Sbaptand output from
4275279519Sbapt.Xr yacc
4276279519Sbaptand
4277279519Sbapt.Xr makeinfo ) ,
4278279519Sbaptexclude them from the patch by giving
4279279519Sbapt.Xr diff
4280279519Sbaptthe
4281279519Sbapt.Op -x Va pattern
4282279519Sbaptoption (see Section
4283279519Sbapt.Dq Comparing Directories ) .
4284279519SbaptIf you want your patch to modify a derived file because your recipients lack
4285279519Sbapttools to build it, make sure that the patch for the derived file follows any
4286279519Sbaptpatches for files that it depends on, so that the recipients' time stamps
4287279519Sbaptwill not confuse
4288279519Sbapt.Xr make .
4289279519Sbapt.Pp
4290279519SbaptNow you can create the patch using
4291279519Sbapt.Li diff -Naur .
4292279519SbaptMake sure to specify the scratch directory first and the newer directory second.
4293279519Sbapt.Pp
4294279519SbaptAdd to the top of the patch a note telling the user any
4295279519Sbapt.Xr rm
4296279519Sbaptand
4297279519Sbapt.Xr mv
4298279519Sbaptcommands to run before applying the patch. Then you can remove the scratch
4299279519Sbaptdirectory.
4300279519Sbapt.Pp
4301279519SbaptYou can also shrink the patch size by using fewer lines of context, but bear
4302279519Sbaptin mind that
4303279519Sbapt.Xr patch
4304279519Sbapttypically needs at least two lines for proper operation when patches do not
4305279519Sbaptexactly match the input files.
4306279519Sbapt.Pp
4307279519Sbapt.Sh  Invoking Xr cmp
4308279519SbaptThe
4309279519Sbapt.Xr cmp
4310279519Sbaptcommand compares two files, and if they differ, tells the first byte and line
4311279519Sbaptnumber where they differ or reports that one file is a prefix of the other.
4312279519SbaptBytes and lines are numbered starting with 1. The arguments of
4313279519Sbapt.Xr cmp
4314279519Sbaptare as follows:
4315279519Sbapt.Pp
4316279519Sbapt.Bd -literal -offset indent
4317279519Sbaptcmp options... from-file [to-file [from-skip [to-skip]]]
4318279519Sbapt.Ed
4319279519Sbapt.Pp
4320279519SbaptThe file name
4321279519Sbapt.Pa -
4322279519Sbaptis always the standard input.
4323279519Sbapt.Xr cmp
4324279519Sbaptalso uses the standard input if one file name is omitted. The
4325279519Sbapt.Va from-skip
4326279519Sbaptand
4327279519Sbapt.Va to-skip
4328279519Sbaptoperands specify how many bytes to ignore at the start of each file; they
4329279519Sbaptare equivalent to the
4330279519Sbapt.Op --ignore-initial= Va from-skip: Va to-skip
4331279519Sbaptoption.
4332279519Sbapt.Pp
4333279519SbaptBy default,
4334279519Sbapt.Xr cmp
4335279519Sbaptoutputs nothing if the two files have the same contents. If one file is a
4336279519Sbaptprefix of the other,
4337279519Sbapt.Xr cmp
4338279519Sbaptprints to standard error a message of the following form:
4339279519Sbapt.Pp
4340279519Sbapt.Bd -literal -offset indent
4341279519Sbaptcmp: EOF on shorter-file
4342279519Sbapt.Ed
4343279519Sbapt.Pp
4344279519SbaptOtherwise,
4345279519Sbapt.Xr cmp
4346279519Sbaptprints to standard output a message of the following form:
4347279519Sbapt.Pp
4348279519Sbapt.Bd -literal -offset indent
4349279519Sbaptfrom-file to-file differ: char byte-number, line line-number
4350279519Sbapt.Ed
4351279519Sbapt.Pp
4352279519SbaptThe message formats can differ outside the POSIX locale. Also, POSIX allows
4353279519Sbaptthe EOF message to be followed by a blank and some additional information.
4354279519Sbapt.Pp
4355279519SbaptAn exit status of 0 means no differences were found, 1 means some differences
4356279519Sbaptwere found, and 2 means trouble.
4357279519Sbapt.Pp
4358279519Sbapt.Ss  Options to Xr cmp
4359279519SbaptBelow is a summary of all of the options that GNU
4360279519Sbapt.Xr cmp
4361279519Sbaptaccepts. Most options have two equivalent names, one of which is a single
4362279519Sbaptletter preceded by
4363279519Sbapt.Li - ,
4364279519Sbaptand the other of which is a long name preceded by
4365279519Sbapt.Li -- .
4366279519SbaptMultiple single letter options (unless they take an argument) can be combined
4367279519Sbaptinto a single command line word:
4368279519Sbapt.Op -bl
4369279519Sbaptis equivalent to
4370279519Sbapt.Op -b -l .
4371279519Sbapt.Pp
4372279519Sbapt.Bl -tag -width Ds
4373279519Sbapt.It  -b
4374279519Sbapt.It  --print-bytes
4375279519SbaptPrint the differing bytes. Display control bytes as a
4376279519Sbapt.Li ^
4377279519Sbaptfollowed by a letter of the alphabet and precede bytes that have the high
4378279519Sbaptbit set with
4379279519Sbapt.Li M-
4380279519Sbapt(which stands for \(lqmeta\(rq).
4381279519Sbapt.Pp
4382279519Sbapt.It  --help
4383279519SbaptOutput a summary of usage and then exit.
4384279519Sbapt.Pp
4385279519Sbapt.It  -i Va skip
4386279519Sbapt.It  --ignore-initial= Va skip
4387279519SbaptIgnore any differences in the first
4388279519Sbapt.Va skip
4389279519Sbaptbytes of the input files. Treat files with fewer than
4390279519Sbapt.Va skip
4391279519Sbaptbytes as if they are empty. If
4392279519Sbapt.Va skip
4393279519Sbaptis of the form
4394279519Sbapt.Op  Va from-skip: Va to-skip ,
4395279519Sbaptskip the first
4396279519Sbapt.Va from-skip
4397279519Sbaptbytes of the first input file and the first
4398279519Sbapt.Va to-skip
4399279519Sbaptbytes of the second.
4400279519Sbapt.Pp
4401279519Sbapt.It  -l
4402279519Sbapt.It  --verbose
4403279519SbaptOutput the (decimal) byte numbers and (octal) values of all differing bytes,
4404279519Sbaptinstead of the default standard output.
4405279519Sbapt.Pp
4406279519Sbapt.It  -n Va count
4407279519Sbapt.It  --bytes= Va count
4408279519SbaptCompare at most
4409279519Sbapt.Va count
4410279519Sbaptinput bytes.
4411279519Sbapt.Pp
4412279519Sbapt.It  -s
4413279519Sbapt.It  --quiet
4414279519Sbapt.It  --silent
4415279519SbaptDo not print anything; only return an exit status indicating whether the files
4416279519Sbaptdiffer.
4417279519Sbapt.Pp
4418279519Sbapt.It  -v
4419279519Sbapt.It  --version
4420279519SbaptOutput version information and then exit.
4421279519Sbapt.El
4422279519Sbapt.Pp
4423279519SbaptIn the above table, operands that are byte counts are normally decimal, but
4424279519Sbaptmay be preceded by
4425279519Sbapt.Li 0
4426279519Sbaptfor octal and
4427279519Sbapt.Li 0x
4428279519Sbaptfor hexadecimal.
4429279519Sbapt.Pp
4430279519SbaptA byte count can be followed by a suffix to specify a multiple of that count;
4431279519Sbaptin this case an omitted integer is understood to be 1. A bare size letter,
4432279519Sbaptor one followed by
4433279519Sbapt.Li iB ,
4434279519Sbaptspecifies a multiple using powers of 1024. A size letter followed by
4435279519Sbapt.Li B
4436279519Sbaptspecifies powers of 1000 instead. For example,
4437279519Sbapt.Op -n 4M
4438279519Sbaptand
4439279519Sbapt.Op -n 4MiB
4440279519Sbaptare equivalent to
4441279519Sbapt.Op -n 4194304 ,
4442279519Sbaptwhereas
4443279519Sbapt.Op -n 4MB
4444279519Sbaptis equivalent to
4445279519Sbapt.Op -n 4000000 .
4446279519SbaptThis notation is upward compatible with the
4447279519Sbapt.Lk http://www.bipm.fr/enus/3_SI/si-prefixes.html
4448279519Sbaptfor decimal multiples and with the
4449279519Sbapt.Lk http://physics.nist.gov/cuu/Units/binary.html .
4450279519Sbapt.Pp
4451279519SbaptThe following suffixes are defined. Large sizes like
4452279519Sbapt.Li 1Y
4453279519Sbaptmay be rejected by your computer due to limitations of its arithmetic.
4454279519Sbapt.Pp
4455279519Sbapt.Bl -tag -width Ds
4456279519Sbapt.It  kB
4457279519Sbaptkilobyte: 10^3 = 1000.
4458279519Sbapt.It  k
4459279519Sbapt.It  K
4460279519Sbapt.It  KiB
4461279519Sbaptkibibyte: 2^10 = 1024.
4462279519Sbapt.Li K
4463279519Sbaptis special: the SI prefix is
4464279519Sbapt.Li k
4465279519Sbaptand the IEC 60027-2 prefix is
4466279519Sbapt.Li Ki ,
4467279519Sbaptbut tradition and POSIX use
4468279519Sbapt.Li k
4469279519Sbaptto mean
4470279519Sbapt.Li KiB .
4471279519Sbapt.It  MB
4472279519Sbaptmegabyte: 10^6 = 1,000,000.
4473279519Sbapt.It  M
4474279519Sbapt.It  MiB
4475279519Sbaptmebibyte: 2^20 = 1,048,576.
4476279519Sbapt.It  GB
4477279519Sbaptgigabyte: 10^9 = 1,000,000,000.
4478279519Sbapt.It  G
4479279519Sbapt.It  GiB
4480279519Sbaptgibibyte: 2^30 = 1,073,741,824.
4481279519Sbapt.It  TB
4482279519Sbaptterabyte: 10^12 = 1,000,000,000,000.
4483279519Sbapt.It  T
4484279519Sbapt.It  TiB
4485279519Sbapttebibyte: 2^40 = 1,099,511,627,776.
4486279519Sbapt.It  PB
4487279519Sbaptpetabyte: 10^15 = 1,000,000,000,000,000.
4488279519Sbapt.It  P
4489279519Sbapt.It  PiB
4490279519Sbaptpebibyte: 2^50 = 1,125,899,906,842,624.
4491279519Sbapt.It  EB
4492279519Sbaptexabyte: 10^18 = 1,000,000,000,000,000,000.
4493279519Sbapt.It  E
4494279519Sbapt.It  EiB
4495279519Sbaptexbibyte: 2^60 = 1,152,921,504,606,846,976.
4496279519Sbapt.It  ZB
4497279519Sbaptzettabyte: 10^21 = 1,000,000,000,000,000,000,000
4498279519Sbapt.It  Z
4499279519Sbapt.It  ZiB
4500279519Sbapt2^70 = 1,180,591,620,717,411,303,424. (
4501279519Sbapt.Li Zi
4502279519Sbaptis a GNU extension to IEC 60027-2.)
4503279519Sbapt.It  YB
4504279519Sbaptyottabyte: 10^24 = 1,000,000,000,000,000,000,000,000.
4505279519Sbapt.It  Y
4506279519Sbapt.It  YiB
4507279519Sbapt2^80 = 1,208,925,819,614,629,174,706,176. (
4508279519Sbapt.Li Yi
4509279519Sbaptis a GNU extension to IEC 60027-2.)
4510279519Sbapt.El
4511279519Sbapt.Pp
4512279519Sbapt.Sh  Invoking Xr diff
4513279519SbaptThe format for running the
4514279519Sbapt.Xr diff
4515279519Sbaptcommand is:
4516279519Sbapt.Pp
4517279519Sbapt.Bd -literal -offset indent
4518279519Sbaptdiff options... files...
4519279519Sbapt.Ed
4520279519Sbapt.Pp
4521279519SbaptIn the simplest case, two file names
4522279519Sbapt.Va from-file
4523279519Sbaptand
4524279519Sbapt.Va to-file
4525279519Sbaptare given, and
4526279519Sbapt.Xr diff
4527279519Sbaptcompares the contents of
4528279519Sbapt.Va from-file
4529279519Sbaptand
4530279519Sbapt.Va to-file .
4531279519SbaptA file name of
4532279519Sbapt.Pa -
4533279519Sbaptstands for text read from the standard input. As a special case,
4534279519Sbapt.Li diff - -
4535279519Sbaptcompares a copy of standard input to itself.
4536279519Sbapt.Pp
4537279519SbaptIf one file is a directory and the other is not,
4538279519Sbapt.Xr diff
4539279519Sbaptcompares the file in the directory whose name is that of the non-directory.
4540279519SbaptThe non-directory file must not be
4541279519Sbapt.Pa - .
4542279519Sbapt.Pp
4543279519SbaptIf two file names are given and both are directories,
4544279519Sbapt.Xr diff
4545279519Sbaptcompares corresponding files in both directories, in alphabetical order; this
4546279519Sbaptcomparison is not recursive unless the
4547279519Sbapt.Op -r
4548279519Sbaptor
4549279519Sbapt.Op --recursive
4550279519Sbaptoption is given.
4551279519Sbapt.Xr diff
4552279519Sbaptnever compares the actual contents of a directory as if it were a file. The
4553279519Sbaptfile that is fully specified may not be standard input, because standard input
4554279519Sbaptis nameless and the notion of \(lqfile with the same name\(rq does not apply.
4555279519Sbapt.Pp
4556279519SbaptIf the
4557279519Sbapt.Op --from-file= Va file
4558279519Sbaptoption is given, the number of file names is arbitrary, and
4559279519Sbapt.Va file
4560279519Sbaptis compared to each named file. Similarly, if the
4561279519Sbapt.Op --to-file= Va file
4562279519Sbaptoption is given, each named file is compared to
4563279519Sbapt.Va file .
4564279519Sbapt.Pp
4565279519Sbapt.Xr diff
4566279519Sbaptoptions begin with
4567279519Sbapt.Li - ,
4568279519Sbaptso normally file names may not begin with
4569279519Sbapt.Li - .
4570279519SbaptHowever,
4571279519Sbapt.Op --
4572279519Sbaptas an argument by itself treats the remaining arguments as file names even
4573279519Sbaptif they begin with
4574279519Sbapt.Li - .
4575279519Sbapt.Pp
4576279519SbaptAn exit status of 0 means no differences were found, 1 means some differences
4577279519Sbaptwere found, and 2 means trouble. Normally, differing binary files count as
4578279519Sbapttrouble, but this can be altered by using the
4579279519Sbapt.Op -a
4580279519Sbaptor
4581279519Sbapt.Op --text
4582279519Sbaptoption, or the
4583279519Sbapt.Op -q
4584279519Sbaptor
4585279519Sbapt.Op --brief
4586279519Sbaptoption.
4587279519Sbapt.Pp
4588279519Sbapt.Ss  Options to Xr diff
4589279519SbaptBelow is a summary of all of the options that GNU
4590279519Sbapt.Xr diff
4591279519Sbaptaccepts. Most options have two equivalent names, one of which is a single
4592279519Sbaptletter preceded by
4593279519Sbapt.Li - ,
4594279519Sbaptand the other of which is a long name preceded by
4595279519Sbapt.Li -- .
4596279519SbaptMultiple single letter options (unless they take an argument) can be combined
4597279519Sbaptinto a single command line word:
4598279519Sbapt.Op -ac
4599279519Sbaptis equivalent to
4600279519Sbapt.Op -a -c .
4601279519SbaptLong named options can be abbreviated to any unique prefix of their name.
4602279519SbaptBrackets ([ and ]) indicate that an option takes an optional argument.
4603279519Sbapt.Pp
4604279519Sbapt.Bl -tag -width Ds
4605279519Sbapt.It  -a
4606279519Sbapt.It  --text
4607279519SbaptTreat all files as text and compare them line-by-line, even if they do not
4608279519Sbaptseem to be text.See Section
4609279519Sbapt.Dq Binary .
4610279519Sbapt.Pp
4611279519Sbapt.It  -b
4612279519Sbapt.It  --ignore-space-change
4613279519SbaptIgnore changes in amount of white space.See Section
4614279519Sbapt.Dq White Space .
4615279519Sbapt.Pp
4616279519Sbapt.It  -B
4617279519Sbapt.It  --ignore-blank-lines
4618279519SbaptIgnore changes that just insert or delete blank lines.See Section
4619279519Sbapt.Dq Blank Lines .
4620279519Sbapt.Pp
4621279519Sbapt.It  --binary
4622279519SbaptRead and write data in binary mode.See Section
4623279519Sbapt.Dq Binary .
4624279519Sbapt.Pp
4625279519Sbapt.It  -c
4626279519SbaptUse the context output format, showing three lines of context.See Section
4627279519Sbapt.Dq Context Format .
4628279519Sbapt.Pp
4629279519Sbapt.It  -C Va lines
4630279519Sbapt.It  --context[= Va lines]
4631279519SbaptUse the context output format, showing
4632279519Sbapt.Va lines
4633279519Sbapt(an integer) lines of context, or three if
4634279519Sbapt.Va lines
4635279519Sbaptis not given.See Section
4636279519Sbapt.Dq Context Format .
4637279519SbaptFor proper operation,
4638279519Sbapt.Xr patch
4639279519Sbapttypically needs at least two lines of context.
4640279519Sbapt.Pp
4641279519SbaptOn older systems,
4642279519Sbapt.Xr diff
4643279519Sbaptsupports an obsolete option
4644279519Sbapt.Op - Va lines
4645279519Sbaptthat has effect when combined with
4646279519Sbapt.Op -c
4647279519Sbaptor
4648279519Sbapt.Op -p .
4649279519SbaptPOSIX 1003.1-2001 (see Section
4650279519Sbapt.Dq Standards conformance )
4651279519Sbaptdoes not allow this; use
4652279519Sbapt.Op -C Va lines
4653279519Sbaptinstead.
4654279519Sbapt.Pp
4655279519Sbapt.It  --changed-group-format= Va format
4656279519SbaptUse
4657279519Sbapt.Va format
4658279519Sbaptto output a line group containing differing lines from both files in if-then-else
4659279519Sbaptformat.See Section
4660279519Sbapt.Dq Line Group Formats .
4661279519Sbapt.Pp
4662279519Sbapt.It  -d
4663279519Sbapt.It  --minimal
4664279519SbaptChange the algorithm perhaps find a smaller set of changes. This makes
4665279519Sbapt.Xr diff
4666279519Sbaptslower (sometimes much slower).See Section
4667279519Sbapt.Dq diff Performance .
4668279519Sbapt.Pp
4669279519Sbapt.It  -D Va name
4670279519Sbapt.It  --ifdef= Va name
4671279519SbaptMake merged
4672279519Sbapt.Li #ifdef
4673279519Sbaptformat output, conditional on the preprocessor macro
4674279519Sbapt.Va name .
4675279519SbaptSee Section.Dq If-then-else .
4676279519Sbapt.Pp
4677279519Sbapt.It  -e
4678279519Sbapt.It  --ed
4679279519SbaptMake output that is a valid
4680279519Sbapt.Xr ed
4681279519Sbaptscript.See Section
4682279519Sbapt.Dq ed Scripts .
4683279519Sbapt.Pp
4684279519Sbapt.It  -E
4685279519Sbapt.It  --ignore-tab-expansion
4686279519SbaptIgnore changes due to tab expansion.See Section
4687279519Sbapt.Dq White Space .
4688279519Sbapt.Pp
4689279519Sbapt.It  -f
4690279519Sbapt.It  --forward-ed
4691279519SbaptMake output that looks vaguely like an
4692279519Sbapt.Xr ed
4693279519Sbaptscript but has changes in the order they appear in the file.See Section
4694279519Sbapt.Dq Forward ed .
4695279519Sbapt.Pp
4696279519Sbapt.It  -F Va regexp
4697279519Sbapt.It  --show-function-line= Va regexp
4698279519SbaptIn context and unified format, for each hunk of differences, show some of
4699279519Sbaptthe last preceding line that matches
4700279519Sbapt.Va regexp .
4701279519SbaptSee Section.Dq Specified Headings .
4702279519Sbapt.Pp
4703279519Sbapt.It  --from-file= Va file
4704279519SbaptCompare
4705279519Sbapt.Va file
4706279519Sbaptto each operand;
4707279519Sbapt.Va file
4708279519Sbaptmay be a directory.
4709279519Sbapt.Pp
4710279519Sbapt.It  --help
4711279519SbaptOutput a summary of usage and then exit.
4712279519Sbapt.Pp
4713279519Sbapt.It  --horizon-lines= Va lines
4714279519SbaptDo not discard the last
4715279519Sbapt.Va lines
4716279519Sbaptlines of the common prefix and the first
4717279519Sbapt.Va lines
4718279519Sbaptlines of the common suffix.See Section
4719279519Sbapt.Dq diff Performance .
4720279519Sbapt.Pp
4721279519Sbapt.It  -i
4722279519Sbapt.It  --ignore-case
4723279519SbaptIgnore changes in case; consider upper- and lower-case letters equivalent.See Section
4724279519Sbapt.Dq Case Folding .
4725279519Sbapt.Pp
4726279519Sbapt.It  -I Va regexp
4727279519Sbapt.It  --ignore-matching-lines= Va regexp
4728279519SbaptIgnore changes that just insert or delete lines that match
4729279519Sbapt.Va regexp .
4730279519SbaptSee Section.Dq Specified Lines .
4731279519Sbapt.Pp
4732279519Sbapt.It  --ignore-file-name-case
4733279519SbaptIgnore case when comparing file names during recursive comparison.See Section
4734279519Sbapt.Dq Comparing Directories .
4735279519Sbapt.Pp
4736279519Sbapt.It  -l
4737279519Sbapt.It  --paginate
4738279519SbaptPass the output through
4739279519Sbapt.Xr pr
4740279519Sbaptto paginate it.See Section
4741279519Sbapt.Dq Pagination .
4742279519Sbapt.Pp
4743279519Sbapt.It  --label= Va label
4744279519SbaptUse
4745279519Sbapt.Va label
4746279519Sbaptinstead of the file name in the context format (see Section
4747279519Sbapt.Dq Context Format )
4748279519Sbaptand unified format (see Section
4749279519Sbapt.Dq Unified Format )
4750279519Sbaptheaders.See Section
4751279519Sbapt.Dq RCS .
4752279519Sbapt.Pp
4753279519Sbapt.It  --left-column
4754279519SbaptPrint only the left column of two common lines in side by side format.See Section
4755279519Sbapt.Dq Side by Side Format .
4756279519Sbapt.Pp
4757279519Sbapt.It  --line-format= Va format
4758279519SbaptUse
4759279519Sbapt.Va format
4760279519Sbaptto output all input lines in if-then-else format.See Section
4761279519Sbapt.Dq Line Formats .
4762279519Sbapt.Pp
4763279519Sbapt.It  -n
4764279519Sbapt.It  --rcs
4765279519SbaptOutput RCS-format diffs; like
4766279519Sbapt.Op -f
4767279519Sbaptexcept that each command specifies the number of lines affected.See Section
4768279519Sbapt.Dq RCS .
4769279519Sbapt.Pp
4770279519Sbapt.It  -N
4771279519Sbapt.It  --new-file
4772279519SbaptIn directory comparison, if a file is found in only one directory, treat it
4773279519Sbaptas present but empty in the other directory.See Section
4774279519Sbapt.Dq Comparing Directories .
4775279519Sbapt.Pp
4776279519Sbapt.It  --new-group-format= Va format
4777279519SbaptUse
4778279519Sbapt.Va format
4779279519Sbaptto output a group of lines taken from just the second file in if-then-else
4780279519Sbaptformat.See Section
4781279519Sbapt.Dq Line Group Formats .
4782279519Sbapt.Pp
4783279519Sbapt.It  --new-line-format= Va format
4784279519SbaptUse
4785279519Sbapt.Va format
4786279519Sbaptto output a line taken from just the second file in if-then-else format.See Section
4787279519Sbapt.Dq Line Formats .
4788279519Sbapt.Pp
4789279519Sbapt.It  --old-group-format= Va format
4790279519SbaptUse
4791279519Sbapt.Va format
4792279519Sbaptto output a group of lines taken from just the first file in if-then-else
4793279519Sbaptformat.See Section
4794279519Sbapt.Dq Line Group Formats .
4795279519Sbapt.Pp
4796279519Sbapt.It  --old-line-format= Va format
4797279519SbaptUse
4798279519Sbapt.Va format
4799279519Sbaptto output a line taken from just the first file in if-then-else format.See Section
4800279519Sbapt.Dq Line Formats .
4801279519Sbapt.Pp
4802279519Sbapt.It  -p
4803279519Sbapt.It  --show-c-function
4804279519SbaptShow which C function each change is in.See Section
4805279519Sbapt.Dq C Function Headings .
4806279519Sbapt.Pp
4807279519Sbapt.It  -q
4808279519Sbapt.It  --brief
4809279519SbaptReport only whether the files differ, not the details of the differences.See Section
4810279519Sbapt.Dq Brief .
4811279519Sbapt.Pp
4812279519Sbapt.It  -r
4813279519Sbapt.It  --recursive
4814279519SbaptWhen comparing directories, recursively compare any subdirectories found.See Section
4815279519Sbapt.Dq Comparing Directories .
4816279519Sbapt.Pp
4817279519Sbapt.It  -s
4818279519Sbapt.It  --report-identical-files
4819279519SbaptReport when two files are the same.See Section
4820279519Sbapt.Dq Comparing Directories .
4821279519Sbapt.Pp
4822279519Sbapt.It  -S Va file
4823279519Sbapt.It  --starting-file= Va file
4824279519SbaptWhen comparing directories, start with the file
4825279519Sbapt.Va file .
4826279519SbaptThis is used for resuming an aborted comparison.See Section
4827279519Sbapt.Dq Comparing Directories .
4828279519Sbapt.Pp
4829279519Sbapt.It  --speed-large-files
4830279519SbaptUse heuristics to speed handling of large files that have numerous scattered
4831279519Sbaptsmall changes.See Section
4832279519Sbapt.Dq diff Performance .
4833279519Sbapt.Pp
4834279519Sbapt.It  --strip-trailing-cr
4835279519SbaptStrip any trailing carriage return at the end of an input line.See Section
4836279519Sbapt.Dq Binary .
4837279519Sbapt.Pp
4838279519Sbapt.It  --suppress-common-lines
4839279519SbaptDo not print common lines in side by side format.See Section
4840279519Sbapt.Dq Side by Side Format .
4841279519Sbapt.Pp
4842279519Sbapt.It  -t
4843279519Sbapt.It  --expand-tabs
4844279519SbaptExpand tabs to spaces in the output, to preserve the alignment of tabs in
4845279519Sbaptthe input files.See Section
4846279519Sbapt.Dq Tabs .
4847279519Sbapt.Pp
4848279519Sbapt.It  -T
4849279519Sbapt.It  --initial-tab
4850279519SbaptOutput a tab rather than a space before the text of a line in normal or context
4851279519Sbaptformat. This causes the alignment of tabs in the line to look normal.See Section
4852279519Sbapt.Dq Tabs .
4853279519Sbapt.Pp
4854279519Sbapt.It  --tabsize= Va columns
4855279519SbaptAssume that tab stops are set every
4856279519Sbapt.Va columns
4857279519Sbapt(default 8) print columns.See Section
4858279519Sbapt.Dq Tabs .
4859279519Sbapt.Pp
4860279519Sbapt.It  --to-file= Va file
4861279519SbaptCompare each operand to
4862279519Sbapt.Va file
4863279519Sbapt;
4864279519Sbapt.Va file
4865279519Sbaptmay be a directory.
4866279519Sbapt.Pp
4867279519Sbapt.It  -u
4868279519SbaptUse the unified output format, showing three lines of context.See Section
4869279519Sbapt.Dq Unified Format .
4870279519Sbapt.Pp
4871279519Sbapt.It  --unchanged-group-format= Va format
4872279519SbaptUse
4873279519Sbapt.Va format
4874279519Sbaptto output a group of common lines taken from both files in if-then-else format.See Section
4875279519Sbapt.Dq Line Group Formats .
4876279519Sbapt.Pp
4877279519Sbapt.It  --unchanged-line-format= Va format
4878279519SbaptUse
4879279519Sbapt.Va format
4880279519Sbaptto output a line common to both files in if-then-else format.See Section
4881279519Sbapt.Dq Line Formats .
4882279519Sbapt.Pp
4883279519Sbapt.It  --unidirectional-new-file
4884279519SbaptWhen comparing directories, if a file appears only in the second directory
4885279519Sbaptof the two, treat it as present but empty in the other.See Section
4886279519Sbapt.Dq Comparing Directories .
4887279519Sbapt.Pp
4888279519Sbapt.It  -U Va lines
4889279519Sbapt.It  --unified[= Va lines]
4890279519SbaptUse the unified output format, showing
4891279519Sbapt.Va lines
4892279519Sbapt(an integer) lines of context, or three if
4893279519Sbapt.Va lines
4894279519Sbaptis not given.See Section
4895279519Sbapt.Dq Unified Format .
4896279519SbaptFor proper operation,
4897279519Sbapt.Xr patch
4898279519Sbapttypically needs at least two lines of context.
4899279519Sbapt.Pp
4900279519SbaptOn older systems,
4901279519Sbapt.Xr diff
4902279519Sbaptsupports an obsolete option
4903279519Sbapt.Op - Va lines
4904279519Sbaptthat has effect when combined with
4905279519Sbapt.Op -u .
4906279519SbaptPOSIX 1003.1-2001 (see Section
4907279519Sbapt.Dq Standards conformance )
4908279519Sbaptdoes not allow this; use
4909279519Sbapt.Op -U Va lines
4910279519Sbaptinstead.
4911279519Sbapt.Pp
4912279519Sbapt.It  -v
4913279519Sbapt.It  --version
4914279519SbaptOutput version information and then exit.
4915279519Sbapt.Pp
4916279519Sbapt.It  -w
4917279519Sbapt.It  --ignore-all-space
4918279519SbaptIgnore white space when comparing lines.See Section
4919279519Sbapt.Dq White Space .
4920279519Sbapt.Pp
4921279519Sbapt.It  -W Va columns
4922279519Sbapt.It  --width= Va columns
4923279519SbaptOutput at most
4924279519Sbapt.Va columns
4925279519Sbapt(default 130) print columns per line in side by side format.See Section
4926279519Sbapt.Dq Side by Side Format .
4927279519Sbapt.Pp
4928279519Sbapt.It  -x Va pattern
4929279519Sbapt.It  --exclude= Va pattern
4930279519SbaptWhen comparing directories, ignore files and subdirectories whose basenames
4931279519Sbaptmatch
4932279519Sbapt.Va pattern .
4933279519SbaptSee Section.Dq Comparing Directories .
4934279519Sbapt.Pp
4935279519Sbapt.It  -X Va file
4936279519Sbapt.It  --exclude-from= Va file
4937279519SbaptWhen comparing directories, ignore files and subdirectories whose basenames
4938279519Sbaptmatch any pattern contained in
4939279519Sbapt.Va file .
4940279519SbaptSee Section.Dq Comparing Directories .
4941279519Sbapt.Pp
4942279519Sbapt.It  -y
4943279519Sbapt.It  --side-by-side
4944279519SbaptUse the side by side output format.See Section
4945279519Sbapt.Dq Side by Side Format .
4946279519Sbapt.El
4947279519Sbapt.Pp
4948279519Sbapt.Sh  Invoking Xr diff3
4949279519SbaptThe
4950279519Sbapt.Xr diff3
4951279519Sbaptcommand compares three files and outputs descriptions of their differences.
4952279519SbaptIts arguments are as follows:
4953279519Sbapt.Pp
4954279519Sbapt.Bd -literal -offset indent
4955279519Sbaptdiff3 options... mine older yours
4956279519Sbapt.Ed
4957279519Sbapt.Pp
4958279519SbaptThe files to compare are
4959279519Sbapt.Va mine ,
4960279519Sbapt.Va older ,
4961279519Sbaptand
4962279519Sbapt.Va yours .
4963279519SbaptAt most one of these three file names may be
4964279519Sbapt.Pa - ,
4965279519Sbaptwhich tells
4966279519Sbapt.Xr diff3
4967279519Sbaptto read the standard input for that file.
4968279519Sbapt.Pp
4969279519SbaptAn exit status of 0 means
4970279519Sbapt.Xr diff3
4971279519Sbaptwas successful, 1 means some conflicts were found, and 2 means trouble.
4972279519Sbapt.Pp
4973279519Sbapt.Ss  Options to Xr diff3
4974279519SbaptBelow is a summary of all of the options that GNU
4975279519Sbapt.Xr diff3
4976279519Sbaptaccepts. Multiple single letter options (unless they take an argument) can
4977279519Sbaptbe combined into a single command line argument.
4978279519Sbapt.Pp
4979279519Sbapt.Bl -tag -width Ds
4980279519Sbapt.It  -a
4981279519Sbapt.It  --text
4982279519SbaptTreat all files as text and compare them line-by-line, even if they do not
4983279519Sbaptappear to be text.See Section
4984279519Sbapt.Dq Binary .
4985279519Sbapt.Pp
4986279519Sbapt.It  -A
4987279519Sbapt.It  --show-all
4988279519SbaptIncorporate all unmerged changes from
4989279519Sbapt.Va older
4990279519Sbaptto
4991279519Sbapt.Va yours
4992279519Sbaptinto
4993279519Sbapt.Va mine ,
4994279519Sbaptsurrounding conflicts with bracket lines.See Section
4995279519Sbapt.Dq Marking Conflicts .
4996279519Sbapt.Pp
4997279519Sbapt.It  --diff-program= Va program
4998279519SbaptUse the compatible comparison program
4999279519Sbapt.Va program
5000279519Sbaptto compare files instead of
5001279519Sbapt.Xr diff .
5002279519Sbapt.Pp
5003279519Sbapt.It  -e
5004279519Sbapt.It  --ed
5005279519SbaptGenerate an
5006279519Sbapt.Xr ed
5007279519Sbaptscript that incorporates all the changes from
5008279519Sbapt.Va older
5009279519Sbaptto
5010279519Sbapt.Va yours
5011279519Sbaptinto
5012279519Sbapt.Va mine .
5013279519SbaptSee Section.Dq Which Changes .
5014279519Sbapt.Pp
5015279519Sbapt.It  -E
5016279519Sbapt.It  --show-overlap
5017279519SbaptLike
5018279519Sbapt.Op -e ,
5019279519Sbaptexcept bracket lines from overlapping changes' first and third files.See Section
5020279519Sbapt.Dq Marking Conflicts .
5021279519SbaptWith
5022279519Sbapt.Op -E ,
5023279519Sbaptan overlapping change looks like this:
5024279519Sbapt.Pp
5025279519Sbapt.Bd -literal -offset indent
5026279519Sbapt<<<<<<< mine
5027279519Sbaptlines from mine
5028279519Sbapt=======
5029279519Sbaptlines from yours
5030279519Sbapt>>>>>>> yours
5031279519Sbapt.Ed
5032279519Sbapt.Pp
5033279519Sbapt.It  --help
5034279519SbaptOutput a summary of usage and then exit.
5035279519Sbapt.Pp
5036279519Sbapt.It  -i
5037279519SbaptGenerate
5038279519Sbapt.Li w
5039279519Sbaptand
5040279519Sbapt.Li q
5041279519Sbaptcommands at the end of the
5042279519Sbapt.Xr ed
5043279519Sbaptscript for System V compatibility. This option must be combined with one of
5044279519Sbaptthe
5045279519Sbapt.Op -AeExX3
5046279519Sbaptoptions, and may not be combined with
5047279519Sbapt.Op -m .
5048279519SbaptSee Section.Dq Saving the Changed File .
5049279519Sbapt.Pp
5050279519Sbapt.It  --label= Va label
5051279519SbaptUse the label
5052279519Sbapt.Va label
5053279519Sbaptfor the brackets output by the
5054279519Sbapt.Op -A ,
5055279519Sbapt.Op -E
5056279519Sbaptand
5057279519Sbapt.Op -X
5058279519Sbaptoptions. This option may be given up to three times, one for each input file.
5059279519SbaptThe default labels are the names of the input files. Thus
5060279519Sbapt.Li diff3 --label X --label Y --label Z -m A B C
5061279519Sbaptacts like
5062279519Sbapt.Li diff3 -m A B C ,
5063279519Sbaptexcept that the output looks like it came from files named
5064279519Sbapt.Li X ,
5065279519Sbapt.Li Y
5066279519Sbaptand
5067279519Sbapt.Li Z
5068279519Sbaptrather than from files named
5069279519Sbapt.Li A ,
5070279519Sbapt.Li B
5071279519Sbaptand
5072279519Sbapt.Li C .
5073279519SbaptSee Section.Dq Marking Conflicts .
5074279519Sbapt.Pp
5075279519Sbapt.It  -m
5076279519Sbapt.It  --merge
5077279519SbaptApply the edit script to the first file and send the result to standard output.
5078279519SbaptUnlike piping the output from
5079279519Sbapt.Xr diff3
5080279519Sbaptto
5081279519Sbapt.Xr ed ,
5082279519Sbaptthis works even for binary files and incomplete lines.
5083279519Sbapt.Op -A
5084279519Sbaptis assumed if no edit script option is specified.See Section
5085279519Sbapt.Dq Bypassing ed .
5086279519Sbapt.Pp
5087279519Sbapt.It  --strip-trailing-cr
5088279519SbaptStrip any trailing carriage return at the end of an input line.See Section
5089279519Sbapt.Dq Binary .
5090279519Sbapt.Pp
5091279519Sbapt.It  -T
5092279519Sbapt.It  --initial-tab
5093279519SbaptOutput a tab rather than two spaces before the text of a line in normal format.
5094279519SbaptThis causes the alignment of tabs in the line to look normal.See Section
5095279519Sbapt.Dq Tabs .
5096279519Sbapt.Pp
5097279519Sbapt.It  -v
5098279519Sbapt.It  --version
5099279519SbaptOutput version information and then exit.
5100279519Sbapt.Pp
5101279519Sbapt.It  -x
5102279519Sbapt.It  --overlap-only
5103279519SbaptLike
5104279519Sbapt.Op -e ,
5105279519Sbaptexcept output only the overlapping changes.See Section
5106279519Sbapt.Dq Which Changes .
5107279519Sbapt.Pp
5108279519Sbapt.It  -X
5109279519SbaptLike
5110279519Sbapt.Op -E ,
5111279519Sbaptexcept output only the overlapping changes. In other words, like
5112279519Sbapt.Op -x ,
5113279519Sbaptexcept bracket changes as in
5114279519Sbapt.Op -E .
5115279519SbaptSee Section.Dq Marking Conflicts .
5116279519Sbapt.Pp
5117279519Sbapt.It  -3
5118279519Sbapt.It  --easy-only
5119279519SbaptLike
5120279519Sbapt.Op -e ,
5121279519Sbaptexcept output only the nonoverlapping changes.See Section
5122279519Sbapt.Dq Which Changes .
5123279519Sbapt.El
5124279519Sbapt.Pp
5125279519Sbapt.Sh  Invoking Xr patch
5126279519SbaptNormally
5127279519Sbapt.Xr patch
5128279519Sbaptis invoked like this:
5129279519Sbapt.Pp
5130279519Sbapt.Bd -literal -offset indent
5131279519Sbaptpatch <patchfile
5132279519Sbapt.Ed
5133279519Sbapt.Pp
5134279519SbaptThe full format for invoking
5135279519Sbapt.Xr patch
5136279519Sbaptis:
5137279519Sbapt.Pp
5138279519Sbapt.Bd -literal -offset indent
5139279519Sbaptpatch options... [origfile [patchfile]]
5140279519Sbapt.Ed
5141279519Sbapt.Pp
5142279519SbaptYou can also specify where to read the patch from with the
5143279519Sbapt.Op -i Va patchfile
5144279519Sbaptor
5145279519Sbapt.Op --input= Va patchfile
5146279519Sbaptoption. If you do not specify
5147279519Sbapt.Va patchfile ,
5148279519Sbaptor if
5149279519Sbapt.Va patchfile
5150279519Sbaptis
5151279519Sbapt.Pa - ,
5152279519Sbapt.Xr patch
5153279519Sbaptreads the patch (that is, the
5154279519Sbapt.Xr diff
5155279519Sbaptoutput) from the standard input.
5156279519Sbapt.Pp
5157279519SbaptIf you do not specify an input file on the command line,
5158279519Sbapt.Xr patch
5159279519Sbapttries to intuit from the
5160279519Sbapt.Em leading text
5161279519Sbapt(any text in the patch that comes before the
5162279519Sbapt.Xr diff
5163279519Sbaptoutput) which file to edit.See Section
5164279519Sbapt.Dq Multiple Patches .
5165279519Sbapt.Pp
5166279519SbaptBy default,
5167279519Sbapt.Xr patch
5168279519Sbaptreplaces the original input file with the patched version, possibly after
5169279519Sbaptrenaming the original file into a backup file (see Section
5170279519Sbapt.Dq Backup Names ,
5171279519Sbaptfor a description of how
5172279519Sbapt.Xr patch
5173279519Sbaptnames backup files). You can also specify where to put the output with the
5174279519Sbapt.Op -o Va file
5175279519Sbaptor
5176279519Sbapt.Op --output= Va file
5177279519Sbaptoption; however, do not use this option if
5178279519Sbapt.Va file
5179279519Sbaptis one of the input files.
5180279519Sbapt.Pp
5181279519Sbapt.Ss  Options to Xr patch
5182279519SbaptHere is a summary of all of the options that GNU
5183279519Sbapt.Xr patch
5184279519Sbaptaccepts.See Section
5185279519Sbapt.Dq patch and Tradition ,
5186279519Sbaptfor which of these options are safe to use in older versions of
5187279519Sbapt.Xr patch .
5188279519Sbapt.Pp
5189279519SbaptMultiple single-letter options that do not take an argument can be combined
5190279519Sbaptinto a single command line argument with only one dash.
5191279519Sbapt.Pp
5192279519Sbapt.Bl -tag -width Ds
5193279519Sbapt.It  -b
5194279519Sbapt.It  --backup
5195279519SbaptBack up the original contents of each file, even if backups would normally
5196279519Sbaptnot be made.See Section
5197279519Sbapt.Dq Backups .
5198279519Sbapt.Pp
5199279519Sbapt.It  -B Va prefix
5200279519Sbapt.It  --prefix= Va prefix
5201279519SbaptPrepend
5202279519Sbapt.Va prefix
5203279519Sbaptto backup file names.See Section
5204279519Sbapt.Dq Backup Names .
5205279519Sbapt.Pp
5206279519Sbapt.It  --backup-if-mismatch
5207279519SbaptBack up the original contents of each file if the patch does not exactly match
5208279519Sbaptthe file. This is the default behavior when not conforming to POSIX.See Section
5209279519Sbapt.Dq Backups .
5210279519Sbapt.Pp
5211279519Sbapt.It  --binary
5212279519SbaptRead and write all files in binary mode, except for standard output and
5213279519Sbapt.Pa /dev/tty .
5214279519SbaptThis option has no effect on POSIX-conforming systems like GNU/Linux. On systems
5215279519Sbaptwhere this option makes a difference, the patch should be generated by
5216279519Sbapt.Li diff -a --binary .
5217279519SbaptSee Section.Dq Binary .
5218279519Sbapt.Pp
5219279519Sbapt.It  -c
5220279519Sbapt.It  --context
5221279519SbaptInterpret the patch file as a context diff.See Section
5222279519Sbapt.Dq patch Input .
5223279519Sbapt.Pp
5224279519Sbapt.It  -d Va directory
5225279519Sbapt.It  --directory= Va directory
5226279519SbaptMake directory
5227279519Sbapt.Va directory
5228279519Sbaptthe current directory for interpreting both file names in the patch file,
5229279519Sbaptand file names given as arguments to other options.See Section
5230279519Sbapt.Dq patch Directories .
5231279519Sbapt.Pp
5232279519Sbapt.It  -D Va name
5233279519Sbapt.It  --ifdef= Va name
5234279519SbaptMake merged if-then-else output using
5235279519Sbapt.Va name .
5236279519SbaptSee Section.Dq If-then-else .
5237279519Sbapt.Pp
5238279519Sbapt.It  --dry-run
5239279519SbaptPrint the results of applying the patches without actually changing any files.See Section
5240279519Sbapt.Dq Dry Runs .
5241279519Sbapt.Pp
5242279519Sbapt.It  -e
5243279519Sbapt.It  --ed
5244279519SbaptInterpret the patch file as an
5245279519Sbapt.Xr ed
5246279519Sbaptscript.See Section
5247279519Sbapt.Dq patch Input .
5248279519Sbapt.Pp
5249279519Sbapt.It  -E
5250279519Sbapt.It  --remove-empty-files
5251279519SbaptRemove output files that are empty after the patches have been applied.See Section
5252279519Sbapt.Dq Creating and Removing .
5253279519Sbapt.Pp
5254279519Sbapt.It  -f
5255279519Sbapt.It  --force
5256279519SbaptAssume that the user knows exactly what he or she is doing, and do not ask
5257279519Sbaptany questions.See Section
5258279519Sbapt.Dq patch Messages .
5259279519Sbapt.Pp
5260279519Sbapt.It  -F Va lines
5261279519Sbapt.It  --fuzz= Va lines
5262279519SbaptSet the maximum fuzz factor to
5263279519Sbapt.Va lines .
5264279519SbaptSee Section.Dq Inexact .
5265279519Sbapt.Pp
5266279519Sbapt.It  -g Va num
5267279519Sbapt.It  --get= Va num
5268279519SbaptIf
5269279519Sbapt.Va num
5270279519Sbaptis positive, get input files from a revision control system as necessary;
5271279519Sbaptif zero, do not get the files; if negative, ask the user whether to get the
5272279519Sbaptfiles.See Section
5273279519Sbapt.Dq Revision Control .
5274279519Sbapt.Pp
5275279519Sbapt.It  --help
5276279519SbaptOutput a summary of usage and then exit.
5277279519Sbapt.Pp
5278279519Sbapt.It  -i Va patchfile
5279279519Sbapt.It  --input= Va patchfile
5280279519SbaptRead the patch from
5281279519Sbapt.Va patchfile
5282279519Sbaptrather than from standard input.See Section
5283279519Sbapt.Dq patch Options .
5284279519Sbapt.Pp
5285279519Sbapt.It  -l
5286279519Sbapt.It  --ignore-white-space
5287279519SbaptLet any sequence of blanks (spaces or tabs) in the patch file match any sequence
5288279519Sbaptof blanks in the input file.See Section
5289279519Sbapt.Dq Changed White Space .
5290279519Sbapt.Pp
5291279519Sbapt.It  -n
5292279519Sbapt.It  --normal
5293279519SbaptInterpret the patch file as a normal diff.See Section
5294279519Sbapt.Dq patch Input .
5295279519Sbapt.Pp
5296279519Sbapt.It  -N
5297279519Sbapt.It  --forward
5298279519SbaptIgnore patches that
5299279519Sbapt.Xr patch
5300279519Sbaptthinks are reversed or already applied. See also
5301279519Sbapt.Op -R .
5302279519SbaptSee Section.Dq Reversed Patches .
5303279519Sbapt.Pp
5304279519Sbapt.It  --no-backup-if-mismatch
5305279519SbaptDo not back up the original contents of files. This is the default behavior
5306279519Sbaptwhen conforming to POSIX.See Section
5307279519Sbapt.Dq Backups .
5308279519Sbapt.Pp
5309279519Sbapt.It  -o Va file
5310279519Sbapt.It  --output= Va file
5311279519SbaptUse
5312279519Sbapt.Va file
5313279519Sbaptas the output file name.See Section
5314279519Sbapt.Dq patch Options .
5315279519Sbapt.Pp
5316279519Sbapt.It  -p Va number
5317279519Sbapt.It  --strip= Va number
5318279519SbaptSet the file name strip count to
5319279519Sbapt.Va number .
5320279519SbaptSee Section.Dq patch Directories .
5321279519Sbapt.Pp
5322279519Sbapt.It  --posix
5323279519SbaptConform to POSIX, as if the
5324279519Sbapt.Ev POSIXLY_CORRECT
5325279519Sbaptenvironment variable had been set.See Section
5326279519Sbapt.Dq patch and POSIX .
5327279519Sbapt.Pp
5328279519Sbapt.It  --quoting-style= Va word
5329279519SbaptUse style
5330279519Sbapt.Va word
5331279519Sbaptto quote names in diagnostics, as if the
5332279519Sbapt.Ev QUOTING_STYLE
5333279519Sbaptenvironment variable had been set to
5334279519Sbapt.Va word .
5335279519SbaptSee Section.Dq patch Quoting Style .
5336279519Sbapt.Pp
5337279519Sbapt.It  -r Va reject-file
5338279519Sbapt.It  --reject-file= Va reject-file
5339279519SbaptUse
5340279519Sbapt.Va reject-file
5341279519Sbaptas the reject file name.See Section
5342279519Sbapt.Dq Reject Names .
5343279519Sbapt.Pp
5344279519Sbapt.It  -R
5345279519Sbapt.It  --reverse
5346279519SbaptAssume that this patch was created with the old and new files swapped.See Section
5347279519Sbapt.Dq Reversed Patches .
5348279519Sbapt.Pp
5349279519Sbapt.It  -s
5350279519Sbapt.It  --quiet
5351279519Sbapt.It  --silent
5352279519SbaptWork silently unless an error occurs.See Section
5353279519Sbapt.Dq patch Messages .
5354279519Sbapt.Pp
5355279519Sbapt.It  -t
5356279519Sbapt.It  --batch
5357279519SbaptDo not ask any questions.See Section
5358279519Sbapt.Dq patch Messages .
5359279519Sbapt.Pp
5360279519Sbapt.It  -T
5361279519Sbapt.It  --set-time
5362279519SbaptSet the modification and access times of patched files from time stamps given
5363279519Sbaptin context diff headers, assuming that the context diff headers use local
5364279519Sbapttime.See Section
5365279519Sbapt.Dq Patching Time Stamps .
5366279519Sbapt.Pp
5367279519Sbapt.It  -u
5368279519Sbapt.It  --unified
5369279519SbaptInterpret the patch file as a unified diff.See Section
5370279519Sbapt.Dq patch Input .
5371279519Sbapt.Pp
5372279519Sbapt.It  -v
5373279519Sbapt.It  --version
5374279519SbaptOutput version information and then exit.
5375279519Sbapt.Pp
5376279519Sbapt.It  -V Va backup-style
5377279519Sbapt.It  --version=control= Va backup-style
5378279519SbaptSelect the naming convention for backup file names.See Section
5379279519Sbapt.Dq Backup Names .
5380279519Sbapt.Pp
5381279519Sbapt.It  --verbose
5382279519SbaptPrint more diagnostics than usual.See Section
5383279519Sbapt.Dq patch Messages .
5384279519Sbapt.Pp
5385279519Sbapt.It  -x Va number
5386279519Sbapt.It  --debug= Va number
5387279519SbaptSet internal debugging flags. Of interest only to
5388279519Sbapt.Xr patch
5389279519Sbaptpatchers.
5390279519Sbapt.Pp
5391279519Sbapt.It  -Y Va prefix
5392279519Sbapt.It  --basename-prefix= Va prefix
5393279519SbaptPrepend
5394279519Sbapt.Va prefix
5395279519Sbaptto base names of backup files.See Section
5396279519Sbapt.Dq Backup Names .
5397279519Sbapt.Pp
5398279519Sbapt.It  -z Va suffix
5399279519Sbapt.It  --suffix= Va suffix
5400279519SbaptUse
5401279519Sbapt.Va suffix
5402279519Sbaptas the backup extension instead of
5403279519Sbapt.Li .orig
5404279519Sbaptor
5405279519Sbapt.Li ~ .
5406279519SbaptSee Section.Dq Backup Names .
5407279519Sbapt.Pp
5408279519Sbapt.It  -Z
5409279519Sbapt.It  --set-utc
5410279519SbaptSet the modification and access times of patched files from time stamps given
5411279519Sbaptin context diff headers, assuming that the context diff headers use UTC.See Section
5412279519Sbapt.Dq Patching Time Stamps .
5413279519Sbapt.Pp
5414279519Sbapt.El
5415279519Sbapt.Sh  Invoking Xr sdiff
5416279519SbaptThe
5417279519Sbapt.Xr sdiff
5418279519Sbaptcommand merges two files and interactively outputs the results. Its arguments
5419279519Sbaptare as follows:
5420279519Sbapt.Pp
5421279519Sbapt.Bd -literal -offset indent
5422279519Sbaptsdiff -o outfile options... from-file to-file
5423279519Sbapt.Ed
5424279519Sbapt.Pp
5425279519SbaptThis merges
5426279519Sbapt.Va from-file
5427279519Sbaptwith
5428279519Sbapt.Va to-file ,
5429279519Sbaptwith output to
5430279519Sbapt.Va outfile .
5431279519SbaptIf
5432279519Sbapt.Va from-file
5433279519Sbaptis a directory and
5434279519Sbapt.Va to-file
5435279519Sbaptis not,
5436279519Sbapt.Xr sdiff
5437279519Sbaptcompares the file in
5438279519Sbapt.Va from-file
5439279519Sbaptwhose file name is that of
5440279519Sbapt.Va to-file ,
5441279519Sbaptand vice versa.
5442279519Sbapt.Va from-file
5443279519Sbaptand
5444279519Sbapt.Va to-file
5445279519Sbaptmay not both be directories.
5446279519Sbapt.Pp
5447279519Sbapt.Xr sdiff
5448279519Sbaptoptions begin with
5449279519Sbapt.Li - ,
5450279519Sbaptso normally
5451279519Sbapt.Va from-file
5452279519Sbaptand
5453279519Sbapt.Va to-file
5454279519Sbaptmay not begin with
5455279519Sbapt.Li - .
5456279519SbaptHowever,
5457279519Sbapt.Op --
5458279519Sbaptas an argument by itself treats the remaining arguments as file names even
5459279519Sbaptif they begin with
5460279519Sbapt.Li - .
5461279519SbaptYou may not use
5462279519Sbapt.Pa -
5463279519Sbaptas an input file.
5464279519Sbapt.Pp
5465279519Sbapt.Xr sdiff
5466279519Sbaptwithout
5467279519Sbapt.Op -o
5468279519Sbapt(or
5469279519Sbapt.Op --output )
5470279519Sbaptproduces a side-by-side difference. This usage is obsolete; use the
5471279519Sbapt.Op -y
5472279519Sbaptor
5473279519Sbapt.Op --side-by-side
5474279519Sbaptoption of
5475279519Sbapt.Xr diff
5476279519Sbaptinstead.
5477279519Sbapt.Pp
5478279519SbaptAn exit status of 0 means no differences were found, 1 means some differences
5479279519Sbaptwere found, and 2 means trouble.
5480279519Sbapt.Pp
5481279519Sbapt.Ss  Options to Xr sdiff
5482279519SbaptBelow is a summary of all of the options that GNU
5483279519Sbapt.Xr sdiff
5484279519Sbaptaccepts. Each option has two equivalent names, one of which is a single letter
5485279519Sbaptpreceded by
5486279519Sbapt.Li - ,
5487279519Sbaptand the other of which is a long name preceded by
5488279519Sbapt.Li -- .
5489279519SbaptMultiple single letter options (unless they take an argument) can be combined
5490279519Sbaptinto a single command line argument. Long named options can be abbreviated
5491279519Sbaptto any unique prefix of their name.
5492279519Sbapt.Pp
5493279519Sbapt.Bl -tag -width Ds
5494279519Sbapt.It  -a
5495279519Sbapt.It  --text
5496279519SbaptTreat all files as text and compare them line-by-line, even if they do not
5497279519Sbaptappear to be text.See Section
5498279519Sbapt.Dq Binary .
5499279519Sbapt.Pp
5500279519Sbapt.It  -b
5501279519Sbapt.It  --ignore-space-change
5502279519SbaptIgnore changes in amount of white space.See Section
5503279519Sbapt.Dq White Space .
5504279519Sbapt.Pp
5505279519Sbapt.It  -B
5506279519Sbapt.It  --ignore-blank-lines
5507279519SbaptIgnore changes that just insert or delete blank lines.See Section
5508279519Sbapt.Dq Blank Lines .
5509279519Sbapt.Pp
5510279519Sbapt.It  -d
5511279519Sbapt.It  --minimal
5512279519SbaptChange the algorithm to perhaps find a smaller set of changes. This makes
5513279519Sbapt.Xr sdiff
5514279519Sbaptslower (sometimes much slower).See Section
5515279519Sbapt.Dq diff Performance .
5516279519Sbapt.Pp
5517279519Sbapt.It  --diff-program= Va program
5518279519SbaptUse the compatible comparison program
5519279519Sbapt.Va program
5520279519Sbaptto compare files instead of
5521279519Sbapt.Xr diff .
5522279519Sbapt.Pp
5523279519Sbapt.It  -E
5524279519Sbapt.It  --ignore-tab-expansion
5525279519SbaptIgnore changes due to tab expansion.See Section
5526279519Sbapt.Dq White Space .
5527279519Sbapt.Pp
5528279519Sbapt.It  --help
5529279519SbaptOutput a summary of usage and then exit.
5530279519Sbapt.Pp
5531279519Sbapt.It  -i
5532279519Sbapt.It  --ignore-case
5533279519SbaptIgnore changes in case; consider upper- and lower-case to be the same.See Section
5534279519Sbapt.Dq Case Folding .
5535279519Sbapt.Pp
5536279519Sbapt.It  -I Va regexp
5537279519Sbapt.It  --ignore-matching-lines= Va regexp
5538279519SbaptIgnore changes that just insert or delete lines that match
5539279519Sbapt.Va regexp .
5540279519SbaptSee Section.Dq Specified Lines .
5541279519Sbapt.Pp
5542279519Sbapt.It  -l
5543279519Sbapt.It  --left-column
5544279519SbaptPrint only the left column of two common lines.See Section
5545279519Sbapt.Dq Side by Side Format .
5546279519Sbapt.Pp
5547279519Sbapt.It  -o Va file
5548279519Sbapt.It  --output= Va file
5549279519SbaptPut merged output into
5550279519Sbapt.Va file .
5551279519SbaptThis option is required for merging.
5552279519Sbapt.Pp
5553279519Sbapt.It  -s
5554279519Sbapt.It  --suppress-common-lines
5555279519SbaptDo not print common lines.See Section
5556279519Sbapt.Dq Side by Side Format .
5557279519Sbapt.Pp
5558279519Sbapt.It  --speed-large-files
5559279519SbaptUse heuristics to speed handling of large files that have numerous scattered
5560279519Sbaptsmall changes.See Section
5561279519Sbapt.Dq diff Performance .
5562279519Sbapt.Pp
5563279519Sbapt.It  --strip-trailing-cr
5564279519SbaptStrip any trailing carriage return at the end of an input line.See Section
5565279519Sbapt.Dq Binary .
5566279519Sbapt.Pp
5567279519Sbapt.It  -t
5568279519Sbapt.It  --expand-tabs
5569279519SbaptExpand tabs to spaces in the output, to preserve the alignment of tabs in
5570279519Sbaptthe input files.See Section
5571279519Sbapt.Dq Tabs .
5572279519Sbapt.Pp
5573279519Sbapt.It  --tabsize= Va columns
5574279519SbaptAssume that tab stops are set every
5575279519Sbapt.Va columns
5576279519Sbapt(default 8) print columns.See Section
5577279519Sbapt.Dq Tabs .
5578279519Sbapt.Pp
5579279519Sbapt.It  -v
5580279519Sbapt.It  --version
5581279519SbaptOutput version information and then exit.
5582279519Sbapt.Pp
5583279519Sbapt.It  -w Va columns
5584279519Sbapt.It  --width= Va columns
5585279519SbaptOutput at most
5586279519Sbapt.Va columns
5587279519Sbapt(default 130) print columns per line.See Section
5588279519Sbapt.Dq Side by Side Format .
5589279519SbaptNote that for historical reasons, this option is
5590279519Sbapt.Op -W
5591279519Sbaptin
5592279519Sbapt.Xr diff ,
5593279519Sbapt.Op -w
5594279519Sbaptin
5595279519Sbapt.Xr sdiff .
5596279519Sbapt.Pp
5597279519Sbapt.It  -W
5598279519Sbapt.It  --ignore-all-space
5599279519SbaptIgnore white space when comparing lines.See Section
5600279519Sbapt.Dq White Space .
5601279519SbaptNote that for historical reasons, this option is
5602279519Sbapt.Op -w
5603279519Sbaptin
5604279519Sbapt.Xr diff ,
5605279519Sbapt.Op -W
5606279519Sbaptin
5607279519Sbapt.Xr sdiff .
5608279519Sbapt.El
5609279519Sbapt.Pp
5610279519Sbapt.Sh  Standards conformance
5611279519SbaptIn a few cases, the GNU utilities' default behavior is incompatible with the
5612279519SbaptPOSIX standard. To suppress these incompatibilities, define the
5613279519Sbapt.Ev POSIXLY_CORRECT
5614279519Sbaptenvironment variable. Unless you are checking for POSIX conformance, you probably
5615279519Sbaptdo not need to define
5616279519Sbapt.Ev POSIXLY_CORRECT .
5617279519Sbapt.Pp
5618279519SbaptNormally options and operands can appear in any order, and programs act as
5619279519Sbaptif all the options appear before any operands. For example,
5620279519Sbapt.Li diff lao tzu -C 2
5621279519Sbaptacts like
5622279519Sbapt.Li diff -C 2 lao tzu ,
5623279519Sbaptsince
5624279519Sbapt.Li 2
5625279519Sbaptis an option-argument of
5626279519Sbapt.Op -C .
5627279519SbaptHowever, if the
5628279519Sbapt.Ev POSIXLY_CORRECT
5629279519Sbaptenvironment variable is set, options must appear before operands, unless otherwise
5630279519Sbaptspecified for a particular command.
5631279519Sbapt.Pp
5632279519SbaptNewer versions of POSIX are occasionally incompatible with older versions.
5633279519SbaptFor example, older versions of POSIX allowed the command
5634279519Sbapt.Li diff -c -10
5635279519Sbaptto have the same meaning as
5636279519Sbapt.Li diff -C 10 ,
5637279519Sbaptbut POSIX 1003.1-2001
5638279519Sbapt.Li diff
5639279519Sbaptno longer allows digit-string options like
5640279519Sbapt.Op -10 .
5641279519Sbapt.Pp
5642279519SbaptThe GNU utilities normally conform to the version of POSIX that is standard
5643279519Sbaptfor your system. To cause them to conform to a different version of POSIX,
5644279519Sbaptdefine the
5645279519Sbapt.Ev _POSIX2_VERSION
5646279519Sbaptenvironment variable to a value of the form
5647279519Sbapt.Va yyyymm
5648279519Sbaptspecifying the year and month the standard was adopted. Two values are currently
5649279519Sbaptsupported for
5650279519Sbapt.Ev _POSIX2_VERSION :
5651279519Sbapt.Li 199209
5652279519Sbaptstands for POSIX 1003.2-1992, and
5653279519Sbapt.Li 200112
5654279519Sbaptstands for POSIX 1003.1-2001. For example, if you are running older software
5655279519Sbaptthat assumes an older version of POSIX and uses
5656279519Sbapt.Li diff -c -10 ,
5657279519Sbaptyou can work around the compatibility problems by setting
5658279519Sbapt.Li _POSIX2_VERSION=199209
5659279519Sbaptin your environment.
5660279519Sbapt.Pp
5661279519Sbapt.Sh  Future Projects
5662279519SbaptHere are some ideas for improving GNU
5663279519Sbapt.Xr diff
5664279519Sbaptand
5665279519Sbapt.Xr patch .
5666279519SbaptThe GNU project has identified some improvements as potential programming
5667279519Sbaptprojects for volunteers. You can also help by reporting any bugs that you
5668279519Sbaptfind.
5669279519Sbapt.Pp
5670279519SbaptIf you are a programmer and would like to contribute something to the GNU
5671279519Sbaptproject, please consider volunteering for one of these projects. If you are
5672279519Sbaptseriously contemplating work, please write to
5673279519Sbapt.Mt gvc@gnu.org
5674279519Sbaptto coordinate with other volunteers.
5675279519Sbapt.Pp
5676279519Sbapt.Ss  Suggested Projects for Improving GNU Xr diff and Xr patch
5677279519SbaptOne should be able to use GNU
5678279519Sbapt.Xr diff
5679279519Sbaptto generate a patch from any pair of directory trees, and given the patch
5680279519Sbaptand a copy of one such tree, use
5681279519Sbapt.Xr patch
5682279519Sbaptto generate a faithful copy of the other. Unfortunately, some changes to directory
5683279519Sbapttrees cannot be expressed using current patch formats; also,
5684279519Sbapt.Xr patch
5685279519Sbaptdoes not handle some of the existing formats. These shortcomings motivate
5686279519Sbaptthe following suggested projects.
5687279519Sbapt.Pp
5688279519Sbapt.Em  Handling Multibyte and Varying-Width Characters
5689279519Sbapt.Pp
5690279519Sbapt.Xr diff ,
5691279519Sbapt.Xr diff3
5692279519Sbaptand
5693279519Sbapt.Xr sdiff
5694279519Sbapttreat each line of input as a string of unibyte characters. This can mishandle
5695279519Sbaptmultibyte characters in some cases. For example, when asked to ignore spaces,
5696279519Sbapt.Xr diff
5697279519Sbaptdoes not properly ignore a multibyte space character.
5698279519Sbapt.Pp
5699279519SbaptAlso,
5700279519Sbapt.Xr diff
5701279519Sbaptcurrently assumes that each byte is one column wide, and this assumption is
5702279519Sbaptincorrect in some locales, e.g., locales that use UTF-8 encoding. This causes
5703279519Sbaptproblems with the
5704279519Sbapt.Op -y
5705279519Sbaptor
5706279519Sbapt.Op --side-by-side
5707279519Sbaptoption of
5708279519Sbapt.Xr diff .
5709279519Sbapt.Pp
5710279519SbaptThese problems need to be fixed without unduly affecting the performance of
5711279519Sbaptthe utilities in unibyte environments.
5712279519Sbapt.Pp
5713279519SbaptThe IBM GNU/Linux Technology Center Internationalization Team has proposed
5714279519Sbapt.Lk http://oss.software.ibm.com/developer/opensource/linux/patches/i18n/diffutils-2.7.2-i18n-0.1.patch.gz .
5715279519SbaptUnfortunately, these patches are incomplete and are to an older version of
5716279519Sbapt.Xr diff ,
5717279519Sbaptso more work needs to be done in this area.
5718279519Sbapt.Pp
5719279519Sbapt.Em  Handling Changes to the Directory Structure
5720279519Sbapt.Pp
5721279519Sbapt.Xr diff
5722279519Sbaptand
5723279519Sbapt.Xr patch
5724279519Sbaptdo not handle some changes to directory structure. For example, suppose one
5725279519Sbaptdirectory tree contains a directory named
5726279519Sbapt.Li D
5727279519Sbaptwith some subsidiary files, and another contains a file with the same name
5728279519Sbapt.Li D .
5729279519Sbapt.Li diff -r
5730279519Sbaptdoes not output enough information for
5731279519Sbapt.Xr patch
5732279519Sbaptto transform the directory subtree into the file.
5733279519Sbapt.Pp
5734279519SbaptThere should be a way to specify that a file has been removed without having
5735279519Sbaptto include its entire contents in the patch file. There should also be a way
5736279519Sbaptto tell
5737279519Sbapt.Xr patch
5738279519Sbaptthat a file was renamed, even if there is no way for
5739279519Sbapt.Xr diff
5740279519Sbaptto generate such information. There should be a way to tell
5741279519Sbapt.Xr patch
5742279519Sbaptthat a file's time stamp has changed, even if its contents have not changed.
5743279519Sbapt.Pp
5744279519SbaptThese problems can be fixed by extending the
5745279519Sbapt.Xr diff
5746279519Sbaptoutput format to represent changes in directory structure, and extending
5747279519Sbapt.Xr patch
5748279519Sbaptto understand these extensions.
5749279519Sbapt.Pp
5750279519Sbapt.Em  Files that are Neither Directories Nor Regular Files
5751279519Sbapt.Pp
5752279519SbaptSome files are neither directories nor regular files: they are unusual files
5753279519Sbaptlike symbolic links, device special files, named pipes, and sockets. Currently,
5754279519Sbapt.Xr diff
5755279519Sbapttreats symbolic links as if they were the pointed-to files, except that a
5756279519Sbaptrecursive
5757279519Sbapt.Xr diff
5758279519Sbaptreports an error if it detects infinite loops of symbolic links (e.g., symbolic
5759279519Sbaptlinks to
5760279519Sbapt.Pa .. ) .
5761279519Sbapt.Xr diff
5762279519Sbapttreats other special files like regular files if they are specified at the
5763279519Sbapttop level, but simply reports their presence when comparing directories. This
5764279519Sbaptmeans that
5765279519Sbapt.Xr patch
5766279519Sbaptcannot represent changes to such files. For example, if you change which file
5767279519Sbapta symbolic link points to,
5768279519Sbapt.Xr diff
5769279519Sbaptoutputs the difference between the two files, instead of the change to the
5770279519Sbaptsymbolic link.
5771279519Sbapt.Pp
5772279519Sbapt.Xr diff
5773279519Sbaptshould optionally report changes to special files specially, and
5774279519Sbapt.Xr patch
5775279519Sbaptshould be extended to understand these extensions.
5776279519Sbapt.Pp
5777279519Sbapt.Em  File Names that Contain Unusual Characters
5778279519Sbapt.Pp
5779279519SbaptWhen a file name contains an unusual character like a newline or white space,
5780279519Sbapt.Li diff -r
5781279519Sbaptgenerates a patch that
5782279519Sbapt.Xr patch
5783279519Sbaptcannot parse. The problem is with format of
5784279519Sbapt.Xr diff
5785279519Sbaptoutput, not just with
5786279519Sbapt.Xr patch ,
5787279519Sbaptbecause with odd enough file names one can cause
5788279519Sbapt.Xr diff
5789279519Sbaptto generate a patch that is syntactically correct but patches the wrong files.
5790279519SbaptThe format of
5791279519Sbapt.Xr diff
5792279519Sbaptoutput should be extended to handle all possible file names.
5793279519Sbapt.Pp
5794279519Sbapt.Em  Outputting Diffs in Time Stamp Order
5795279519Sbapt.Pp
5796279519SbaptApplying
5797279519Sbapt.Xr patch
5798279519Sbaptto a multiple-file diff can result in files whose time stamps are out of order.
5799279519SbaptGNU
5800279519Sbapt.Xr patch
5801279519Sbapthas options to restore the time stamps of the updated files (see Section
5802279519Sbapt.Dq Patching Time Stamps ) ,
5803279519Sbaptbut sometimes it is useful to generate a patch that works even if the recipient
5804279519Sbaptdoes not have GNU patch, or does not use these options. One way to do this
5805279519Sbaptwould be to implement a
5806279519Sbapt.Xr diff
5807279519Sbaptoption to output diffs in time stamp order.
5808279519Sbapt.Pp
5809279519Sbapt.Em  Ignoring Certain Changes
5810279519Sbapt.Pp
5811279519SbaptIt would be nice to have a feature for specifying two strings, one in
5812279519Sbapt.Va from-file
5813279519Sbaptand one in
5814279519Sbapt.Va to-file ,
5815279519Sbaptwhich should be considered to match. Thus, if the two strings are
5816279519Sbapt.Li foo
5817279519Sbaptand
5818279519Sbapt.Li bar ,
5819279519Sbaptthen if two lines differ only in that
5820279519Sbapt.Li foo
5821279519Sbaptin file 1 corresponds to
5822279519Sbapt.Li bar
5823279519Sbaptin file 2, the lines are treated as identical.
5824279519Sbapt.Pp
5825279519SbaptIt is not clear how general this feature can or should be, or what syntax
5826279519Sbaptshould be used for it.
5827279519Sbapt.Pp
5828279519SbaptA partial substitute is to filter one or both files before comparing, e.g.:
5829279519Sbapt.Pp
5830279519Sbapt.Bd -literal -offset indent
5831279519Sbaptsed 's/foo/bar/g' file1 | diff - file2
5832279519Sbapt.Ed
5833279519Sbapt.Pp
5834279519SbaptHowever, this outputs the filtered text, not the original.
5835279519Sbapt.Pp
5836279519Sbapt.Em  Improving Performance
5837279519Sbapt.Pp
5838279519SbaptWhen comparing two large directory structures, one of which was originally
5839279519Sbaptcopied from the other with time stamps preserved (e.g., with
5840279519Sbapt.Li cp -pR ) ,
5841279519Sbaptit would greatly improve performance if an option told
5842279519Sbapt.Xr diff
5843279519Sbaptto assume that two files with the same size and time stamps have the same
5844279519Sbaptcontent.See Section
5845279519Sbapt.Dq diff Performance .
5846279519Sbapt.Pp
5847279519Sbapt.Ss  Reporting Bugs
5848279519SbaptIf you think you have found a bug in GNU
5849279519Sbapt.Xr cmp ,
5850279519Sbapt.Xr diff ,
5851279519Sbapt.Xr diff3 ,
5852279519Sbaptor
5853279519Sbapt.Xr sdiff ,
5854279519Sbaptplease report it by electronic mail to the
5855279519Sbapt.Lk http://mail.gnu.org/mailman/listinfo/bug-gnu-utils
5856279519Sbapt.Mt bug-gnu-utils@gnu.org .
5857279519SbaptPlease send bug reports for GNU
5858279519Sbapt.Xr patch
5859279519Sbaptto
5860279519Sbapt.Mt bug-patch@gnu.org .
5861279519SbaptSend as precise a description of the problem as you can, including the output
5862279519Sbaptof the
5863279519Sbapt.Op --version
5864279519Sbaptoption and sample input files that produce the bug, if applicable. If you
5865279519Sbapthave a nontrivial fix for the bug, please send it as well. If you have a patch,
5866279519Sbaptplease send it too. It may simplify the maintainer's job if the patch is relative
5867279519Sbaptto a recent test release, which you can find in the directory
5868279519Sbapt.Lk ftp://alpha.gnu.org/gnu/diffutils/ .
5869279519Sbapt.Pp
5870279519Sbapt.Sh  Copying This Manual
5871279519Sbapt.Ss  GNU Free Documentation License
5872279519Sbapt.Bd -filled -offset indent
5873279519SbaptCopyright \(co 2000,2001,2002 Free Software Foundation, Inc. 59 Temple Place,
5874279519SbaptSuite 330, Boston, MA 02111-1307, USA
5875279519Sbapt.Pp
5876279519SbaptEveryone is permitted to copy and distribute verbatim copies of this license
5877279519Sbaptdocument, but changing it is not allowed.
5878279519Sbapt.Ed
5879279519Sbapt.Pp
5880279519Sbapt.Bl -enum
5881279519Sbapt.It
5882279519SbaptPREAMBLE
5883279519Sbapt.Pp
5884279519SbaptThe purpose of this License is to make a manual, textbook, or other functional
5885279519Sbaptand useful document
5886279519Sbapt.Em free
5887279519Sbaptin the sense of freedom: to assure everyone the effective freedom to copy
5888279519Sbaptand redistribute it, with or without modifying it, either commercially or
5889279519Sbaptnoncommercially. Secondarily, this License preserves for the author and publisher
5890279519Sbapta way to get credit for their work, while not being considered responsible
5891279519Sbaptfor modifications made by others.
5892279519Sbapt.Pp
5893279519SbaptThis License is a kind of \(lqcopyleft\(rq, which means that derivative works of the
5894279519Sbaptdocument must themselves be free in the same sense. It complements the GNU
5895279519SbaptGeneral Public License, which is a copyleft license designed for free software.
5896279519Sbapt.Pp
5897279519SbaptWe have designed this License in order to use it for manuals for free software,
5898279519Sbaptbecause free software needs free documentation: a free program should come
5899279519Sbaptwith manuals providing the same freedoms that the software does. But this
5900279519SbaptLicense is not limited to software manuals; it can be used for any textual
5901279519Sbaptwork, regardless of subject matter or whether it is published as a printed
5902279519Sbaptbook. We recommend this License principally for works whose purpose is instruction
5903279519Sbaptor reference.
5904279519Sbapt.Pp
5905279519Sbapt.It
5906279519SbaptAPPLICABILITY AND DEFINITIONS
5907279519Sbapt.Pp
5908279519SbaptThis License applies to any manual or other work, in any medium, that contains
5909279519Sbapta notice placed by the copyright holder saying it can be distributed under
5910279519Sbaptthe terms of this License. Such a notice grants a world-wide, royalty-free
5911279519Sbaptlicense, unlimited in duration, to use that work under the conditions stated
5912279519Sbaptherein. The \(lqDocument\(rq, below, refers to any such manual or work. Any member
5913279519Sbaptof the public is a licensee, and is addressed as \(lqyou\(rq. You accept the license
5914279519Sbaptif you copy, modify or distribute the work in a way requiring permission under
5915279519Sbaptcopyright law.
5916279519Sbapt.Pp
5917279519SbaptA \(lqModified Version\(rq of the Document means any work containing the Document
5918279519Sbaptor a portion of it, either copied verbatim, or with modifications and/or translated
5919279519Sbaptinto another language.
5920279519Sbapt.Pp
5921279519SbaptA \(lqSecondary Section\(rq is a named appendix or a front-matter section of the Document
5922279519Sbaptthat deals exclusively with the relationship of the publishers or authors
5923279519Sbaptof the Document to the Document's overall subject (or to related matters)
5924279519Sbaptand contains nothing that could fall directly within that overall subject.
5925279519Sbapt(Thus, if the Document is in part a textbook of mathematics, a Secondary Section
5926279519Sbaptmay not explain any mathematics.) The relationship could be a matter of historical
5927279519Sbaptconnection with the subject or with related matters, or of legal, commercial,
5928279519Sbaptphilosophical, ethical or political position regarding them.
5929279519Sbapt.Pp
5930279519SbaptThe \(lqInvariant Sections\(rq are certain Secondary Sections whose titles are designated,
5931279519Sbaptas being those of Invariant Sections, in the notice that says that the Document
5932279519Sbaptis released under this License. If a section does not fit the above definition
5933279519Sbaptof Secondary then it is not allowed to be designated as Invariant. The Document
5934279519Sbaptmay contain zero Invariant Sections. If the Document does not identify any
5935279519SbaptInvariant Sections then there are none.
5936279519Sbapt.Pp
5937279519SbaptThe \(lqCover Texts\(rq are certain short passages of text that are listed, as Front-Cover
5938279519SbaptTexts or Back-Cover Texts, in the notice that says that the Document is released
5939279519Sbaptunder this License. A Front-Cover Text may be at most 5 words, and a Back-Cover
5940279519SbaptText may be at most 25 words.
5941279519Sbapt.Pp
5942279519SbaptA \(lqTransparent\(rq copy of the Document means a machine-readable copy, represented
5943279519Sbaptin a format whose specification is available to the general public, that is
5944279519Sbaptsuitable for revising the document straightforwardly with generic text editors
5945279519Sbaptor (for images composed of pixels) generic paint programs or (for drawings)
5946279519Sbaptsome widely available drawing editor, and that is suitable for input to text
5947279519Sbaptformatters or for automatic translation to a variety of formats suitable for
5948279519Sbaptinput to text formatters. A copy made in an otherwise Transparent file format
5949279519Sbaptwhose markup, or absence of markup, has been arranged to thwart or discourage
5950279519Sbaptsubsequent modification by readers is not Transparent. An image format is
5951279519Sbaptnot Transparent if used for any substantial amount of text. A copy that is
5952279519Sbaptnot \(lqTransparent\(rq is called \(lqOpaque\(rq.
5953279519Sbapt.Pp
5954279519SbaptExamples of suitable formats for Transparent copies include plain ascii without
5955279519Sbaptmarkup, Texinfo input format, LaTeX input format, SGML or XML using a publicly
5956279519Sbaptavailable DTD, and standard-conforming simple HTML, PostScript or PDF designed
5957279519Sbaptfor human modification. Examples of transparent image formats include PNG,
5958279519SbaptXCF and JPG. Opaque formats include proprietary formats that can be read and
5959279519Sbaptedited only by proprietary word processors, SGML or XML for which the DTD
5960279519Sbaptand/or processing tools are not generally available, and the machine-generated
5961279519SbaptHTML, PostScript or PDF produced by some word processors for output purposes
5962279519Sbaptonly.
5963279519Sbapt.Pp
5964279519SbaptThe \(lqTitle Page\(rq means, for a printed book, the title page itself, plus such
5965279519Sbaptfollowing pages as are needed to hold, legibly, the material this License
5966279519Sbaptrequires to appear in the title page. For works in formats which do not have
5967279519Sbaptany title page as such, \(lqTitle Page\(rq means the text near the most prominent
5968279519Sbaptappearance of the work's title, preceding the beginning of the body of the
5969279519Sbapttext.
5970279519Sbapt.Pp
5971279519SbaptA section \(lqEntitled XYZ\(rq means a named subunit of the Document whose title either
5972279519Sbaptis precisely XYZ or contains XYZ in parentheses following text that translates
5973279519SbaptXYZ in another language. (Here XYZ stands for a specific section name mentioned
5974279519Sbaptbelow, such as \(lqAcknowledgements\(rq, \(lqDedications\(rq, \(lqEndorsements\(rq, or \(lqHistory\(rq.) To
5975279519Sbapt\(lqPreserve the Title\(rq of such a section when you modify the Document means that
5976279519Sbaptit remains a section \(lqEntitled XYZ\(rq according to this definition.
5977279519Sbapt.Pp
5978279519SbaptThe Document may include Warranty Disclaimers next to the notice which states
5979279519Sbaptthat this License applies to the Document. These Warranty Disclaimers are
5980279519Sbaptconsidered to be included by reference in this License, but only as regards
5981279519Sbaptdisclaiming warranties: any other implication that these Warranty Disclaimers
5982279519Sbaptmay have is void and has no effect on the meaning of this License.
5983279519Sbapt.Pp
5984279519Sbapt.It
5985279519SbaptVERBATIM COPYING
5986279519Sbapt.Pp
5987279519SbaptYou may copy and distribute the Document in any medium, either commercially
5988279519Sbaptor noncommercially, provided that this License, the copyright notices, and
5989279519Sbaptthe license notice saying this License applies to the Document are reproduced
5990279519Sbaptin all copies, and that you add no other conditions whatsoever to those of
5991279519Sbaptthis License. You may not use technical measures to obstruct or control the
5992279519Sbaptreading or further copying of the copies you make or distribute. However,
5993279519Sbaptyou may accept compensation in exchange for copies. If you distribute a large
5994279519Sbaptenough number of copies you must also follow the conditions in section 3.
5995279519Sbapt.Pp
5996279519SbaptYou may also lend copies, under the same conditions stated above, and you
5997279519Sbaptmay publicly display copies.
5998279519Sbapt.Pp
5999279519Sbapt.It
6000279519SbaptCOPYING IN QUANTITY
6001279519Sbapt.Pp
6002279519SbaptIf you publish printed copies (or copies in media that commonly have printed
6003279519Sbaptcovers) of the Document, numbering more than 100, and the Document's license
6004279519Sbaptnotice requires Cover Texts, you must enclose the copies in covers that carry,
6005279519Sbaptclearly and legibly, all these Cover Texts: Front-Cover Texts on the front
6006279519Sbaptcover, and Back-Cover Texts on the back cover. Both covers must also clearly
6007279519Sbaptand legibly identify you as the publisher of these copies. The front cover
6008279519Sbaptmust present the full title with all words of the title equally prominent
6009279519Sbaptand visible. You may add other material on the covers in addition. Copying
6010279519Sbaptwith changes limited to the covers, as long as they preserve the title of
6011279519Sbaptthe Document and satisfy these conditions, can be treated as verbatim copying
6012279519Sbaptin other respects.
6013279519Sbapt.Pp
6014279519SbaptIf the required texts for either cover are too voluminous to fit legibly,
6015279519Sbaptyou should put the first ones listed (as many as fit reasonably) on the actual
6016279519Sbaptcover, and continue the rest onto adjacent pages.
6017279519Sbapt.Pp
6018279519SbaptIf you publish or distribute Opaque copies of the Document numbering more
6019279519Sbaptthan 100, you must either include a machine-readable Transparent copy along
6020279519Sbaptwith each Opaque copy, or state in or with each Opaque copy a computer-network
6021279519Sbaptlocation from which the general network-using public has access to download
6022279519Sbaptusing public-standard network protocols a complete Transparent copy of the
6023279519SbaptDocument, free of added material. If you use the latter option, you must take
6024279519Sbaptreasonably prudent steps, when you begin distribution of Opaque copies in
6025279519Sbaptquantity, to ensure that this Transparent copy will remain thus accessible
6026279519Sbaptat the stated location until at least one year after the last time you distribute
6027279519Sbaptan Opaque copy (directly or through your agents or retailers) of that edition
6028279519Sbaptto the public.
6029279519Sbapt.Pp
6030279519SbaptIt is requested, but not required, that you contact the authors of the Document
6031279519Sbaptwell before redistributing any large number of copies, to give them a chance
6032279519Sbaptto provide you with an updated version of the Document.
6033279519Sbapt.Pp
6034279519Sbapt.It
6035279519SbaptMODIFICATIONS
6036279519Sbapt.Pp
6037279519SbaptYou may copy and distribute a Modified Version of the Document under the conditions
6038279519Sbaptof sections 2 and 3 above, provided that you release the Modified Version
6039279519Sbaptunder precisely this License, with the Modified Version filling the role of
6040279519Sbaptthe Document, thus licensing distribution and modification of the Modified
6041279519SbaptVersion to whoever possesses a copy of it. In addition, you must do these
6042279519Sbaptthings in the Modified Version:
6043279519Sbapt.Pp
6044279519Sbapt.Bl -enum
6045279519Sbapt.It
6046279519SbaptUse in the Title Page (and on the covers, if any) a title distinct from that
6047279519Sbaptof the Document, and from those of previous versions (which should, if there
6048279519Sbaptwere any, be listed in the History section of the Document). You may use the
6049279519Sbaptsame title as a previous version if the original publisher of that version
6050279519Sbaptgives permission.
6051279519Sbapt.Pp
6052279519Sbapt.It
6053279519SbaptList on the Title Page, as authors, one or more persons or entities responsible
6054279519Sbaptfor authorship of the modifications in the Modified Version, together with
6055279519Sbaptat least five of the principal authors of the Document (all of its principal
6056279519Sbaptauthors, if it has fewer than five), unless they release you from this requirement.
6057279519Sbapt.Pp
6058279519Sbapt.It
6059279519SbaptState on the Title page the name of the publisher of the Modified Version,
6060279519Sbaptas the publisher.
6061279519Sbapt.Pp
6062279519Sbapt.It
6063279519SbaptPreserve all the copyright notices of the Document.
6064279519Sbapt.Pp
6065279519Sbapt.It
6066279519SbaptAdd an appropriate copyright notice for your modifications adjacent to the
6067279519Sbaptother copyright notices.
6068279519Sbapt.Pp
6069279519Sbapt.It
6070279519SbaptInclude, immediately after the copyright notices, a license notice giving
6071279519Sbaptthe public permission to use the Modified Version under the terms of this
6072279519SbaptLicense, in the form shown in the Addendum below.
6073279519Sbapt.Pp
6074279519Sbapt.It
6075279519SbaptPreserve in that license notice the full lists of Invariant Sections and required
6076279519SbaptCover Texts given in the Document's license notice.
6077279519Sbapt.Pp
6078279519Sbapt.It
6079279519SbaptInclude an unaltered copy of this License.
6080279519Sbapt.Pp
6081279519Sbapt.It
6082279519SbaptPreserve the section Entitled \(lqHistory\(rq, Preserve its Title, and add to it an
6083279519Sbaptitem stating at least the title, year, new authors, and publisher of the Modified
6084279519SbaptVersion as given on the Title Page. If there is no section Entitled \(lqHistory\(rq
6085279519Sbaptin the Document, create one stating the title, year, authors, and publisher
6086279519Sbaptof the Document as given on its Title Page, then add an item describing the
6087279519SbaptModified Version as stated in the previous sentence.
6088279519Sbapt.Pp
6089279519Sbapt.It
6090279519SbaptPreserve the network location, if any, given in the Document for public access
6091279519Sbaptto a Transparent copy of the Document, and likewise the network locations
6092279519Sbaptgiven in the Document for previous versions it was based on. These may be
6093279519Sbaptplaced in the \(lqHistory\(rq section. You may omit a network location for a work
6094279519Sbaptthat was published at least four years before the Document itself, or if the
6095279519Sbaptoriginal publisher of the version it refers to gives permission.
6096279519Sbapt.Pp
6097279519Sbapt.It
6098279519SbaptFor any section Entitled \(lqAcknowledgements\(rq or \(lqDedications\(rq, Preserve the Title
6099279519Sbaptof the section, and preserve in the section all the substance and tone of
6100279519Sbapteach of the contributor acknowledgements and/or dedications given therein.
6101279519Sbapt.Pp
6102279519Sbapt.It
6103279519SbaptPreserve all the Invariant Sections of the Document, unaltered in their text
6104279519Sbaptand in their titles. Section numbers or the equivalent are not considered
6105279519Sbaptpart of the section titles.
6106279519Sbapt.Pp
6107279519Sbapt.It
6108279519SbaptDelete any section Entitled \(lqEndorsements\(rq. Such a section may not be included
6109279519Sbaptin the Modified Version.
6110279519Sbapt.Pp
6111279519Sbapt.It
6112279519SbaptDo not retitle any existing section to be Entitled \(lqEndorsements\(rq or to conflict
6113279519Sbaptin title with any Invariant Section.
6114279519Sbapt.Pp
6115279519Sbapt.It
6116279519SbaptPreserve any Warranty Disclaimers.
6117279519Sbapt.El
6118279519Sbapt.Pp
6119279519SbaptIf the Modified Version includes new front-matter sections or appendices that
6120279519Sbaptqualify as Secondary Sections and contain no material copied from the Document,
6121279519Sbaptyou may at your option designate some or all of these sections as invariant.
6122279519SbaptTo do this, add their titles to the list of Invariant Sections in the Modified
6123279519SbaptVersion's license notice. These titles must be distinct from any other section
6124279519Sbapttitles.
6125279519Sbapt.Pp
6126279519SbaptYou may add a section Entitled \(lqEndorsements\(rq, provided it contains nothing
6127279519Sbaptbut endorsements of your Modified Version by various parties---for example,
6128279519Sbaptstatements of peer review or that the text has been approved by an organization
6129279519Sbaptas the authoritative definition of a standard.
6130279519Sbapt.Pp
6131279519SbaptYou may add a passage of up to five words as a Front-Cover Text, and a passage
6132279519Sbaptof up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts
6133279519Sbaptin the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover
6134279519SbaptText may be added by (or through arrangements made by) any one entity. If
6135279519Sbaptthe Document already includes a cover text for the same cover, previously
6136279519Sbaptadded by you or by arrangement made by the same entity you are acting on behalf
6137279519Sbaptof, you may not add another; but you may replace the old one, on explicit
6138279519Sbaptpermission from the previous publisher that added the old one.
6139279519Sbapt.Pp
6140279519SbaptThe author(s) and publisher(s) of the Document do not by this License give
6141279519Sbaptpermission to use their names for publicity for or to assert or imply endorsement
6142279519Sbaptof any Modified Version.
6143279519Sbapt.Pp
6144279519Sbapt.It
6145279519SbaptCOMBINING DOCUMENTS
6146279519Sbapt.Pp
6147279519SbaptYou may combine the Document with other documents released under this License,
6148279519Sbaptunder the terms defined in section 4 above for modified versions, provided
6149279519Sbaptthat you include in the combination all of the Invariant Sections of all of
6150279519Sbaptthe original documents, unmodified, and list them all as Invariant Sections
6151279519Sbaptof your combined work in its license notice, and that you preserve all their
6152279519SbaptWarranty Disclaimers.
6153279519Sbapt.Pp
6154279519SbaptThe combined work need only contain one copy of this License, and multiple
6155279519Sbaptidentical Invariant Sections may be replaced with a single copy. If there
6156279519Sbaptare multiple Invariant Sections with the same name but different contents,
6157279519Sbaptmake the title of each such section unique by adding at the end of it, in
6158279519Sbaptparentheses, the name of the original author or publisher of that section
6159279519Sbaptif known, or else a unique number. Make the same adjustment to the section
6160279519Sbapttitles in the list of Invariant Sections in the license notice of the combined
6161279519Sbaptwork.
6162279519Sbapt.Pp
6163279519SbaptIn the combination, you must combine any sections Entitled \(lqHistory\(rq in the
6164279519Sbaptvarious original documents, forming one section Entitled \(lqHistory\(rq; likewise
6165279519Sbaptcombine any sections Entitled \(lqAcknowledgements\(rq, and any sections Entitled
6166279519Sbapt\(lqDedications\(rq. You must delete all sections Entitled \(lqEndorsements.\(rq
6167279519Sbapt.Pp
6168279519Sbapt.It
6169279519SbaptCOLLECTIONS OF DOCUMENTS
6170279519Sbapt.Pp
6171279519SbaptYou may make a collection consisting of the Document and other documents released
6172279519Sbaptunder this License, and replace the individual copies of this License in the
6173279519Sbaptvarious documents with a single copy that is included in the collection, provided
6174279519Sbaptthat you follow the rules of this License for verbatim copying of each of
6175279519Sbaptthe documents in all other respects.
6176279519Sbapt.Pp
6177279519SbaptYou may extract a single document from such a collection, and distribute it
6178279519Sbaptindividually under this License, provided you insert a copy of this License
6179279519Sbaptinto the extracted document, and follow this License in all other respects
6180279519Sbaptregarding verbatim copying of that document.
6181279519Sbapt.Pp
6182279519Sbapt.It
6183279519SbaptAGGREGATION WITH INDEPENDENT WORKS
6184279519Sbapt.Pp
6185279519SbaptA compilation of the Document or its derivatives with other separate and independent
6186279519Sbaptdocuments or works, in or on a volume of a storage or distribution medium,
6187279519Sbaptis called an \(lqaggregate\(rq if the copyright resulting from the compilation is
6188279519Sbaptnot used to limit the legal rights of the compilation's users beyond what
6189279519Sbaptthe individual works permit. When the Document is included in an aggregate,
6190279519Sbaptthis License does not apply to the other works in the aggregate which are
6191279519Sbaptnot themselves derivative works of the Document.
6192279519Sbapt.Pp
6193279519SbaptIf the Cover Text requirement of section 3 is applicable to these copies of
6194279519Sbaptthe Document, then if the Document is less than one half of the entire aggregate,
6195279519Sbaptthe Document's Cover Texts may be placed on covers that bracket the Document
6196279519Sbaptwithin the aggregate, or the electronic equivalent of covers if the Document
6197279519Sbaptis in electronic form. Otherwise they must appear on printed covers that bracket
6198279519Sbaptthe whole aggregate.
6199279519Sbapt.Pp
6200279519Sbapt.It
6201279519SbaptTRANSLATION
6202279519Sbapt.Pp
6203279519SbaptTranslation is considered a kind of modification, so you may distribute translations
6204279519Sbaptof the Document under the terms of section 4. Replacing Invariant Sections
6205279519Sbaptwith translations requires special permission from their copyright holders,
6206279519Sbaptbut you may include translations of some or all Invariant Sections in addition
6207279519Sbaptto the original versions of these Invariant Sections. You may include a translation
6208279519Sbaptof this License, and all the license notices in the Document, and any Warranty
6209279519SbaptDisclaimers, provided that you also include the original English version of
6210279519Sbaptthis License and the original versions of those notices and disclaimers. In
6211279519Sbaptcase of a disagreement between the translation and the original version of
6212279519Sbaptthis License or a notice or disclaimer, the original version will prevail.
6213279519Sbapt.Pp
6214279519SbaptIf a section in the Document is Entitled \(lqAcknowledgements\(rq, \(lqDedications\(rq, or
6215279519Sbapt\(lqHistory\(rq, the requirement (section 4) to Preserve its Title (section 1) will
6216279519Sbapttypically require changing the actual title.
6217279519Sbapt.Pp
6218279519Sbapt.It
6219279519SbaptTERMINATION
6220279519Sbapt.Pp
6221279519SbaptYou may not copy, modify, sublicense, or distribute the Document except as
6222279519Sbaptexpressly provided for under this License. Any other attempt to copy, modify,
6223279519Sbaptsublicense or distribute the Document is void, and will automatically terminate
6224279519Sbaptyour rights under this License. However, parties who have received copies,
6225279519Sbaptor rights, from you under this License will not have their licenses terminated
6226279519Sbaptso long as such parties remain in full compliance.
6227279519Sbapt.Pp
6228279519Sbapt.It
6229279519SbaptFUTURE REVISIONS OF THIS LICENSE
6230279519Sbapt.Pp
6231279519SbaptThe Free Software Foundation may publish new, revised versions of the GNU
6232279519SbaptFree Documentation License from time to time. Such new versions will be similar
6233279519Sbaptin spirit to the present version, but may differ in detail to address new
6234279519Sbaptproblems or concerns. See
6235279519Sbapt.Lk http://www.gnu.org/copyleft/ .
6236279519Sbapt.Pp
6237279519SbaptEach version of the License is given a distinguishing version number. If the
6238279519SbaptDocument specifies that a particular numbered version of this License \(lqor any
6239279519Sbaptlater version\(rq applies to it, you have the option of following the terms and
6240279519Sbaptconditions either of that specified version or of any later version that has
6241279519Sbaptbeen published (not as a draft) by the Free Software Foundation. If the Document
6242279519Sbaptdoes not specify a version number of this License, you may choose any version
6243279519Sbaptever published (not as a draft) by the Free Software Foundation.
6244279519Sbapt.El
6245279519Sbapt.Pp
6246279519Sbapt.Em  ADDENDUM: How to use this License for your documents
6247279519Sbapt.Pp
6248279519SbaptTo use this License in a document you have written, include a copy of the
6249279519SbaptLicense in the document and put the following copyright and license notices
6250279519Sbaptjust after the title page:
6251279519Sbapt.Pp
6252279519Sbapt.Bd -literal -offset indent
6253279519Sbapt
6254279519Sbapt  Copyright (C)  year  your name.
6255279519Sbapt  Permission is granted to copy, distribute and/or modify this document
6256279519Sbapt  under the terms of the GNU Free Documentation License, Version 1.2
6257279519Sbapt  or any later version published by the Free Software Foundation;
6258279519Sbapt  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
6259279519Sbapt  Texts.  A copy of the license is included in the section entitled \(lqGNU
6260279519Sbapt  Free Documentation License\(rq.
6261279519Sbapt
6262279519Sbapt.Ed
6263279519Sbapt.Pp
6264279519SbaptIf you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace
6265279519Sbaptthe \(lqwith...Texts.\(rq line with this:
6266279519Sbapt.Pp
6267279519Sbapt.Bd -literal -offset indent
6268279519Sbapt
6269279519Sbapt    with the Invariant Sections being list their titles, with
6270279519Sbapt    the Front-Cover Texts being list, and with the Back-Cover Texts
6271279519Sbapt    being list.
6272279519Sbapt
6273279519Sbapt.Ed
6274279519Sbapt.Pp
6275279519SbaptIf you have Invariant Sections without Cover Texts, or some other combination
6276279519Sbaptof the three, merge those two alternatives to suit the situation.
6277279519Sbapt.Pp
6278279519SbaptIf your document contains nontrivial examples of program code, we recommend
6279279519Sbaptreleasing these examples in parallel under your choice of free software license,
6280279519Sbaptsuch as the GNU General Public License, to permit their use in free software.
6281279519Sbapt.Pp
6282279519Sbapt.Sh  Translations of This Manual
6283279519SbaptNishio Futoshi of the GNUjdoc project has prepared a Japanese translation
6284279519Sbaptof this manual. Its most recent version can be found at
6285279519Sbapt.Lk http://openlab.ring.gr.jp/gnujdoc/cvsweb/cvsweb.cgi/gnujdoc/ .
6286279519Sbapt.Pp
6287279519Sbapt.Sh  Index
6288