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

📄 diff.texi

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
output line represents two differing lines, one might be incompletewhile the other is not.  In this case, the output line is complete,but its the gutter is marked @samp{\} if the first line is incomplete,@samp{/} if the second line is.Side by side format is sometimes easiest to read, but it has limitations.It generates much wider output than usual, and truncates lines that aretoo long to fit.  Also, it relies on lining up output more heavily thanusual, so its output looks particularly bad if you use varyingwidth fonts, nonstandard tab stops, or nonprinting characters.You can use the @code{sdiff} command to interactively merge side by sidedifferences.  @xref{Interactive Merging}, for more information on merging files.@menu* Side by Side Format::		Controlling side by side output format.* Example Side by Side::	Sample side by side output.@end menu@node Side by Side Format, Example Side by Side, , Side by Side@section Controlling Side by Side Format@cindex side by side formatThe @samp{-y} or @samp{--side-by-side} option selects side by sideformat.  Because side by side output lines contain two input lines, theyare wider than usual.  They are normally 130 columns, which can fit ontoa traditional printer line.  You can set the length of output lines withthe @samp{-W @var{columns}} or @samp{--width=@var{columns}} option.  Theoutput line is split into two halves of equal length, separated by asmall gutter to mark differences; the right half is aligned to a tabstop so that tabs line up.  Input lines that are too long to fit in halfof an output line are truncated for output.The @samp{--left-column} option prints only the left column of twocommon lines.  The @samp{--suppress-common-lines} option suppressescommon lines entirely.@node Example Side by Side, , Side by Side Format, Side by Side@subsection An Example of Side by Side FormatHere is the output of the command @samp{diff -y -W 72 lao tzu}(@pxref{Sample diff Input}, for the complete contents of the two files).@exampleThe Way that can be told of is n   <The name that can be named is no   <The Nameless is the origin of He        The Nameless is the origin of HeThe Named is the mother of all t   |    The named is the mother of all t                                   >Therefore let there always be no        Therefore let there always be no  so we may see their subtlety,           so we may see their subtlety,And let there always be being,          And let there always be being,  so we may see their outcome.            so we may see their outcome.The two are the same,                   The two are the same,But after they are produced,            But after they are produced,  they have different names.              they have different names.                                   >    They both may be called deep and                                   >    Deeper and more profound,                                   >    The door of all subtleties!@end example@node Scripts, If-then-else, Side by Side, Output Formats@section Making Edit Scripts@cindex script output formatsSeveral output modes produce command scripts for editing @var{from-file}to produce @var{to-file}.@menu* ed Scripts::		Using @code{diff} to produce commands for @code{ed}.* Forward ed::		Making forward @code{ed} scripts.* RCS::			A special @code{diff} output format used by RCS.@end menu@node ed Scripts, Forward ed, , Scripts@subsection @code{ed} Scripts@cindex @code{ed} script output format@code{diff} can produce commands that direct the @code{ed} text editorto change the first file into the second file.  Long ago, this was theonly output mode that was suitable for editing one file into anotherautomatically; today, with @code{patch}, it is almost obsolete.  Use the@samp{-e} or @samp{--ed} option to select this output format.Like the normal format (@pxref{Normal}), this output format does notshow any context; unlike the normal format, it does not include theinformation necessary to apply the diff in reverse (to produce the firstfile if all you have is the second file and the diff).If the file @file{d} contains the output of @samp{diff -e old new}, thenthe command @samp{(cat d && echo w) | ed - old} edits @file{old} to makeit a copy of @file{new}.  More generally, if @file{d1}, @file{d2},@dots{}, @file{dN} contain the outputs of @samp{diff -e old new1},@samp{diff -e new1 new2}, @dots{}, @samp{diff -e newN-1 newN},respectively, then the command @samp{(cat d1 d2 @dots{} dN && echo w) |ed - old} edits @file{old} to make it a copy of @file{newN}.@menu* Detailed ed::		A detailed description of @code{ed} format.* Example ed::		A sample @code{ed} script.@end menu@node Detailed ed, Example ed, , ed Scripts@subsubsection Detailed Description of @code{ed} FormatThe @code{ed} output format consists of one or more hunks ofdifferences.  The changes closest to the ends of the files come first sothat commands that change the number of lines do not affect how@code{ed} interprets line numbers in succeeding commands.  @code{ed}format hunks look like this:@example@var{change-command}@var{to-file-line}@var{to-file-line}@dots{}.@end exampleBecause @code{ed} uses a single period on a line to indicate the end ofinput, GNU @code{diff} protects lines of changes that contain a singleperiod on a line by writing two periods instead, then writing asubsequent @code{ed} command to change the two periods into one.  The@code{ed} format cannot represent an incomplete line, so if the secondfile ends in a changed incomplete line, @code{diff} reports an error andthen pretends that a newline was appended.There are three types of change commands.  Each consists of a linenumber or comma-separated range of lines in the first file and a singlecharacter indicating the kind of change to make.  All line numbers arethe original line numbers in the file.  The types of change commandsare:@table @samp@item @var{l}aAdd text from the second file after line @var{l} in the first file.  Forexample, @samp{8a} means to add the following lines after line 8 of file1.@item @var{r}cReplace the lines in range @var{r} in the first file with the followinglines.  Like a combined add and delete, but more compact.  For example,@samp{5,7c} means change lines 5--7 of file 1 to read as the text file2.@item @var{r}dDelete the lines in range @var{r} from the first file.  For example,@samp{5,7d} means delete lines 5--7 of file 1.@end table@node Example ed, , Detailed ed, ed Scripts@subsubsection Example @code{ed} ScriptHere is the output of @samp{diff -e lao tzu} (@pxref{Samplediff Input}, for the complete contents of the two files):@example11aThey both may be called deep and profound.Deeper and more profound,The door of all subtleties!.4cThe named is the mother of all things..1,2d@end example@node Forward ed, RCS, ed Scripts, Scripts@subsection Forward @code{ed} Scripts@cindex forward @code{ed} script output format@code{diff} can produce output that is like an @code{ed} script, butwith hunks in forward (front to back) order.  The format of the commandsis also changed slightly: command characters precede the lines theymodify, spaces separate line numbers in ranges, and no attempt is madeto disambiguate hunk lines consisting of a single period.  Like@code{ed} format, forward @code{ed} format cannot represent incompletelines.Forward @code{ed} format is not very useful, because neither @code{ed}nor @code{patch} can apply diffs in this format.  It exists mainly forcompatibility with older versions of @code{diff}.  Use the @samp{-f} or@samp{--forward-ed} option to select it.@node RCS, , Forward ed, Scripts@subsection RCS Scripts@cindex RCS script output formatThe RCS output format is designed specifically for use by the RevisionControl System, which is a set of free programs used for organizingdifferent versions and systems of files.  Use the @samp{-n} or@samp{--rcs} option to select this output format.  It is like theforward @code{ed} format (@pxref{Forward ed}), but it can representarbitrary changes to the contents of a file because it avoids theforward @code{ed} format's problems with lines consisting of a singleperiod and with incomplete lines.  Instead of ending text sections witha line consisting of a single period, each command specifies the numberof lines it affects; a combination of the @samp{a} and @samp{d}commands are used instead of @samp{c}.  Also, if the second file endsin a changed incomplete line, then the output also ends in anincomplete line.Here is the output of @samp{diff -n lao tzu} (@pxref{Samplediff Input}, for the complete contents of the two files):@exampled1 2d4 1a4 2The named is the mother of all things.a11 3They both may be called deep and profound.Deeper and more profound,The door of all subtleties!@end example@node If-then-else, , Scripts, Output Formats@section Merging Files with If-then-else@cindex merged output format@cindex if-then-else output format@cindex C if-then-else output format@cindex @code{ifdef} output formatYou can use @code{diff} to merge two files of C source code.  The outputof @code{diff} in this format contains all the lines of both files.Lines common to both files are output just once; the differing parts areseparated by the C preprocessor directives @code{#ifdef @var{name}} or@code{#ifndef @var{name}}, @code{#else}, and @code{#endif}.  Whencompiling the output, you select which version to use by either definingor leaving undefined the macro @var{name}.To merge two files, use @code{diff} with the @samp{-D @var{name}} or@samp{--ifdef=@var{name}} option.  The argument @var{name} is the Cpreprocessor identifier to use in the @code{#ifdef} and @code{#ifndef}directives.For example, if you change an instance of @code{wait (&s)} to@code{waitpid (-1, &s, 0)} and then merge the old and new files withthe @samp{--ifdef=HAVE_WAITPID} option, then the affected part of your codemight look like this:@example    do @{#ifndef HAVE_WAITPID        if ((w = wait (&s)) < 0  &&  errno != EINTR)#else /* HAVE_WAITPID */        if ((w = waitpid (-1, &s, 0)) < 0  &&  errno != EINTR)#endif /* HAVE_WAITPID */            return w;    @} while (w != child);@end exampleYou can specify formats for languages other than C by using line groupformats and line formats, as described in the next sections.@menu* Line Group Formats::		Formats for general if-then-else line groups.* Line Formats::		Formats for each line in a line group.* Detailed If-then-else::	A detailed description of if-then-else format.* Example If-then-else::	Sample if-then-else format output.@end menu@node Line Group Formats, Line Formats, , If-then-else@subsection Line Group Formats@cindex line group formats@cindex formats for if-then-else line groupsLine group formats let you specify formats suitable for manyapplications that allow if-then-else input, including programminglanguages and text formatting languages.  A line group format specifiesthe output format for a contiguous group of similar lines.For example, the following command compares the TeX files @file{old}and @file{new}, and outputs a merged file in which old regions aresurrounded by @samp{\begin@{em@}}-@samp{\end@{em@}} lines, and newregions are surrounded by @samp{\begin@{bf@}}-@samp{\end@{bf@}} lines.@examplediff \   --old-group-format='\begin@{em@}%<\end@{em@}' \   --new-group-format='\begin@{bf@}%>\end@{bf@}' \   old new@end exampleThe following command is equivalent to the above example, but it is alittle more verbose, because it spells out the default line group formats.@examplediff \   --old-group-format='\begin@{em@}%<\end@{em@}' \   --new-group-format='\begin@{bf@}%>\end@{bf@}' \   --unchanged-group-format='%=' \   --changed-group-format='\begin@{em@}%<\end@{em@}\begin@{bf@}%>\end@{bf@}' \   old new@end exampleHere is a more advanced example, which outputs a diff listing withheaders containing line numbers in a ``plain English'' style.@examplediff \   --unchanged-group-format='' \   --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:%<' \   --new-group-format='-------- %dN line%(N=1?:s) added after %de:%>' \   --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:%<-------- to:%>' \   old new@end exampleTo specify a line group format, use @code{diff} with one of the optionslisted below.  You can specify up to four line group formats, one foreach kind of line group.  You should quote @var{format}, because ittypically contains shell metacharacters.@table @samp@item --old-group-format=@var{format}These line groups are hunks containing only lines from the first file.

⌨️ 快捷键说明

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