⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diff.texi

📁 制作2.6内核的CLFS时 使用的diffutils-2.8.7.tar.gz包
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
\input texinfo @c -*-texinfo-*-@comment $Id: diff.texi,v 1.25 2004/04/12 07:44:35 eggert Exp $@comment %**start of header@setfilename diff.info@include version.texi@settitle Comparing and Merging Files@syncodeindex vr cp@setchapternewpage odd@comment %**end of header@copyingThis manual is for GNU Diffutils(version @value{VERSION}, @value{UPDATED}),and documents the @acronym{GNU} @command{diff}, @command{diff3},@command{sdiff}, and @command{cmp} commands for showing thedifferences between files and the @acronym{GNU} @command{patch} command forusing their output to update files.Copyright @copyright{} 1992, 1993, 1994, 1998, 2001, 2002, 2004 FreeSoftware Foundation, Inc.@quotationPermission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.1 orany later version published by the Free Software Foundation; with noInvariant Sections, with the Front-Cover texts being ``A GNU Manual,''and with the Back-Cover Texts as in (a) below.  A copy of thelicense is included in the section entitled ``GNU Free DocumentationLicense.''(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modifythis GNU Manual, like GNU software.  Copies published by the FreeSoftware Foundation raise funds for GNU development.''@end quotation@end copying@c Debian install-info (up through at least version 1.9.20) uses only the@c first dircategory.  Put this one first, as it is more useful in practice.@dircategory Individual utilities@direntry* cmp: (diff)Invoking cmp.                      Compare 2 files byte by byte.* diff: (diff)Invoking diff.                    Compare 2 files line by line.* diff3: (diff)Invoking diff3.                  Compare 3 files line by line.* patch: (diff)Invoking patch.                  Apply a patch to a file.* sdiff: (diff)Invoking sdiff.                  Merge 2 files side-by-side.@end direntry@dircategory Text creation and manipulation@direntry* Diff: (diff).                 Comparing and merging files.@end direntry@titlepage@title Comparing and Merging Files@subtitle for Diffutils @value{VERSION} and @code{patch} 2.5.4@subtitle @value{UPDATED}@author David MacKenzie, Paul Eggert, and Richard Stallman@page@vskip 0pt plus 1filll@insertcopying@end titlepage@shortcontents@contents@ifnottex@node Top@top Comparing and Merging Files@insertcopying@end ifnottex@menu* Overview::              Preliminary information.* Comparison::            What file comparison means.* Output Formats::        Formats for two-way difference reports.* Incomplete Lines::      Lines that lack trailing newlines.* Comparing Directories:: Comparing files and directories.* Adjusting Output::      Making @command{diff} output prettier.* diff Performance::      Making @command{diff} smarter or faster.* Comparing Three Files:: Formats for three-way difference reports.* diff3 Merging::         Merging from a common ancestor.* Interactive Merging::   Interactive merging with @command{sdiff}.* Merging with patch::    Using @command{patch} to change old files into new ones.* Making Patches::        Tips for making and using patch distributions.* Invoking cmp::          Compare two files byte by byte.* Invoking diff::         Compare two files line by line.* Invoking diff3::        Compare three files line by line.* Invoking patch::        Apply a diff file to an original.* Invoking sdiff::        Side-by-side merge of file differences.* Standards conformance:: Conformance to the @acronym{POSIX} standard.* Projects::              If you've found a bug or other shortcoming.* Copying This Manual::   How to make copies of this manual.* Translations::          Available translations of this manual.* Index::                 Index.@end menu@node Overview@unnumbered Overview@cindex overview of @command{diff} and @command{patch}Computer users often find occasion to ask how two files differ.  Perhapsone file is a newer version of the other file.  Or maybe the two filesstarted out as identical copies but were changed by different people.You can use the @command{diff} command to show differences between twofiles, or each corresponding file in two directories.  @command{diff}outputs differences between files line by line in any of severalformats, selectable by command line options.  This set of differences isoften called a @dfn{diff} or @dfn{patch}.  For files that are identical,@command{diff} normally produces no output; for binary (non-text) files,@command{diff} normally reports only that they are different.You can use the @command{cmp} command to show the byte and line numberswhere two files differ.  @command{cmp} can also show all the bytesthat differ between the two files, side by side.  A way to comparetwo files character by character is the Emacs command @kbd{M-xcompare-windows}.  @xref{Other Window, , Other Window, emacs, The @acronym{GNU}Emacs Manual}, for more information on that command.You can use the @command{diff3} command to show differences among threefiles.  When two people have made independent changes to a commonoriginal, @command{diff3} can report the differences between the originaland the two changed versions, and can produce a merged file thatcontains both persons' changes together with warnings about conflicts.You can use the @command{sdiff} command to merge two files interactively.You can use the set of differences produced by @command{diff} to distributeupdates to text files (such as program source code) to other people.This method is especially useful when the differences are small comparedto the complete files.  Given @command{diff} output, you can use the@command{patch} program to update, or @dfn{patch}, a copy of the file.  If youthink of @command{diff} as subtracting one file from another to producetheir difference, you can think of @command{patch} as adding the differenceto one file to reproduce the other.This manual first concentrates on making diffs, and later shows how touse diffs to update files.@acronym{GNU} @command{diff} was written by Paul Eggert, Mike Haertel,David Hayes, Richard Stallman, and Len Tower.  Wayne Davison designed andimplemented the unified output format.  The basic algorithm is describedby Eugene W. Myers in ``An O(ND) Difference Algorithm and its Variations'',@cite{Algorithmica} Vol.@: 1 No.@: 2, 1986, pp.@: 251--266; and in ``A FileComparison Program'', Webb Miller and Eugene W. Myers,@cite{Software---Practice and Experience} Vol.@: 15 No.@: 11, 1985,pp.@: 1025--1040.@c From: "Gene Myers" <gene@cs.arizona.edu>@c They are about the same basic algorithm; the Algorithmica@c paper gives a rigorous treatment and the sub-algorithm for@c delivering scripts and should be the primary reference, but@c both should be mentioned.The algorithm was independently discovered as described by E. Ukkonen in``Algorithms for Approximate String Matching'',@cite{Information and Control} Vol.@: 64, 1985, pp.@: 100--118.@c From: "Gene Myers" <gene@cs.arizona.edu>@c Date: Wed, 29 Sep 1993 08:27:55 MST@c Ukkonen should be given credit for also discovering the algorithm used@c in GNU diff.Unless the @option{--minimal} option is used, @command{diff} uses aheuristic by Paul Eggert that limits the cost to @math{O(N^1.5 log N)}at the price of producing suboptimal output for large inputs with manydifferences.  Related algorithms are surveyed by Alfred V. Aho insection 6.3 of ``Algorithms for Finding Patterns in Strings'',@cite{Handbook of Theoretical Computer Science} (Jan Van Leeuwen,ed.), Vol.@: A, @cite{Algorithms and Complexity}, Elsevier/MIT Press,1990, pp.@: 255--300.@acronym{GNU} @command{diff3} was written by Randy Smith.  @acronym{GNU}@command{sdiff} was written by Thomas Lord.  @acronym{GNU} @command{cmp}was written by Torbj@"orn Granlund and David MacKenzie.@acronym{GNU} @command{patch} was written mainly by Larry Wall and Paul Eggert;several @acronym{GNU} enhancements were contributed by Wayne Davison andDavid MacKenzie.  Parts of this manual are adapted from a manual pagewritten by Larry Wall, with his permission.@node Comparison@chapter What Comparison Means@cindex introductionThere are several ways to think about the differences between two files.One way to think of the differences is as a series of lines that weredeleted from, inserted in, or changed in one file to produce the otherfile.  @command{diff} compares two files line by line, finds groups oflines that differ, and reports each group of differing lines.  It canreport the differing lines in several formats, which have differentpurposes.@acronym{GNU} @command{diff} can show whether files are differentwithout detailing the differences.  It also provides ways to suppresscertain kinds of differences that are not important to you.  Mostcommonly, such differences are changes in the amount of white spacebetween words or lines.  @command{diff} also provides ways to suppressdifferences in alphabetic case or in lines that match a regularexpression that you provide.  These options can accumulate; forexample, you can ignore changes in both white space and alphabeticcase.Another way to think of the differences between two files is as asequence of pairs of bytes that can be either identical ordifferent.  @command{cmp} reports the differences between two filesbyte by byte, instead of line by line.  As a result, it is oftenmore useful than @command{diff} for comparing binary files.  For textfiles, @command{cmp} is useful mainly when you want to know only whethertwo files are identical, or whether one file is a prefix of the other.To illustrate the effect that considering changes byte by bytecan have compared with considering them line by line, think of whathappens if a single newline character is added to the beginning of afile.  If that file is then compared with an otherwise identical filethat lacks the newline at the beginning, @command{diff} will report that ablank line has been added to the file, while @command{cmp} will report thatalmost every byte of the two files differs.@command{diff3} normally compares three input files line by line, findsgroups of lines that differ, and reports each group of differing lines.Its output is designed to make it easy to inspect two different sets ofchanges to the same file.@menu* Hunks::             Groups of differing lines.* White Space::       Suppressing differences in white space.* Blank Lines::       Suppressing differences whose lines are all blank.* Specified Lines::   Suppressing differences whose lines all match a pattern.* Case Folding::      Suppressing differences in alphabetic case.* Brief::             Summarizing which files are different.* Binary::            Comparing binary files or forcing text comparisons.@end menu@node Hunks@section Hunks@cindex hunksWhen comparing two files, @command{diff} finds sequences of lines common toboth files, interspersed with groups of differing lines called@dfn{hunks}.  Comparing two identical files yields one sequence ofcommon lines and no hunks, because no lines differ.  Comparing twoentirely different files yields no common lines and one large hunk thatcontains all lines of both files.  In general, there are many ways tomatch up lines between two given files.  @command{diff} tries to minimizethe total hunk size by finding large sequences of common linesinterspersed with small hunks of differing lines.For example, suppose the file @file{F} contains the three lines@samp{a}, @samp{b}, @samp{c}, and the file @file{G} contains the samethree lines in reverse order @samp{c}, @samp{b}, @samp{a}.  If@command{diff} finds the line @samp{c} as common, then the command@samp{diff F G} produces this output:@example1,2d0< a< b3a2,3> b> a@end example@noindentBut if @command{diff} notices the common line @samp{b} instead, it producesthis output:@example1c1< a---> c3c3< c---> a@end example@noindentIt is also possible to find @samp{a} as the common line.  @command{diff}does not always find an optimal matching between the files; it takesshortcuts to run faster.  But its output is usually close to theshortest possible.  You can adjust this tradeoff with the@option{-d} or @option{--minimal} option (@pxref{diff Performance}).@node White Space@section Suppressing Differences in Blank and Tab Spacing@cindex blank and tab difference suppression@cindex tab and blank difference suppressionThe @option{-E} or @option{--ignore-tab-expansion} option ignores thedistinction between tabs and spaces on input.  A tab is considered to beequivalent to the number of spaces to the next tab stop (@pxref{Tabs}).The @option{-b} or @option{--ignore-space-change} option is stronger.It ignores white space at line end, and considers all other sequences ofone or more white space characters within a line to be equivalent.  With thisoption, @command{diff} considers the following two lines to be equivalent,where @samp{$} denotes the line end:@exampleHere lyeth  muche rychnesse  in lytell space.   -- John Heywood$Here lyeth muche rychnesse in lytell space. -- John Heywood   $@end exampleThe @option{-w} or @option{--ignore-all-space} option is stronger still.It ignores differences even if one line has white space wherethe other line has none.  @dfn{White space} characters includetab, newline, vertical tab, form feed, carriage return, and space;some locales may define additional characters to be white space.With this option, @command{diff} considers thefollowing two lines to be equivalent, where @samp{$} denotes the lineend and @samp{^M} denotes a carriage return:@exampleHere lyeth  muche  rychnesse in lytell space.--  John Heywood$  He relyeth much erychnes  seinly tells pace.  --John Heywood   ^M$@end example@node Blank Lines@section Suppressing Differences Whose Lines Are All Blank@cindex blank line difference suppressionThe @option{-B} or @option{--ignore-blank-lines} option ignores changesthat consist entirely of blank lines.  With this option, for example, afile containing@example1.  A point is that which has no part.2.  A line is breadthless length.-- Euclid, The Elements, I@end example@noindentis considered identical to a file containing@example1.  A point is that which has no part.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -