Lines Matching refs:diff

3 @setfilename diff.info
9 This file documents the the GNU @code{diff}, @code{diff3}, @code{sdiff},
39 @subtitle @code{diff}, @code{diff3}, @code{sdiff}, @code{cmp}, and @code{patch}
40 @subtitle Edition 1.3, for @code{diff} 2.5 and @code{patch} 2.1
66 This file documents the the GNU @code{diff}, @code{diff3}, @code{sdiff},
70 This is Edition 1.2, for @code{diff} 2.4 and @code{patch} 2.1.
79 * Adjusting Output:: Making @code{diff} output prettier.
80 * diff Performance:: Making @code{diff} smarter or faster.
89 * Invoking diff:: How to run @code{diff} and a summary of its options.
102 @cindex overview of @code{diff} and @code{patch}
108 You can use the @code{diff} command to show differences between two
109 files, or each corresponding file in two directories. @code{diff}
112 often called a @dfn{diff} or @dfn{patch}. For files that are identical,
113 @code{diff} normally produces no output; for binary (non-text) files,
114 @code{diff} normally reports only that they are different.
131 You can use the set of differences produced by @code{diff} to distribute
134 to the complete files. Given @code{diff} output, you can use the
136 think of @code{diff} as subtracting one file from another to produce
143 GNU @code{diff} was written by Mike Haertel, David Hayes, Richard
162 @c in GNU diff.
180 file. @code{diff} compares two files line by line, finds groups of
185 GNU @code{diff} can show whether files are different without detailing
189 lines. @code{diff} also provides ways to suppress differences in
198 more useful than @code{diff} for comparing binary files. For text
206 that lacks the newline at the beginning, @code{diff} will report that a
229 When comparing two files, @code{diff} finds sequences of lines common to
235 match up lines between two given files. @code{diff} tries to minimize
242 @code{diff} finds the line @samp{c} as common, then the command
243 @samp{diff F G} produces this output:
255 But if @code{diff} notices the common line @samp{b} instead, it produces
270 It is also possible to find @samp{a} as the common line. @code{diff}
274 @samp{--minimal} option (@pxref{diff Performance}).
284 @code{diff} considers the following two lines to be equivalent, where
297 With these options, @code{diff} considers the
335 GNU @code{diff} can treat lowercase letters as equivalent to their
348 shell from expanding them. For example, @samp{diff -I '^[0-9]'} ignores
354 words, for each nonignorable change, @code{diff} prints the complete set
358 using more than one @samp{-I} option. @code{diff} tries to match each
369 files, @code{diff} simply reports whether files differ. The @samp{-q}
374 comparisons, because @code{diff} can stop analyzing the files as soon as
386 Unlike @code{diff}, @code{cmp} cannot compare directories; it can only
391 @cindex binary file diff
392 @cindex text versus binary diff
394 If @code{diff} thinks that either of the two files it is comparing is
400 @code{diff} determines whether a file is text or binary by checking the
403 that part of the file is non-null, @code{diff} considers the file to be
406 Sometimes you might want to force @code{diff} to consider files to be
408 null characters; @code{diff} would erroneously decide that those are
411 indicate special formatting. You can force @code{diff} to consider all
415 newline characters, and the @code{diff} output will consist of hunks
419 You can also force @code{diff} to consider all files to be binary files,
424 @code{diff} normally reads and writes all data as text. Use the
425 @samp{--binary} option to force @code{diff} to read and write binary
429 followed by a newline. On such systems, @code{diff} normally ignores
431 output line, but with the @samp{--binary} option @code{diff} treats
446 @code{diff} to decide whether a file is binary. As with @code{diff}, if
453 @chapter @code{diff} Output Formats
455 @cindex format of @code{diff} output
457 @code{diff} has several mutually exclusive options for output format.
459 @code{diff} reports the differences between two sample input files.
462 * Sample diff Input:: Sample @code{diff} input files for examples.
470 @node Sample diff Input, Normal, , Output Formats
472 @cindex @code{diff} sample input
473 @cindex sample input for @code{diff}
476 illustrate the output of @code{diff} and how various options can change
518 @node Normal, Context, Sample diff Input, Output Formats
523 The ``normal'' @code{diff} output format shows each hunk of differences
531 compatibility with older versions of @code{diff} and the Posix standard.
586 Here is the output of the command @samp{diff lao tzu}
587 (@pxref{Sample diff Input}, for the complete contents of the two files).
616 GNU @code{diff} provides two output formats that show context around the
622 form of @code{diff} output, you should use one of the output formats
627 lines away from where the diff says they are, @code{patch} can adjust
628 the line numbers accordingly and still apply the diff correctly.
713 Here is the output of @samp{diff -c lao tzu} (@pxref{Sample diff Input},
752 Here is the output of @samp{diff --context=1 lao tzu} (@pxref{Sample
753 diff Input}, for the complete contents of the two files). Notice that
792 At present, only GNU @code{diff} can produce this format and only GNU
840 Here is the output of the command @samp{diff -u lao tzu}
841 (@pxref{Sample diff Input}, for the complete contents of the two files):
873 appendix was changed. GNU @code{diff} can show this by displaying the
889 or @samp{--show-function-line=@var{regexp}} option. @code{diff}
916 regular expression for such lines; @code{diff} tries to match each line
935 @samp{-c -F'^[_a-zA-Z$]'} (@pxref{Specified Headings}). GNU @code{diff}
944 names, you might want @code{diff} to show alternate names in the header
950 twice, @code{diff} reports an error. The @samp{-L} option does not
954 Here are the first two lines of the output from @samp{diff -C2
968 @code{diff} can produce a side by side difference listing of two files.
1043 Here is the output of the command @samp{diff -y -W 72 lao tzu}
1044 (@pxref{Sample diff Input}, for the complete contents of the two files).
1072 * ed Scripts:: Using @code{diff} to produce commands for @code{ed}.
1074 * RCS:: A special @code{diff} output format used by RCS.
1081 @code{diff} can produce commands that direct the @code{ed} text editor
1089 information necessary to apply the diff in reverse (to produce the first
1090 file if all you have is the second file and the diff).
1092 If the file @file{d} contains the output of @samp{diff -e old new}, then
1095 @dots{}, @file{dN} contain the outputs of @samp{diff -e old new1},
1096 @samp{diff -e new1 new2}, @dots{}, @samp{diff -e newN-1 newN},
1122 input, GNU @code{diff} protects lines of changes that contain a single
1126 file ends in a changed incomplete line, @code{diff} reports an error and
1155 Here is the output of @samp{diff -e lao tzu} (@pxref{Sample
1156 diff Input}, for the complete contents of the two files):
1175 @code{diff} can produce output that is like an @code{ed} script, but
1185 compatibility with older versions of @code{diff}. Use the @samp{-f} or
1206 Here is the output of @samp{diff -n lao tzu} (@pxref{Sample
1207 diff Input}, for the complete contents of the two files):
1228 You can use @code{diff} to merge two files of C source code. The output
1229 of @code{diff} in this format contains all the lines of both files.
1236 To merge two files, use @code{diff} with the @samp{-D @var{name}} or
1283 diff \
1297 diff \
1313 Here is a more advanced example, which outputs a diff listing with
1317 diff \
1329 To specify a line group format, use @code{diff} with one of the options
1452 diff \
1526 similar to @code{diff}'s normal format. You can tailor this command
1527 to get fine control over @code{diff}'s output.
1530 diff \
1549 For lines common to both files, @code{diff} uses the unchanged line
1552 @code{diff} uses the old line group format; if the hunk contains only
1553 lines from the second file, @code{diff} uses the new group format;
1554 otherwise, @code{diff} uses the changed group format.
1577 You should carefully check the @code{diff} output for proper nesting.
1589 the @code{diff} @samp{-D @var{name}} option, except it operates on
1590 a file and a diff to produce a merged file; @xref{patch Options}.
1595 Here is the output of @samp{diff -DTWO lao tzu} (@pxref{Sample
1596 diff Input}, for the complete contents of the two files):
1627 You can use @code{diff} to compare some or all of the files in two
1628 directory trees. When both file name arguments to @code{diff} are
1631 @code{diff} is silent about pairs of files that contain no differences,
1633 it reports pairs of identical files. Normally @code{diff} reports
1639 For file names that are in only one of the directories, @code{diff}
1642 can make @code{diff} act as though the file existed but was empty in the
1682 @node Adjusting Output, diff Performance, Comparing Directories, Top
1683 @chapter Making @code{diff} Output Prettier
1685 @code{diff} provides several ways to adjust the appearance of its output.
1690 * Pagination:: Page numbering and timestamping @code{diff} output.
1698 The lines of text in some of the @code{diff} output formats are preceded
1702 line. GNU @code{diff} provides two ways to make tab-aligned columns
1705 The first way is to have @code{diff} convert all tabs into the correct
1707 @samp{-t} or @samp{--expand-tabs} option. @code{diff} assumes that
1725 @section Paginating @code{diff} Output
1726 @cindex paginating @code{diff} output
1730 @code{diff} output through the @code{pr} program. Here is what the page
1731 header might look like for @samp{diff -lc lao tzu}:
1734 Mar 11 13:37 1991 diff -lc lao tzu Page 1
1737 @node diff Performance, Comparing Three Files, Adjusting Output, Top
1738 @chapter @code{diff} Performance Tradeoffs
1739 @cindex performance of @code{diff}
1741 GNU @code{diff} runs quite efficiently; however, in some circumstances
1744 @code{diff} by changing the way it compares files.
1750 The way that GNU @code{diff} determines which lines have changed always
1752 enough for practical purposes. If the @code{diff} output is large, you
1753 might want @code{diff} to use a modified algorithm that sometimes
1756 @code{diff} to run more slowly than usual, so it is not the default
1762 the algorithm that @code{diff} uses. If the input files have a constant
1764 changing the output. If not, @code{diff} might produce a larger set of
1767 Normally @code{diff} discards the prefix and suffix that is common to
1769 This makes @code{diff} run faster, but occasionally it may produce
1771 prevents @code{diff} from discarding the last @var{lines} lines of the
1773 @code{diff} further opportunities to find a minimal output.
1775 @node Comparing Three Files, diff3 Merging, diff Performance, Top
1805 first two files are the same that we used for @code{diff} (@pxref{Sample
1806 diff Input}). This is the third sample file, called @file{tao}:
1869 called @dfn{diff3 hunks}, by analogy with @code{diff} hunks
1874 As with @code{diff}, several solutions are possible. When comparing the
1877 commands @samp{diff A B} and @samp{diff A C}. This does not necessarily
2209 @cindex diff merging
2228 @section Specifying @code{diff} Options to @code{sdiff}
2232 @code{diff}. @xref{diff Options}, for the use of these options.
2250 @code{diff}: with @code{sdiff}, @samp{-w @var{columns}} is equivalent to
2253 equivalent to @code{diff} with the @samp{-y} or @samp{--side-by-side}
2304 @code{patch} takes comparison output produced by @code{diff} and applies
2309 with your changes. @code{patch} automatically determines the diff
2323 @code{diff} hunks (@pxref{Hunks}) one by one. If a hunk does not
2348 @code{patch} normally determines which @code{diff} format the patch
2352 certain format of diff. The output formats listed here are the only
2358 context diff.
2366 normal diff.
2370 unified diff.
2378 diff, and then skip any trailing text. Thus you can feed a news article
2380 entire diff is indented by a constant amount of white space, @code{patch}
2410 Sometimes people run @code{diff} with the new file first instead of
2411 second. This creates a diff that is ``reversed''. To apply such
2423 a normal diff and the first command is an append (which should have been
2451 unified diff, and the maximum fuzz factor is set to 1 or more, then
2463 not be set to more than the number of lines of context in the diff,
2470 normal or @code{ed} diff, many of the contexts are simply null. The
2479 line number specified in the diff, it tells you the offset. A single
2485 script, and can only detect wrong line numbers in a normal diff when it
2487 context diff using a fuzz factor equal to or greater than the number of
2488 lines of context shown in the diff (typically 3). In these cases, you
2489 should probably look at a context diff between your original and patched
2504 file that the second directory does not. If you give @code{diff} the
2505 @samp{-N} or @samp{--new-file} option, it outputs a diff that deletes
2507 file after applying such a diff. The @samp{-E} or
2509 that are empty after applying the diff.
2610 context diff header or with an @samp{Index:} line. If you are patching
2655 Now you can create the patch. The de-facto standard @code{diff} format
2657 produced by giving @code{diff} the @samp{-C 2} option. Do not use less
2659 least two lines for proper operation. Give @code{diff} the @samp{-P}
2668 @node Invoking cmp, Invoking diff, Making Patches, Top
2735 @node Invoking diff, Invoking diff3, Invoking cmp, Top
2736 @chapter Invoking @code{diff}
2737 @cindex invoking @code{diff}
2738 @cindex @code{diff} invocation
2740 The format for running the @code{diff} command is:
2743 diff @var{options}@dots{} @var{from-file} @var{to-file}
2746 In the simplest case, @code{diff} compares the contents of the two files
2748 text read from the standard input. As a special case, @samp{diff - -}
2751 If @var{from-file} is a directory and @var{to-file} is not, @code{diff}
2756 @code{diff} compares corresponding files in both directories, in
2758 @samp{-r} or @samp{--recursive} option is given. @code{diff} never
2764 @code{diff} options begin with @samp{-}, so normally @var{from-file} and
2773 * diff Options:: Summary of options to @code{diff}.
2776 @node diff Options, , , Invoking diff
2777 @section Options to @code{diff}
2778 @cindex @code{diff} options
2779 @cindex options for @code{diff}
2781 Below is a summary of all of the options that GNU @code{diff} accepts.
2832 @code{diff} slower (sometimes much slower). @xref{diff Performance}.
2873 scattered small changes. @xref{diff Performance}.
2878 @xref{diff Performance}.
2938 makes @code{diff} slower (sometimes much slower). @xref{diff
3006 option when it runs @code{diff}. This option is not intended for users
3022 scattered small changes. @xref{diff Performance}.
3070 Output the version number of @code{diff}.
3092 @node Invoking diff3, Invoking patch, Invoking diff, Top
3245 @samp{-}, @code{patch} reads the patch (that is, the @code{diff} output)
3254 that comes before the @code{diff} output) which file to edit. In the
3255 header of a context or unified diff, @code{patch} looks in lines
3425 Interpret the patch file as a context diff. @xref{patch Input}.
3479 Interpret the patch file as a normal diff. @xref{patch Input}.
3543 Interpret the patch file as a unified diff. @xref{patch Input}.
3589 side-by-side difference. This usage is obsolete; use @samp{diff
3593 * sdiff Options:: Summary of options to @code{diff}.
3622 makes @code{sdiff} slower (sometimes much slower). @xref{diff
3627 scattered small changes. @xref{diff Performance}.
3667 makes @code{sdiff} slower (sometimes much slower). @xref{diff
3680 scattered small changes. @xref{diff Performance}.
3697 Note that for historical reasons, this option is @samp{-W} in @code{diff},
3702 Note that for historical reasons, this option is @samp{-w} in @code{diff},
3710 @cindex newline treatment by @code{diff}
3727 @code{diff} cannot represent an incomplete line, so it pretends there
3731 contain just @samp{f} and @samp{g}, respectively. Then @samp{diff F G}
3745 @samp{diff -n F G} outputs the following without a trailing newline:
3753 @samp{diff -e F G} reports two errors and outputs the following:
3764 Here are some ideas for improving GNU @code{diff} and @code{patch}. The
3780 @section Suggested Projects for Improving GNU @code{diff} and @code{patch}
3783 One should be able to use GNU @code{diff} to generate a patch from any
3804 @code{diff} and @code{patch} do not handle some changes to directory
3807 with the same name @samp{D}. @samp{diff -r} does not output enough
3814 there is no way for @code{diff} to generate such information.
3816 These problems can be fixed by extending the @code{diff} output format
3826 sockets. Currently, @code{diff} treats symbolic links like regular files;
3831 points to, @code{diff} outputs the difference between the two files,
3836 @code{diff} should optionally report changes to special files specially,
3844 white space, @samp{diff -r} generates a patch that @code{patch} cannot
3845 parse. The problem is with format of @code{diff} output, not just with
3847 @code{diff} to generate a patch that is syntactically correct but
3848 patches the wrong files. The format of @code{diff} output should be
3855 GNU @code{diff} can analyze files with arbitrarily long lines and files
3858 removed, and @code{patch} should be extended to parse @code{diff}
3865 @code{diff} operates by reading both files into memory. This method
3866 fails if the files are too large, and @code{diff} should have a fallback.
3897 If you think you have found a bug in GNU @code{cmp}, @code{diff},