📄 diff.texi
字号:
+ They both may be called deep and profound.+ Deeper and more profound,+ The door of all subtleties!@end example@node Detailed Context@subsubsection Detailed Description of Context FormatThe context 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@noindent@vindex LC_TIME@cindex time stamp format, context diffsThe time stamp normally looks like @samp{2002-02-21 23:30:39.942229878-0800} to indicate the date, time with fractional seconds, and timezone in @uref{ftp://ftp.isi.edu/in-notes/rfc2822.txt, Internet RFC2822 format}. (The fractional seconds are omitted on hosts that donot support fractional time stamps.) However, a traditional timestamp like @samp{Thu Feb 21 23:30:39 2002} is used if the@env{LC_TIME} locale category is either @samp{C} or @samp{POSIX}.You can change the header's content with the@option{--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-numbers} **** @var{from-file-line} @var{from-file-line}@dots{}--- @var{to-file-line-numbers} ---- @var{to-file-line} @var{to-file-line}@dots{}@end exampleIf a hunk contains two or more lines, its line numbers look like@samp{@var{start},@var{end}}. Otherwise only its end line numberappears. An empty hunk is considered to end at the line that precedesthe hunk.The 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 Unified Format@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 @option{-U @var{lines}},@option{--unified@r{[}=@var{lines}@r{]}}, or @option{-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 @acronym{GNU} @command{diff} can produce this format andonly @acronym{GNU} @command{patch} can automatically apply diffs in thisformat. For proper operation, @command{patch} typically needs atleast three lines of context.@menu* Example Unified:: Sample output in unified format.* Detailed Unified:: A detailed description of unified format.@end menu@node Example Unified@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 2002-02-21 23:30:39.942229878 -0800+++ tzu 2002-02-21 23:30:50.442260588 -0800@@@@ -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 Detailed Unified@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@noindent@cindex time stamp format, unified diffsThe time stamp looks like @samp{2002-02-21 23:30:39.942229878 -0800}to indicate the date, time with fractional seconds, and time zone.The fractional seconds are omitted on hosts that do not supportfractional time stamps.You can change the header's content with the@option{--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-line-numbers} @var{to-file-line-numbers} @@@@ @var{line-from-either-file} @var{line-from-either-file}@dots{}@end exampleIf a hunk contains just one line, only its start line number appears.Otherwise its line numbers look like @samp{@var{start},@var{count}}.An empty hunk is considered to start at the line that follows the hunk.If a hunk and its context contain two or more lines, itsline numbers look like @samp{@var{start},@var{count}}. Otherwise onlyits end line number appears. An empty hunk is considered to end atthe line that precedes the hunk.The 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 print 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 Sections@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 whichfunction was changed. If the files are documents, it could mean whichchapter or appendix was changed. @acronym{GNU} @command{diff} canshow this by displaying the nearest section heading line that precedesthe differing lines. Which lines are ``section headings'' isdetermined 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@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 @option{-F @var{regexp}}or @option{--show-function-line=@var{regexp}} option. @command{diff}considers lines that match the @command{grep}-style regular expression@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, Perl, Python.@table @samp@item ^[[:alpha:]$_]C, C++, Prolog@item ^(Lisp@item ^@@nodeTexinfo@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 @option{-F} or @option{--show-function-line} option finds the nearestunchanged line that precedes each hunk of differences and matches thegiven regular expression. Then it adds 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, this option leaves the output forthat hunk unchanged. If that line is more than 40 characters long, itoutputs only the first 40 characters. You can specify more than oneregular expression for such lines; @command{diff} tries to match each lineagainst each regular expression, starting with the last one given. Thismeans that you can use @option{-p} and @option{-F} together, if you wish.@node C Function Headings@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 @option{-p} or @option{--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 @option{-C @var{lines}} elsewhere in thecommand line. You can override both the format and the number with@option{-U @var{lines}} elsewhere in the command line.The @option{-p} or @option{--show-c-function} option is equivalent to@option{-F '^[[:alpha:]$_]'} if the unified format is specified, otherwise@option{-c -F '^[[:alpha:]$_]'} (@pxref{Specified Headings}). @acronym{GNU}@command{diff} provides this option for the sake of convenience.@node Alternate Names@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 @command{diff} to show alternate names in the headerof the context and unified output formats. To do this, use the@option{--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, @command{diff} reports an error. The @option{--label} option does notaffect the file names in the @command{pr} header when the @option{-l} or@option{--paginate} option is used (@pxref{Pagination}).Here are the first two lines of the output from @samp{diff -C 2--label=original --label=modified lao tzu}:@example*** original--- modified@end example@node Side by Side@section Showing Differences Side by Side@cindex side by side@cindex two-column output@cindex columnar output@command{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@option{--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 anoutput 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 @command{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@subsection Controlling Side by Side Format@cindex side by side formatThe @option{-y} or @option{--side-by-side} option selects side by sideformat. Because side by side output lines contain two input lines, theoutput is wider than usual: normally 130 print columns, which can fitonto a traditional printer line. You can set the width of the output
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -