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

📄 diff.texi

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
\input texinfo @c -*-texinfo-*-@c %**start of header@setfilename diff.info@settitle Comparing and Merging Files@setchapternewpage odd@c %**end of header@ifinfoThis file documents the the GNU @code{diff}, @code{diff3}, @code{sdiff},and @code{cmp} commands for showing the differences between text filesand the @code{patch} command for using their output to update files.Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.@ignorePermission is granted to process this file through TeX and print theresults, provided the printed document carries copying permissionnotice identical to this one except for the removal of this paragraph(this paragraph not being relevant to the printed manual).@end ignorePermission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided that the entireresulting derived work is distributed under the terms of a permissionnotice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that this permission notice may be stated in a translation approvedby the Foundation.@end ifinfo@titlepage@title Comparing and Merging Files@subtitle @code{diff}, @code{diff3}, @code{sdiff}, @code{cmp}, and @code{patch}@subtitle Edition 1.3, for @code{diff} 2.5 and @code{patch} 2.1@subtitle September 1993@author by David MacKenzie, Paul Eggert, and Richard Stallman@page@vskip 0pt plus 1filllCopyright @copyright{} 1992, 1993, 1994 Free Software Foundation, Inc.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided that the entireresulting derived work is distributed under the terms of a permissionnotice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that this permission notice may be stated in a translation approvedby the Foundation.@end titlepage@node Top, , , (dir)@ifinfoThis file documents the the GNU @code{diff}, @code{diff3}, @code{sdiff},and @code{cmp} commands for showing the differences between text filesand the @code{patch} command for using their output to update files.This is Edition 1.2, for @code{diff} 2.4 and @code{patch} 2.1.@end ifinfo@menu* Overview::		Preliminary information.* Comparison::		What file comparison means.* Output Formats::	Formats for difference reports.* Comparing Directories::	Comparing files and directories.* Adjusting Output::	Making @code{diff} output prettier.* diff Performance::	Making @code{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 @code{sdiff}.* Merging with patch::	Using @code{patch} to change old files into new ones.* Making Patches::	Tips for making patch distributions.* Invoking cmp::	How to run @code{cmp} and a summary of its options.* Invoking diff::	How to run @code{diff} and a summary of its options.* Invoking diff3::	How to run @code{diff3} and a summary of its options.* Invoking patch::	How to run @code{patch} and a summary of its options.* Invoking sdiff::	How to run @code{sdiff} and a summary of its options.* Incomplete Lines::	Lines that lack trailing newlines.* Projects::		If you think you've found a bug or other shortcoming.* Concept Index::	Index of concepts.@end menu@node Overview, Comparison, , Top@unnumbered Overview@cindex overview of @code{diff} and @code{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 @code{diff} command to show differences between twofiles, or each corresponding file in two directories.  @code{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,@code{diff} normally produces no output; for binary (non-text) files,@code{diff} normally reports only that they are different.You can use the @code{cmp} command to show the offsets and line numberswhere two files differ.  @code{cmp} can also show all the charactersthat differ between the two files, side by side.  Another way to comparetwo files character by character is the Emacs command @kbd{M-xcompare-windows}.  @xref{Other Window, , Other Window, emacs, The GNUEmacs Manual}, for more information on that command.You can use the @code{diff3} command to show differences among threefiles.  When two people have made independent changes to a commonoriginal, @code{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 @code{sdiff} command to merge two files interactively.You can use the set of differences produced by @code{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 @code{diff} output, you can use the@code{patch} program to update, or @dfn{patch}, a copy of the file.  If youthink of @code{diff} as subtracting one file from another to producetheir difference, you can think of @code{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.GNU @code{diff} was written by Mike Haertel, David Hayes, RichardStallman, Len Tower, and Paul Eggert.  Wayne Davison designed andimplemented the unified output format.  The basic algorithm is describedin ``An O(ND) Difference Algorithm and its Variations'', Eugene W. Myers,@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 in``Algorithms for Approximate String Matching'',E. Ukkonen, @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.GNU @code{diff3} was written by Randy Smith.  GNU @code{sdiff} waswritten by Thomas Lord.  GNU @code{cmp} was written by Torbjorn Granlundand David MacKenzie.@code{patch} was written mainly by Larry Wall; the GNU enhancements werewritten mainly by Wayne Davison and David MacKenzie.  Parts of thismanual are adapted from a manual page written by Larry Wall, with hispermission.@node Comparison, Output Formats, Overview, Top@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.  @code{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.GNU @code{diff} can show whether files are different without detailingthe differences.  It also provides ways to suppress certain kinds ofdifferences that are not important to you.  Most commonly, suchdifferences are changes in the amount of white space between words orlines.  @code{diff} also provides ways to suppress differences inalphabetic case or in lines that match a regular expression that youprovide.  These options can accumulate; for example, you can ignorechanges in both white space and alphabetic case.Another way to think of the differences between two files is as asequence of pairs of characters that can be either identical ordifferent.  @code{cmp} reports the differences between two filescharacter by character, instead of line by line.  As a result, it ismore useful than @code{diff} for comparing binary files.  For textfiles, @code{cmp} is useful mainly when you want to know only whethertwo files are identical.To illustrate the effect that considering changes character by charactercan 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, @code{diff} will report that ablank line has been added to the file, while @code{cmp} will report thatalmost every character of the two files differs.@code{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 in blank lines.* Case Folding::	Suppressing differences in alphabetic case.* Specified Folding::	Suppressing differences that match regular expressions.* Brief::		Summarizing which files are different.* Binary::		Comparing binary files or forcing text comparisons.@end menu@node Hunks, White Space, , Comparison@section Hunks@cindex hunksWhen comparing two files, @code{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.  @code{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@code{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 @code{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.  @code{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@samp{--minimal} option (@pxref{diff Performance}).@node White Space, Blank Lines, Hunks, Comparison@section Suppressing Differences in Blank and Tab Spacing@cindex blank and tab difference suppression@cindex tab and blank difference suppressionThe @samp{-b} and @samp{--ignore-space-change} options ignore white spaceat line end, and considers all other sequences of one or morewhite space characters to be equivalent.  With these options,@code{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 @samp{-w} and @samp{--ignore-all-space} options are stronger than@samp{-b}.  They ignore difference even if one file has white space wherethe other file 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 these options, @code{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, Case Folding, White Space, Comparison@section Suppressing Differences in Blank Lines@cindex blank line difference suppressionThe @samp{-B} and @samp{--ignore-blank-lines} options ignore insertionsor deletions of blank lines.  These options normally affect only linesthat are completely empty; they do not affect lines that look empty butcontain space or tab characters.  With these options, 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.2.  A line is breadthless length.-- Euclid, The Elements, I@end example@node Case Folding, Specified Folding, Blank Lines, Comparison@section Suppressing Case Differences@cindex case difference suppression

⌨️ 快捷键说明

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