📄 diff.texi
字号:
@noindentYou can change the header's content with the @samp{-L @var{label}} or@samp{--label=@var{label}} option; see @ref{Alternate Names}.Next come one or more hunks of differences; each hunk shows one areawhere the files differ. Context format hunks look like this:@example****************** @var{from-file-line-range} **** @var{from-file-line} @var{from-file-line}@dots{}--- @var{to-file-line-range} ---- @var{to-file-line} @var{to-file-line}@dots{}@end exampleThe lines of context around the lines that differ start with two spacecharacters. The lines that differ between the two files start with oneof the following indicator characters, followed by a space character:@table @samp@item !A line that is part of a group of one or more lines that changed betweenthe two files. There is a corresponding group of lines marked with@samp{!} in the part of this hunk for the other file.@item +An ``inserted'' line in the second file that corresponds to nothing inthe first file.@item -A ``deleted'' line in the first file that corresponds to nothing in thesecond file.@end tableIf all of the changes in a hunk are insertions, the lines of@var{from-file} are omitted. If all of the changes are deletions, thelines of @var{to-file} are omitted.@node Example Context, Less Context, Detailed Context, Context Format@subsubsection An Example of Context FormatHere is the output of @samp{diff -c lao tzu} (@pxref{Sample diff Input},for the complete contents of the two files). Notice that up to threelines that are not different are shown around each line that isdifferent; they are the context lines. Also notice that the first twohunks have run together, because their contents overlap.@example*** lao Sat Jan 26 23:30:39 1991--- tzu Sat Jan 26 23:30:50 1991****************** 1,7 ****- The Way that can be told of is not the eternal Way;- The name that can be named is not the eternal name. The Nameless is the origin of Heaven and Earth;! The Named is the mother of all things. Therefore let there always be non-being, so we may see their subtlety, And let there always be being,--- 1,6 ---- The Nameless is the origin of Heaven and Earth;! The named is the mother of all things.! Therefore let there always be non-being, so we may see their subtlety, And let there always be being,****************** 9,11 ****--- 8,13 ---- The two are the same, But after they are produced, they have different names.+ They both may be called deep and profound.+ Deeper and more profound,+ The door of all subtleties!@end example@node Less Context, , Example Context, Context Format@subsubsection An Example of Context Format with Less ContextHere is the output of @samp{diff --context=1 lao tzu} (@pxref{Samplediff Input}, for the complete contents of the two files). Notice thatat most one context line is reported here.@example*** lao Sat Jan 26 23:30:39 1991--- tzu Sat Jan 26 23:30:50 1991****************** 1,5 ****- The Way that can be told of is not the eternal Way;- The name that can be named is not the eternal name. The Nameless is the origin of Heaven and Earth;! The Named is the mother of all things. Therefore let there always be non-being,--- 1,4 ---- The Nameless is the origin of Heaven and Earth;! The named is the mother of all things.! Therefore let there always be non-being,****************** 11 ****--- 10,13 ---- they have different names.+ They both may be called deep and profound.+ Deeper and more profound,+ The door of all subtleties!@end example@node Unified Format, Sections, Context Format, Context@subsection Unified Format@cindex unified output format@cindex @samp{+-} output formatThe unified output format is a variation on the context format that ismore compact because it omits redundant context lines. To select thisoutput format, use the @samp{-U @var{lines}},@samp{--unified@r{[}=@var{lines}@r{]}}, or @samp{-u}option. The argument @var{lines} is the number of lines of context toshow. When it is not given, it defaults to three.At present, only GNU @code{diff} can produce this format and only GNU@code{patch} can automatically apply diffs in this format. For properoperation, @code{patch} typically needs at least two lines of context.@menu* Detailed Unified:: A detailed description of unified format.* Example Unified:: Sample output in unified format.@end menu@node Detailed Unified, Example Unified, , Unified Format@subsubsection Detailed Description of Unified FormatThe unified output format starts with a two-line header, which lookslike this:@example--- @var{from-file} @var{from-file-modification-time}+++ @var{to-file} @var{to-file-modification-time}@end example@noindentYou can change the header's content with the @samp{-L @var{label}} or@samp{--label=@var{label}} option; see @xref{Alternate Names}.Next come one or more hunks of differences; each hunk shows one areawhere the files differ. Unified format hunks look like this:@example@@@@ @var{from-file-range} @var{to-file-range} @@@@ @var{line-from-either-file} @var{line-from-either-file}@dots{}@end exampleThe lines common to both files begin with a space character. The linesthat actually differ between the two files have one of the followingindicator characters in the left column:@table @samp@item +A line was added here to the first file.@item -A line was removed here from the first file.@end table@node Example Unified, , Detailed Unified, Unified Format@subsubsection An Example of Unified FormatHere is the output of the command @samp{diff -u lao tzu}(@pxref{Sample diff Input}, for the complete contents of the two files):@example--- lao Sat Jan 26 23:30:39 1991+++ tzu Sat Jan 26 23:30:50 1991@@@@ -1,7 +1,6 @@@@-The Way that can be told of is not the eternal Way;-The name that can be named is not the eternal name. The Nameless is the origin of Heaven and Earth;-The Named is the mother of all things.+The named is the mother of all things.+ Therefore let there always be non-being, so we may see their subtlety, And let there always be being,@@@@ -9,3 +8,6 @@@@ The two are the same, But after they are produced, they have different names.+They both may be called deep and profound.+Deeper and more profound,+The door of all subtleties!@end example@node Sections, Alternate Names, Unified Format, Context@subsection Showing Which Sections Differences Are in@cindex headings@cindex section headingsSometimes you might want to know which part of the files each changefalls in. If the files are source code, this could mean which functionwas changed. If the files are documents, it could mean which chapter orappendix was changed. GNU @code{diff} can show this by displaying thenearest section heading line that precedes the differing lines. Whichlines are ``section headings'' is determined by a regular expression.@menu* Specified Headings:: Showing headings that match regular expressions.* C Function Headings:: Showing headings of C functions.@end menu@node Specified Headings, C Function Headings, , Sections@subsubsection Showing Lines That Match Regular Expressions@cindex specified headings@cindex regular expression matching headingsTo show in which sections differences occur for files that are notsource code for C or similar languages, use the @samp{-F @var{regexp}}or @samp{--show-function-line=@var{regexp}} option. @code{diff}considers lines that match the argument @var{regexp} to be the beginningof a section of the file. Here are suggested regular expressions forsome common languages:@c Please add to this list, e.g. Fortran, Pascal.@table @samp@item ^[A-Za-z_]C, C++, Prolog@item ^(Lisp@item ^@@\(chapter\|appendix\|unnumbered\|chapheading\)Texinfo@end tableThis option does not automatically select an output format; in order touse it, you must select the context format (@pxref{Context Format}) orunified format (@pxref{Unified Format}). In other output formats ithas no effect.The @samp{-F} and @samp{--show-function-line} options find the nearestunchanged line that precedes each hunk of differences and matches thegiven regular expression. Then they add that line to the end of theline of asterisks in the context format, or to the @samp{@@@@} line inunified format. If no matching line exists, they leave the output forthat hunk unchanged. If that line is more than 40 characters long, theyoutput only the first 40 characters. You can specify more than oneregular expression for such lines; @code{diff} tries to match each lineagainst each regular expression, starting with the last one given. Thismeans that you can use @samp{-p} and @samp{-F} together, if you wish.@node C Function Headings, , Specified Headings, Sections@subsubsection Showing C Function Headings@cindex C function headings@cindex function headings, CTo show in which functions differences occur for C and similarlanguages, you can use the @samp{-p} or @samp{--show-c-function} option.This option automatically defaults to the context output format(@pxref{Context Format}), with the default number of lines of context.You can override that number with @samp{-C @var{lines}} elsewhere in thecommand line. You can override both the format and the number with@samp{-U @var{lines}} elsewhere in the command line.The @samp{-p} and @samp{--show-c-function} options are equivalent to@samp{-F'^[_a-zA-Z$]'} if the unified format is specified, otherwise@samp{-c -F'^[_a-zA-Z$]'} (@pxref{Specified Headings}). GNU @code{diff}provides them for the sake of convenience.@node Alternate Names, , Sections, Context@subsection Showing Alternate File Names@cindex alternate file names@cindex file name alternatesIf you are comparing two files that have meaningless or uninformativenames, you might want @code{diff} to show alternate names in the headerof the context and unified output formats. To do this, use the @samp{-L@var{label}} or @samp{--label=@var{label}} option. The first timeyou give this option, its argument replaces the name and date of thefirst file in the header; the second time, its argument replaces thename and date of the second file. If you give this option more thantwice, @code{diff} reports an error. The @samp{-L} option does notaffect the file names in the @code{pr} header when the @samp{-l} or@samp{--paginate} option is used (@pxref{Pagination}).Here are the first two lines of the output from @samp{diff -C2-Loriginal -Lmodified lao tzu}:@example*** original--- modified@end example@node Side by Side, Scripts, Context, Output Formats@section Showing Differences Side by Side@cindex side by side@cindex two-column output@cindex columnar output@code{diff} can produce a side by side difference listing of two files.The files are listed in two columns with a gutter between them. Thegutter contains one of the following markers:@table @asis@item white spaceThe corresponding lines are in common. That is, either the lines areidentical, or the difference is ignored because of one of the@samp{--ignore} options (@pxref{White Space}).@item @samp{|}The corresponding lines differ, and they are either both completeor both incomplete.@item @samp{<}The files differ and only the first file contains the line.@item @samp{>}The files differ and only the second file contains the line.@item @samp{(}Only the first file contains the line, but the difference is ignored.@item @samp{)}Only the second file contains the line, but the difference is ignored.@item @samp{\}The corresponding lines differ, and only the first line is incomplete.@item @samp{/}The corresponding lines differ, and only the second line is incomplete.@end tableNormally, an output line is incomplete if and only if the lines that itcontains are incomplete; @xref{Incomplete Lines}. However, when an
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -