shithub: riscv

ref: fcb6d6ec65fb82c3b6b936dd148df72b9955994b
dir: /sys/man/1/diff/

View raw version
.TH DIFF 1 
.SH NAME
diff, merge3 \- differential file comparisons
.SH SYNOPSIS
.B diff
[
.B -abcefmnruw
]
.I file1 ... file2
.PP
.B merge3
.I left common right
.SH DESCRIPTION
.I Diff
tells what lines must be changed in two files to bring them
into agreement.
If one file
is a directory,
then a file in that directory with basename the same as that of
the other file is used.
If both files are directories, similarly named files in the
two directories are compared by the method of 
.I diff
for text
files and
.IR cmp (1)
otherwise.
If more than two file names are given, then each argument is compared
to the last argument as above.
The 
.B -r
option causes
.I diff
to process similarly named subdirectories recursively.
When processing more than one file, 
.I diff
prefixes file differences with a single line
listing the two differing files, in the form of
a 
.I diff
command line.
The
.B -m
flag causes this behavior even when processing single files.
.PP
The normal output contains lines of these forms:
.IP "" 5
.I n1
.B a
.I n3,n4
.br
.I n1,n2
.B d
.I n3
.br
.I n1,n2
.B c
.I n3,n4
.PP
These lines resemble
.I ed
commands to convert
.I file1
into
.IR file2 .
The numbers after the letters pertain to
.IR file2 .
In fact, by exchanging `a' for `d' and reading backward
one may ascertain equally how to convert 
.I file2
into
.IR file1 .
As in 
.IR ed ,
identical pairs where
.I n1
=
.I n2
or
.I n3
=
.I n4
are abbreviated as a single number.
.PP
Following each of these lines come all the lines that are
affected in the first file flagged by `<', 
then all the lines that are affected in the second file
flagged by `>'.
.PP
The
.B -b
option causes
trailing blanks (spaces and tabs) to be ignored
and other strings of blanks to compare equal.
The
.B -w
option causes all white-space to be removed from input lines
before applying the difference algorithm.
.PP
The
.B -n
option prefixes each range with 
.IB file : \fR
and inserts a space around the 
.BR a ,
.BR c ,
and
.B d
verbs.
The
.B -e
option produces a script of
.I "a, c"
and 
.I d
commands for the editor
.IR ed ,
which will recreate
.I file2
from
.IR file1 .
The
.B -f
option produces a similar script,
not useful with
.IR ed ,
in the opposite order. It may, however, be
useful as input to a stream-oriented post-processor.
.PP
The
.B -c
option includes three lines of context around each
change, merging changes whose contexts overlap.
In this mode,
.I diff
prints
.L -
and
.L +
instead of
.L <
and
.L >
because the former are easier to distinguish when mixed.
The
.B -a
flag displays the entire file as context.
.PP
The
.B -u
option provides a unix-compatible unified diff.
This format is similar to that provided by
.BR -c .
However, the
.L +
and
.L -
prefixes are not separated from the rest of the line by spaces,
and the file header is in the following format:
.IP
.EX
--- filename.old
+++ filename.new
@@ -line,len +line,len @@
.EE
.PP
Except in rare circumstances,
.I diff
finds a smallest sufficient set of file
differences.
.PP
Merge3 merges the contents of
.I left
and
.I right
using
.I common
as a common reference between the two files.
Changes between
.IR left ,
.I right
and
.I common
are computed.
Any change which does not conflict is output directly.
When a change does conflict, that is to say,
affects the same lines of the output file,
then the change is output with conflict markers.
The conflict markers look like this:
.IP
.EX
leading content
<<<<<<<<<< leftfile
this is an edit made
to the left file
========== original
this is the initial content
========== rightfile
here is something that was
written into the right file
>>>>>>>>>>
trailing content
.EE
.PP
If no conflicts are detected,
.I merge3
exits with a nil status,
otherwise it exits with a status of "conflicted".
.SH FILES
.B /tmp/diff[12]
.SH SOURCE
.B /sys/src/cmd/diff
.SH "SEE ALSO"
.IR cmp (1),
.IR comm (1),
.IR ed (1),
.IR idiff (1)
.SH DIAGNOSTICS
Exit status is the empty string
for no differences,
.L some
for some, 
and
.L error
for trouble.
.SH BUGS
Editing scripts produced under the
.BR -e " or"
.BR -f " option are naive about"
creating lines consisting of a single `\fB.\fR'.
.PP
When running
.I diff
on directories, the notion of what is a text
file is open to debate.