Lines Matching full:diff

2 @comment $Id: diff.texi,v 1.25 2004/04/12 07:44:35 eggert Exp $
4 @setfilename diff.info
13 and documents the @acronym{GNU} @command{diff}, @command{diff3},
40 * cmp: (diff)Invoking cmp. Compare 2 files byte by byte.
41 * diff: (diff)Invoking diff. Compare 2 files line by line.
42 * diff3: (diff)Invoking diff3. Compare 3 files line by line.
43 * patch: (diff)Invoking patch. Apply a patch to a file.
44 * sdiff: (diff)Invoking sdiff. Merge 2 files side-by-side.
49 * Diff: (diff). Comparing and merging files.
79 * Adjusting Output:: Making @command{diff} output prettier.
80 * diff Performance:: Making @command{diff} smarter or faster.
91 * Invoking diff:: Compare two files line by line.
93 * Invoking patch:: Apply a diff file to an original.
106 @cindex overview of @command{diff} and @command{patch}
112 You can use the @command{diff} command to show differences between two
113 files, or each corresponding file in two directories. @command{diff}
116 often called a @dfn{diff} or @dfn{patch}. For files that are identical,
117 @command{diff} normally produces no output; for binary (non-text) files,
118 @command{diff} normally reports only that they are different.
135 You can use the set of differences produced by @command{diff} to distribute
138 to the complete files. Given @command{diff} output, you can use the
140 think of @command{diff} as subtracting one file from another to produce
147 @acronym{GNU} @command{diff} was written by Paul Eggert, Mike Haertel,
166 @c in GNU diff.
167 Unless the @option{--minimal} option is used, @command{diff} uses a
192 file. @command{diff} compares two files line by line, finds groups of
197 @acronym{GNU} @command{diff} can show whether files are different
201 between words or lines. @command{diff} also provides ways to suppress
211 more useful than @command{diff} for comparing binary files. For text
219 that lacks the newline at the beginning, @command{diff} will report that a
242 When comparing two files, @command{diff} finds sequences of lines common to
248 match up lines between two given files. @command{diff} tries to minimize
255 @command{diff} finds the line @samp{c} as common, then the command
256 @samp{diff F G} produces this output:
268 But if @command{diff} notices the common line @samp{b} instead, it produces
283 It is also possible to find @samp{a} as the common line. @command{diff}
287 @option{-d} or @option{--minimal} option (@pxref{diff Performance}).
301 option, @command{diff} considers the following two lines to be equivalent,
314 With this option, @command{diff} considers the
363 shell from expanding them. For example, @samp{diff -I '^[[:digit:]]'} ignores
369 words, for each nonignorable change, @command{diff} prints the complete set
373 using more than one @option{-I} option. @command{diff} tries to match each
380 @acronym{GNU} @command{diff} can treat lower case letters as
394 files, @command{diff} simply reports whether files differ. The @option{-q}
399 comparisons, because @command{diff} can stop analyzing the files as soon as
413 Unlike @command{diff}, @command{cmp} cannot compare directories; it can only
418 @cindex binary file diff
419 @cindex text versus binary diff
421 If @command{diff} thinks that either of the two files it is comparing is
427 @command{diff} determines whether a file is text or binary by checking the
430 that part of the file is non-null, @command{diff} considers the file to be
433 Sometimes you might want to force @command{diff} to consider files to be
435 null characters; @command{diff} would erroneously decide that those are
438 indicate special formatting. You can force @command{diff} to consider all
442 newline characters, and the @command{diff} output will consist of hunks
446 You can also force @command{diff} to report only whether files differ
451 resulting @command{diff} output does not capture all the differences.
452 This trouble causes @command{diff} to exit with status 2. However,
455 options both cause @command{diff} to generate a form of output that
459 @command{diff} normally reads and writes all data as text. Use the
460 @option{--binary} option to force @command{diff} to read and write binary
464 followed by a newline. On such systems, @command{diff} normally ignores
466 output line, but with the @option{--binary} option @command{diff} treats
472 The @option{--strip-trailing-cr} causes @command{diff} to treat input
489 @command{diff} to decide whether a file is binary. As with @command{diff}, if
496 @chapter @command{diff} Output Formats
498 @cindex format of @command{diff} output
500 @command{diff} has several mutually exclusive options for output format.
502 @command{diff} reports the differences between two sample input files.
505 * Sample diff Input:: Sample @command{diff} input files for examples.
513 @node Sample diff Input
515 @cindex @command{diff} sample input
516 @cindex sample input for @command{diff}
519 illustrate the output of @command{diff} and how various options can change
571 @acronym{GNU} @command{diff} provides two output formats that show context
577 form of @command{diff} output, you should use one of the output formats
582 lines away from where the diff says they are, @command{patch} can adjust
583 the line numbers accordingly and still apply the diff correctly.
617 Here is the output of @samp{diff -c lao tzu} (@pxref{Sample diff Input},
656 Here is the output of @samp{diff -C 1 lao tzu} (@pxref{Sample diff
762 At present, only @acronym{GNU} @command{diff} can produce this format and
775 Here is the output of the command @samp{diff -u lao tzu}
776 (@pxref{Sample diff Input}, for the complete contents of the two files):
859 chapter or appendix was changed. @acronym{GNU} @command{diff} can
876 or @option{--show-function-line=@var{regexp}} option. @command{diff}
904 regular expression for such lines; @command{diff} tries to match each line
924 @command{diff} provides this option for the sake of convenience.
932 names, you might want @command{diff} to show alternate names in the header
938 twice, @command{diff} reports an error. The @option{--label} option does not
942 Here are the first two lines of the output from @samp{diff -C 2
956 @command{diff} can produce a side by side difference listing of two files.
1031 Here is the output of the command @samp{diff -y -W 72 lao tzu}
1032 (@pxref{Sample diff Input}, for the complete contents of the two files).
1057 The ``normal'' @command{diff} output format shows each hunk of differences
1065 compatibility with older versions of @command{diff} and the @acronym{POSIX}
1077 Here is the output of the command @samp{diff lao tzu}
1078 (@pxref{Sample diff Input}, for the complete contents of the two files).
1150 * ed Scripts:: Using @command{diff} to produce commands for @command{ed}.
1152 * RCS:: A special @command{diff} output format used by @acronym{RCS}.
1159 @command{diff} can produce commands that direct the @command{ed} text editor
1167 information necessary to apply the diff in reverse (to produce the first
1168 file if all you have is the second file and the diff).
1170 If the file @file{d} contains the output of @samp{diff -e old new}, then
1173 @dots{}, @file{dN} contain the outputs of @samp{diff -e old new1},
1174 @samp{diff -e new1 new2}, @dots{}, @samp{diff -e newN-1 newN},
1186 Here is the output of @samp{diff -e lao tzu} (@pxref{Sample
1187 diff Input}, for the complete contents of the two files):
1219 end of input, @acronym{GNU} @command{diff} protects lines of changes
1224 line, @command{diff} reports an error and then pretends that a newline
1254 @command{diff} can produce output that is like an @command{ed} script, but
1264 compatibility with older versions of @command{diff}. Use the @option{-f} or
1285 Here is the output of @samp{diff -n lao tzu} (@pxref{Sample
1286 diff Input}, for the complete contents of the two files):
1307 You can use @command{diff} to merge two files of C source code. The output
1308 of @command{diff} in this format contains all the lines of both files.
1315 To merge two files, use @command{diff} with the @option{-D @var{name}} or
1362 diff \
1376 diff \
1392 Here is a more advanced example, which outputs a diff listing with
1396 diff \
1408 To specify a line group format, use @command{diff} with one of the options
1535 diff \
1609 similar to normal @command{diff} format. You can tailor this command
1610 to get fine control over @command{diff} output.
1613 diff \
1632 Here is the output of @samp{diff -DTWO lao tzu} (@pxref{Sample
1633 diff Input}, for the complete contents of the two files):
1664 For lines common to both files, @command{diff} uses the unchanged line
1667 @command{diff} uses the old line group format; if the hunk contains only
1668 lines from the second file, @command{diff} uses the new group format;
1669 otherwise, @command{diff} uses the changed group format.
1692 You should carefully check the @command{diff} output for proper nesting.
1704 the @command{diff} @option{-D @var{name}} option, except it operates on
1705 a file and a diff to produce a merged file; @xref{patch Options}.
1711 @cindex newline treatment by @command{diff}
1728 output formats (@pxref{Output Formats}) @command{diff} cannot
1733 contain just @samp{f} and @samp{g}, respectively. Then @samp{diff F G}
1747 @samp{diff -n F G} outputs the following without a trailing newline:
1756 @samp{diff -e F G} reports two errors and outputs the following:
1768 You can use @command{diff} to compare some or all of the files in two
1769 directory trees. When both file name arguments to @command{diff} are
1773 @command{diff} is silent about pairs of files that contain no differences,
1775 it reports pairs of identical files. Normally @command{diff} reports
1781 For file names that are in only one of the directories, @command{diff}
1784 can make @command{diff} act as though the file existed but was empty in the
1826 one directory and upper case in the upper, @command{diff} normally
1829 @command{diff} ignores case differences in file names, so that for example
1844 @chapter Making @command{diff} Output Prettier
1846 @command{diff} provides several ways to adjust the appearance of its output.
1851 * Pagination:: Page numbering and time-stamping @command{diff} output.
1859 The lines of text in some of the @command{diff} output formats are
1863 columns in the line. @acronym{GNU} @command{diff} provides two ways
1866 The first way is to have @command{diff} convert all tabs into the correct
1871 information). @command{diff} normally assumes that tab stops are set
1887 @section Paginating @command{diff} Output
1888 @cindex paginating @command{diff} output
1892 @command{diff} output through the @command{pr} program. Here is what the page
1893 header might look like for @samp{diff -lc lao tzu}:
1896 2002-02-22 14:20 diff -lc lao tzu Page 1
1899 @node diff Performance
1900 @chapter @command{diff} Performance Tradeoffs
1901 @cindex performance of @command{diff}
1903 @acronym{GNU} @command{diff} runs quite efficiently; however, in some
1907 One way to improve @command{diff} performance is to use hard or
1909 because @command{diff} normally does not need to read two hard or
1912 make a few changes to the copy, and then often use @samp{diff -r} to
1919 You can also affect the performance of @acronym{GNU} @command{diff} by
1925 The way that @acronym{GNU} @command{diff} determines which lines have
1928 @command{diff} output is large, you might want @command{diff} to use a
1931 however, it can also cause @command{diff} to run more slowly than
1937 the algorithm that @command{diff} uses. If the input files have a constant
1939 changing the output. If not, @command{diff} might produce a larger set of
1942 Normally @command{diff} discards the prefix and suffix that is common to
1944 This makes @command{diff} run faster, but occasionally it may produce
1946 prevents @command{diff} from discarding the last @var{lines} lines of the
1948 @command{diff} further opportunities to find a minimal output.
1952 The @command{diff} command is free to choose which identical sequence is
1953 included in the hunk. In this case, @command{diff} normally shifts the
1988 first two files are the same that we used for @command{diff} (@pxref{Sample
1989 diff Input}). This is the third sample file, called @file{tao}:
2091 called @dfn{diff3 hunks}, by analogy with @command{diff} hunks
2096 As with @command{diff}, several solutions are possible. When comparing the
2099 commands @samp{diff A B} and @samp{diff A C}. This does not necessarily
2394 @cindex diff merging
2413 @section Specifying @command{diff} Options to @command{sdiff}
2417 @command{diff}. @xref{diff Options}, for the use of these options.
2437 @command{diff}: with @command{sdiff}, @option{-w @var{columns}} is
2440 @option{-o} option is equivalent to @command{diff} with the @option{-y}
2500 @command{patch} takes comparison output produced by @command{diff} and applies
2505 with your changes. @command{patch} automatically determines the diff
2518 @command{diff} hunks (@pxref{Hunks}) one by one. If a hunk does not
2548 @command{patch} normally determines which @command{diff} format the patch
2552 certain format of diff. The output formats listed here are the only
2558 context diff.
2566 normal diff.
2570 unified diff.
2609 apply the diff, and then skip any trailing text. Thus you can feed a
2611 entire diff is indented by a constant amount of white space,
2613 diff contains trailing carriage return on each line, @command{patch}
2614 automatically ignores the carriage return. If a context diff has been
2648 Sometimes people run @command{diff} with the new file first instead of
2649 second. This creates a diff that is ``reversed''. To apply such
2659 a normal diff and the first command is an append (which should have been
2687 unified diff, and the maximum fuzz factor is set to 1 or more, then
2700 in the diff, ordinarily 3.
2706 normal or @command{ed} diff, many of the contexts are simply null. The
2716 line number specified in the diff, it tells you the offset. A single
2722 script, and can only detect wrong line numbers in a normal diff when it
2724 context diff using a fuzz factor equal to or greater than the number of
2725 lines of context shown in the diff (typically 3). In these cases, you
2726 should probably look at a context diff between your original and patched
2763 directory but not the other. If you give @command{diff} the
2766 Epoch (1970-01-01 00:00:00 UTC), @command{diff} outputs a patch that
2794 given in context diff headers. If the context diff headers do not
2799 @option{--set-utc}, except that it assumes that the context diff
2804 adjustments. If the context diff headers specify a time zone, this
2809 given in the diff header, of if the file's contents do not exactly
2813 Due to the limitations of the current @command{diff} format,
2840 If the header is that of a context diff, @command{patch} takes the old
3177 when intuiting file names from diff headers. @xref{Multiple Patches}.
3180 Do not remove files that are removed by a diff.
3243 are compatible if the file names in the context diff header and the
3314 To generate the patch, use the command @samp{diff -Naur @var{old}
3324 diff -Naur gcc-3.0.3 gcc-3.0.4
3344 @acronym{GNU} @command{diff} can analyze files with arbitrarily long lines
3355 When producing a patch for multiple files, apply @command{diff} to
3363 diff -Naur v2.0.29/prog/README prog/README
3375 diff -Naur v2.0.29/prog/README v2.0.30/prog/README
3381 context diff header or with an @samp{Index:} line. Take care to not send out
3411 The simplest way to generate a patch is to use @samp{diff -Naur}
3424 exclude them from the patch by giving @command{diff} the @option{-x
3431 Now you can create the patch using @samp{diff -Naur}. Make sure to
3622 @node Invoking diff
3623 @chapter Invoking @command{diff}
3624 @cindex invoking @command{diff}
3625 @cindex @command{diff} invocation
3627 The format for running the @command{diff} command is:
3630 diff @var{options}@dots{} @var{files}@dots{}
3634 @var{to-file} are given, and @command{diff} compares the contents of
3636 text read from the standard input. As a special case, @samp{diff - -}
3639 If one file is a directory and the other is not, @command{diff} compares
3644 @command{diff} compares corresponding files in both directories, in
3646 @option{-r} or @option{--recursive} option is given. @command{diff} never
3657 @command{diff} options begin with @samp{-}, so normally file names
3669 * diff Options:: Summary of options to @command{diff}.
3672 @node diff Options
3673 @section Options to @command{diff}
3674 @cindex @command{diff} options
3675 @cindex options for @command{diff}
3678 @command{diff} accepts. Most options have two equivalent names, one
3715 On older systems, @command{diff} supports an obsolete option
3728 @command{diff} slower (sometimes much slower). @xref{diff Performance}.
3764 @xref{diff Performance}.
3849 scattered small changes. @xref{diff Performance}.
3901 On older systems, @command{diff} supports an obsolete option
3978 @item --diff-program=@var{program}
3980 instead of @command{diff}.
4077 @file{-}, @command{patch} reads the patch (that is, the @command{diff} output)
4082 that comes before the @command{diff} output) which file to edit.
4129 @samp{diff -a --binary}. @xref{Binary}.
4133 Interpret the patch file as a context diff. @xref{patch Input}.
4188 Interpret the patch file as a normal diff. @xref{patch Input}.
4237 stamps given in context diff headers, assuming that the context diff
4242 Interpret the patch file as a unified diff. @xref{patch Input}.
4272 stamps given in context diff headers, assuming that the context diff
4302 or @option{--side-by-side} option of @command{diff} instead.
4308 * sdiff Options:: Summary of options to @command{diff}.
4342 makes @command{sdiff} slower (sometimes much slower). @xref{diff
4345 @item --diff-program=@var{program}
4347 instead of @command{diff}.
4382 scattered small changes. @xref{diff Performance}.
4405 option is @option{-W} in @command{diff}, @option{-w} in @command{sdiff}.
4410 Note that for historical reasons, this option is @option{-w} in @command{diff},
4427 @samp{diff lao tzu -C 2} acts like @samp{diff -C 2 lao tzu}, since
4434 command @samp{diff -c -10} to have the same meaning as @samp{diff -C
4435 10}, but @acronym{POSIX} 1003.1-2001 @samp{diff} no longer allows
4447 assumes an older version of @acronym{POSIX} and uses @samp{diff -c -10},
4454 Here are some ideas for improving @acronym{GNU} @command{diff} and
4470 @section Suggested Projects for Improving @acronym{GNU} @command{diff} and @command{patch}
4473 One should be able to use @acronym{GNU} @command{diff} to generate a
4496 @command{diff}, @command{diff3} and @command{sdiff} treat each line of
4499 @command{diff} does not properly ignore a multibyte space character.
4501 Also, @command{diff} currently assumes that each byte is one column
4504 @option{--side-by-side} option of @command{diff}.
4512 to support internationalized @command{diff}}.
4514 version of @command{diff}, so more work needs to be done in this area.
4520 @command{diff} and @command{patch} do not handle some changes to directory
4523 with the same name @samp{D}. @samp{diff -r} does not output enough
4530 there is no way for @command{diff} to generate such information.
4534 These problems can be fixed by extending the @command{diff} output format
4544 sockets. Currently, @command{diff} treats symbolic links as if they
4545 were the pointed-to files, except that a recursive @command{diff}
4547 symbolic links to @file{..}). @command{diff} treats other special
4552 @command{diff} outputs the difference between the two files, instead
4557 @command{diff} should optionally report changes to special files specially,
4565 white space, @samp{diff -r} generates a patch that @command{patch} cannot
4566 parse. The problem is with format of @command{diff} output, not just with
4568 @command{diff} to generate a patch that is syntactically correct but
4569 patches the wrong files. The format of @command{diff} output should be
4575 Applying @command{patch} to a multiple-file diff can result in files
4581 implement a @command{diff} option to output diffs in time stamp order.
4599 sed 's/foo/bar/g' file1 | diff - file2
4610 told @command{diff} to assume that two files with the same size and
4611 time stamps have the same content. @xref{diff Performance}.
4619 @command{diff}, @command{diff3}, or @command{sdiff}, please report it