<s>
In	O
computing	O
,	O
the	O
utility	O
diff	B-Application
is	O
a	O
data	B-Application
comparison	I-Application
tool	O
that	O
computes	O
and	O
displays	O
the	O
differences	O
between	O
the	O
contents	O
of	O
files	O
.	O
</s>
<s>
Unlike	O
edit	O
distance	O
notions	O
used	O
for	O
other	O
purposes	O
,	O
diff	B-Application
is	O
line-oriented	O
rather	O
than	O
character-oriented	O
,	O
but	O
it	O
is	O
like	O
Levenshtein	O
distance	O
in	O
that	O
it	O
tries	O
to	O
determine	O
the	O
smallest	O
set	O
of	O
deletions	O
and	O
insertions	O
to	O
create	O
one	O
file	O
from	O
the	O
other	O
.	O
</s>
<s>
The	O
utility	O
displays	O
the	O
changes	O
in	O
one	O
of	O
several	O
standard	O
formats	O
,	O
such	O
that	O
both	O
humans	O
or	O
computers	O
can	O
parse	O
the	O
changes	O
,	O
and	O
use	O
them	O
for	O
patching	B-Application
.	O
</s>
<s>
Typically	O
,	O
diff	B-Application
is	O
used	O
to	O
show	O
the	O
changes	O
between	O
two	O
versions	O
of	O
the	O
same	O
file	O
.	O
</s>
<s>
The	O
output	O
is	O
called	O
a	O
"	O
diff	B-Application
"	O
,	O
or	O
a	O
patch	B-Application
,	O
since	O
the	O
output	O
can	O
be	O
applied	O
with	O
the	O
Unix	B-Application
program	O
.	O
</s>
<s>
The	O
output	O
of	O
similar	O
file	B-Application
comparison	I-Application
utilities	O
is	O
also	O
called	O
a	O
"	O
diff	B-Application
"	O
;	O
like	O
the	O
use	O
of	O
the	O
word	O
"	O
grep	B-Application
"	O
for	O
describing	O
the	O
act	O
of	O
searching	O
,	O
the	O
word	O
diff	B-Application
became	O
a	O
generic	O
term	O
for	O
calculating	O
data	O
difference	O
and	O
the	O
results	O
thereof	O
.	O
</s>
<s>
The	O
POSIX	O
standard	O
specifies	O
the	O
behavior	O
of	O
the	O
"	O
diff	B-Application
"	O
and	O
"	O
patch	B-Application
"	O
utilities	O
and	O
their	O
file	O
formats	O
.	O
</s>
<s>
diff	B-Application
was	O
developed	O
in	O
the	O
early	O
1970s	O
on	O
the	O
Unix	B-Application
operating	I-Application
system	I-Application
,	O
which	O
was	O
emerging	O
from	O
Bell	O
Labs	O
in	O
Murray	O
Hill	O
,	O
New	O
Jersey	O
.	O
</s>
<s>
The	O
first	O
released	O
version	O
shipped	O
with	O
the	O
5th	O
Edition	O
of	O
Unix	B-Application
in	O
1974	O
,	O
and	O
was	O
written	O
by	O
Douglas	O
McIlroy	O
,	O
and	O
James	O
Hunt	O
.	O
</s>
<s>
McIlroy	O
's	O
work	O
was	O
preceded	O
and	O
influenced	O
by	O
Steve	O
Johnson	O
's	O
comparison	O
program	O
on	O
GECOS	B-Application
and	O
Mike	O
Lesk	O
's	O
program	O
.	O
</s>
<s>
also	O
originated	O
on	O
Unix	B-Application
and	O
,	O
like	O
,	O
produced	O
line-by-line	O
changes	O
and	O
even	O
used	O
angle-brackets	O
(">"	O
and	O
""	O
)	O
for	O
presenting	O
line	O
insertions	O
and	O
deletions	O
in	O
the	O
program	O
's	O
output	O
.	O
</s>
<s>
The	O
heuristics	B-Algorithm
used	O
in	O
these	O
early	O
applications	O
were	O
,	O
however	O
,	O
deemed	O
unreliable	O
.	O
</s>
<s>
The	O
potential	O
usefulness	O
of	O
a	O
diff	B-Application
tool	O
provoked	O
McIlroy	O
into	O
researching	O
and	O
designing	O
a	O
more	O
robust	O
tool	O
that	O
could	O
be	O
used	O
in	O
a	O
variety	O
of	O
tasks	O
,	O
but	O
perform	O
well	O
in	O
the	O
processing	O
and	O
size	O
limitations	O
of	O
the	O
PDP-11	B-Device
'	O
s	O
hardware	O
.	O
</s>
<s>
In	O
the	O
context	O
of	O
Unix	B-Application
,	O
the	O
use	O
of	O
the	O
line	O
editor	O
provided	O
with	O
the	O
natural	O
ability	O
to	O
create	O
machine-usable	O
"	O
edit	O
scripts	O
"	O
.	O
</s>
<s>
McIlroy	O
considered	O
writing	O
a	O
post-processor	O
for	O
where	O
a	O
variety	O
of	O
output	O
formats	O
could	O
be	O
designed	O
and	O
implemented	O
,	O
but	O
he	O
found	O
it	O
more	O
frugal	O
and	O
simpler	O
to	O
have	O
be	O
responsible	O
for	O
generating	O
the	O
syntax	O
and	O
reverse-order	O
input	O
accepted	O
by	O
the	O
command	B-Application
.	O
</s>
<s>
Late	O
in	O
1984	O
Larry	O
Wall	O
created	O
a	O
separate	O
utility	O
,	O
patch	B-Application
,	O
</s>
<s>
Modes	O
in	O
Emacs	B-Application
also	O
allow	O
for	O
converting	O
the	O
format	O
of	O
patches	B-Application
and	O
even	O
editing	O
patches	B-Application
interactively	O
.	O
</s>
<s>
The	O
Source	B-Device
Code	I-Device
Control	I-Device
System	I-Device
(	O
SCCS	O
)	O
and	O
its	O
ability	O
to	O
archive	O
revisions	O
emerged	O
in	O
the	O
late	O
1970s	O
as	O
a	O
consequence	O
of	O
storing	O
edit	O
scripts	O
from	O
.	O
</s>
<s>
The	O
diff	B-Application
command	B-Application
is	O
invoked	O
from	O
the	O
command	B-Application
line	O
,	O
passing	O
it	O
the	O
names	O
of	O
two	O
files	O
:	O
diff	B-Application
original	O
new	O
.	O
</s>
<s>
The	O
output	O
of	O
the	O
command	B-Application
represents	O
the	O
changes	O
required	O
to	O
transform	O
the	O
original	O
file	O
into	O
the	O
new	O
file	O
.	O
</s>
<s>
The	O
command	B-Application
diff	B-Application
original	O
new	O
produces	O
the	O
following	O
normal	O
diff	B-Application
output	O
:	O
</s>
<s>
Here	O
,	O
the	O
diff	B-Application
output	O
is	O
shown	O
with	O
colors	O
to	O
make	O
it	O
easier	O
to	O
read	O
.	O
</s>
<s>
The	O
diff	B-Application
utility	I-Application
does	O
not	O
produce	O
colored	O
output	O
;	O
its	O
output	O
is	O
plain	O
text	O
.	O
</s>
<s>
In	O
this	O
traditional	O
output	O
format	O
,	O
a	O
stands	O
for	O
added	O
,	O
d	O
for	O
deleted	O
and	O
c	B-Language
for	O
changed	O
.	O
</s>
<s>
Line	O
numbers	O
of	O
the	O
original	O
file	O
appear	O
before	O
a/d/c	O
and	O
those	O
of	O
the	O
new	O
file	O
appear	O
after	O
.	O
</s>
<s>
However	O
,	O
some	O
diff	B-Application
tools	O
highlight	O
moved	O
lines	O
.	O
</s>
<s>
An	O
ed	B-Application
script	I-Application
can	O
still	O
be	O
generated	O
by	O
modern	O
versions	O
of	O
diff	B-Application
with	O
the	O
-e	O
option	O
.	O
</s>
<s>
In	O
order	O
to	O
transform	O
the	O
content	O
of	O
file	O
original	O
into	O
the	O
content	O
of	O
file	O
new	O
using	O
,	O
we	O
should	O
append	O
two	O
lines	O
to	O
this	O
diff	B-Application
file	O
,	O
one	O
line	O
containing	O
a	O
w	O
(	O
write	O
)	O
command	B-Application
,	O
and	O
one	O
containing	O
a	O
q	O
(	O
quit	O
)	O
command	B-Application
(	O
e.g.	O
</s>
<s>
Here	O
we	O
gave	O
the	O
diff	B-Application
file	O
the	O
name	O
mydiff	O
and	O
the	O
transformation	O
will	O
then	O
happen	O
when	O
we	O
run	O
.	O
</s>
<s>
The	O
Berkeley	B-Operating_System
distribution	I-Operating_System
of	I-Operating_System
Unix	I-Operating_System
made	O
a	O
point	O
of	O
adding	O
the	O
context	B-Application
format	I-Application
(	O
)	O
and	O
the	O
ability	O
to	O
recurse	O
on	O
filesystem	O
directory	O
structures	O
(	O
)	O
,	O
adding	O
those	O
features	O
in	O
2.8	O
BSD	B-Operating_System
,	O
released	O
in	O
July	O
1981	O
.	O
</s>
<s>
The	O
context	B-Application
format	I-Application
of	O
diff	B-Application
introduced	O
at	O
Berkeley	O
helped	O
with	O
distributing	O
patches	B-Application
for	O
source	O
code	O
that	O
may	O
have	O
been	O
changed	O
minimally	O
.	O
</s>
<s>
In	O
the	O
context	B-Application
format	I-Application
,	O
any	O
changed	O
lines	O
are	O
shown	O
alongside	O
unchanged	O
lines	O
before	O
and	O
after	O
.	O
</s>
<s>
The	O
inclusion	O
of	O
any	O
number	O
of	O
unchanged	O
lines	O
provides	O
a	O
context	O
to	O
the	O
patch	B-Application
.	O
</s>
<s>
The	O
context	B-Application
format	I-Application
introduces	O
greater	O
readability	O
for	O
humans	O
and	O
reliability	O
when	O
applying	O
the	O
patch	B-Application
,	O
and	O
an	O
output	O
which	O
is	O
accepted	O
as	O
input	O
to	O
the	O
patch	B-Application
program	O
.	O
</s>
<s>
This	O
intelligent	O
behavior	O
is	O
n't	O
possible	O
with	O
the	O
traditional	O
diff	B-Application
output	O
.	O
</s>
<s>
If	O
the	O
context	O
of	O
unchanged	O
lines	O
in	O
a	O
hunk	O
overlap	O
with	O
an	O
adjacent	O
hunk	O
,	O
then	O
diff	B-Application
will	O
avoid	O
duplicating	O
the	O
unchanged	O
lines	O
and	O
merge	B-General_Concept
the	O
hunks	O
into	O
a	O
single	O
hunk	O
.	O
</s>
<s>
At	O
the	O
beginning	O
of	O
the	O
patch	B-Application
is	O
the	O
file	O
information	O
,	O
including	O
the	O
full	O
path	O
and	O
a	O
time	O
stamp	O
delimited	O
by	O
a	O
tab	O
character	O
.	O
</s>
<s>
The	O
command	B-Application
produces	O
the	O
following	O
output	O
:	O
</s>
<s>
Here	O
,	O
the	O
diff	B-Application
output	O
is	O
shown	O
with	O
colors	O
to	O
make	O
it	O
easier	O
to	O
read	O
.	O
</s>
<s>
The	O
diff	B-Application
utility	I-Application
does	O
not	O
produce	O
colored	O
output	O
;	O
its	O
output	O
is	O
plain	O
text	O
.	O
</s>
<s>
The	O
unified	B-Application
format	I-Application
(	O
or	O
unidiff	O
)	O
inherits	O
the	O
technical	O
improvements	O
made	O
by	O
the	O
context	B-Application
format	I-Application
,	O
but	O
produces	O
a	O
smaller	O
diff	B-Application
with	O
old	O
and	O
new	O
text	O
presented	O
immediately	O
adjacent	O
.	O
</s>
<s>
Unified	B-Application
format	I-Application
is	O
usually	O
invoked	O
using	O
the	O
"	O
-u	O
"	O
command	B-Application
line	O
option	O
.	O
</s>
<s>
This	O
output	O
is	O
often	O
used	O
as	O
input	O
to	O
the	O
patch	B-Application
program	O
.	O
</s>
<s>
Many	O
projects	O
specifically	O
request	O
that	O
"	O
diffs	B-Application
"	O
be	O
submitted	O
in	O
the	O
unified	B-Application
format	I-Application
,	O
making	O
unified	O
diff	B-Application
format	O
the	O
most	O
common	O
format	O
for	O
exchange	O
between	O
software	O
developers	O
.	O
</s>
<s>
Unified	O
context	O
diffs	B-Application
were	O
originally	O
developed	O
by	O
Wayne	O
Davison	O
in	O
August	O
1990	O
(	O
in	O
unidiff	O
which	O
appeared	O
in	O
Volume	O
14	O
of	O
comp.sources.misc	O
)	O
.	O
</s>
<s>
Richard	O
Stallman	O
added	O
unified	O
diff	B-Application
support	O
to	O
the	O
GNU	B-Operating_System
Project	I-Operating_System
's	O
diff	B-Application
utility	I-Application
one	O
month	O
later	O
,	O
and	O
the	O
feature	O
debuted	O
in	O
GNU	B-Operating_System
diff	B-Application
1.15	O
,	O
released	O
in	O
January	O
1991	O
.	O
</s>
<s>
GNU	B-Operating_System
diff	B-Application
has	O
since	O
generalized	O
the	O
context	B-Application
format	I-Application
to	O
allow	O
arbitrary	O
formatting	O
of	O
diffs	B-Application
.	O
</s>
<s>
The	O
format	O
starts	O
with	O
the	O
same	O
two-line	O
header	B-General_Concept
as	O
the	O
context	B-Application
format	I-Application
,	O
except	O
that	O
the	O
original	O
file	O
is	O
preceded	O
by	O
"	O
---	O
"	O
and	O
the	O
new	O
file	O
is	O
preceded	O
by	O
"	O
+++	O
"	O
.	O
</s>
<s>
The	O
range	O
information	O
is	O
surrounded	O
by	O
double	O
at	O
signs	O
,	O
and	O
combines	O
onto	O
a	O
single	O
line	O
what	O
appears	O
on	O
two	O
lines	O
in	O
the	O
context	B-Application
format	I-Application
(	O
above	O
)	O
.	O
</s>
<s>
In	O
many	O
versions	O
of	O
GNU	B-Operating_System
diff	B-Application
,	O
each	O
range	O
can	O
omit	O
the	O
comma	O
and	O
trailing	O
value	O
s	O
,	O
in	O
which	O
case	O
s	O
defaults	O
to	O
1	O
.	O
</s>
<s>
Note	O
that	O
the	O
only	O
really	O
interesting	O
value	O
is	O
the	O
l	O
line	O
number	O
of	O
the	O
first	O
range	O
;	O
all	O
the	O
other	O
values	O
can	O
be	O
computed	O
from	O
the	O
diff	B-Application
.	O
</s>
<s>
If	O
hunk	O
size	O
information	O
does	O
not	O
correspond	O
with	O
the	O
number	O
of	O
lines	O
in	O
the	O
hunk	O
,	O
then	O
the	O
diff	B-Application
could	O
be	O
considered	O
invalid	O
and	O
be	O
rejected	O
.	O
</s>
<s>
This	O
is	O
mainly	O
useful	O
to	O
make	O
the	O
diff	B-Application
easier	O
to	O
read	O
.	O
</s>
<s>
When	O
creating	O
a	O
diff	B-Application
with	O
GNU	B-Operating_System
diff	B-Application
,	O
the	O
heading	O
is	O
identified	O
by	O
regular	B-Language
expression	I-Language
matching	O
.	O
</s>
<s>
The	O
command	B-Application
diff	B-Application
-u	O
original	O
new	O
produces	O
the	O
following	O
output	O
:	O
</s>
<s>
Here	O
,	O
the	O
diff	B-Application
output	O
is	O
shown	O
with	O
colors	O
to	O
make	O
it	O
easier	O
to	O
read	O
.	O
</s>
<s>
The	O
diff	B-Application
utility	I-Application
does	O
not	O
produce	O
colored	O
output	O
;	O
its	O
output	O
is	O
plain	O
text	O
.	O
</s>
<s>
This	O
is	O
invisible	O
on	O
screen	O
and	O
can	O
be	O
lost	O
when	O
diffs	B-Application
are	O
copy/pasted	O
from	O
console/terminal	O
screens	O
.	O
</s>
<s>
There	O
are	O
some	O
modifications	O
and	O
extensions	O
to	O
the	O
diff	B-Application
formats	O
that	O
are	O
used	O
and	O
understood	O
by	O
certain	O
programs	O
and	O
in	O
certain	O
contexts	O
.	O
</s>
<s>
For	O
example	O
,	O
some	O
revision	B-Architecture
control	I-Architecture
systems	I-Architecture
—	O
such	O
as	O
Subversion	B-Application
—	O
specify	O
a	O
version	O
number	O
,	O
"	O
working	O
copy	O
"	O
,	O
or	O
any	O
other	O
comment	O
instead	O
of	O
or	O
in	O
addition	O
to	O
a	O
timestamp	O
in	O
the	O
diff	B-Application
's	O
header	B-General_Concept
section	O
.	O
</s>
<s>
Some	O
tools	O
allow	O
diffs	B-Application
for	O
several	O
different	O
files	O
to	O
be	O
merged	O
into	O
one	O
,	O
using	O
a	O
header	B-General_Concept
for	O
each	O
modified	O
file	O
that	O
may	O
look	O
something	O
like	O
this	O
:	O
</s>
<s>
Neither	O
the	O
unidiff	O
utility	O
nor	O
the	O
POSIX	O
diff	B-Application
standard	O
define	O
a	O
way	O
to	O
handle	O
this	O
type	O
of	O
files	O
.	O
</s>
<s>
The	O
patch	B-Application
program	O
is	O
not	O
aware	O
even	O
of	O
an	O
implementation	O
specific	O
diff	B-Application
output	O
.	O
</s>
<s>
Changes	O
since	O
1975	O
include	O
improvements	O
to	O
the	O
core	O
algorithm	O
,	O
the	O
addition	O
of	O
useful	O
features	O
to	O
the	O
command	B-Application
,	O
and	O
the	O
design	O
of	O
new	O
output	O
formats	O
.	O
</s>
<s>
and	O
in	O
A	O
File	B-Application
Comparison	I-Application
Program	O
by	O
Webb	O
Miller	O
and	O
Myers	O
.	O
</s>
<s>
The	O
first	O
editions	O
of	O
the	O
diff	B-Application
program	O
were	O
designed	O
for	O
line	O
comparisons	O
of	O
text	O
files	O
expecting	O
the	O
newline	O
character	O
to	O
delimit	O
lines	O
.	O
</s>
<s>
GNU	B-Operating_System
diff	B-Application
and	O
diff3	B-Application
are	O
included	O
in	O
the	O
diffutils	B-Application
package	O
with	O
other	O
diff	B-Application
and	O
patch	B-Application
related	O
utilities	O
.	O
</s>
<s>
Nowadays	O
there	O
is	O
also	O
a	O
patchutils	O
package	O
that	O
can	O
combine	O
,	O
rearrange	O
,	O
compare	O
and	O
fix	O
context	O
diffs	B-Application
and	O
unified	O
diffs	B-Application
.	O
</s>
<s>
Postprocessors	O
sdiff	B-Application
and	O
diffmk	B-Application
render	O
side-by-side	O
diff	B-Application
listings	O
and	O
applied	O
change	O
marks	O
to	O
printed	O
documents	O
,	O
respectively	O
.	O
</s>
<s>
Diff3	B-Application
compares	O
one	O
file	O
against	O
two	O
other	O
files	O
by	O
reconciling	O
two	O
diffs	B-Application
.	O
</s>
<s>
It	O
is	O
also	O
used	O
by	O
revision	B-Architecture
control	I-Architecture
systems	I-Architecture
,	O
e.g.	O
</s>
<s>
RCS	B-Architecture
,	O
for	O
merging	B-General_Concept
.	O
</s>
<s>
Emacs	B-Application
has	O
Ediff	O
for	O
showing	O
the	O
changes	O
a	O
patch	B-Application
would	O
provide	O
in	O
a	O
user	O
interface	O
that	O
combines	O
interactive	O
editing	O
and	O
merging	B-General_Concept
capabilities	O
for	O
patch	B-Application
files	I-Application
.	O
</s>
<s>
Vim	B-Application
provides	O
vimdiff	O
to	O
compare	O
from	O
two	O
to	O
eight	O
files	O
,	O
with	O
differences	O
highlighted	O
in	O
color	O
.	O
</s>
<s>
While	O
historically	O
invoking	O
the	O
diff	B-Application
program	O
,	O
modern	O
vim	B-Application
uses	O
git	B-Application
's	O
fork	O
of	O
xdiff	O
library	B-Library
(	O
LibXDiff	O
)	O
code	O
,	O
providing	O
improved	O
speed	O
and	O
functionality	O
.	O
</s>
<s>
GNU	B-Operating_System
Wdiff	O
is	O
a	O
front	O
end	O
to	O
diff	B-Application
that	O
shows	O
the	O
words	O
or	O
phrases	O
that	O
changed	O
in	O
a	O
text	O
document	O
of	O
written	O
language	O
even	O
in	O
the	O
presence	O
of	O
word-wrapping	O
or	O
different	O
column	O
widths	O
.	O
</s>
<s>
colordiff	O
is	O
a	O
Perl	O
wrapper	O
for	O
'	O
diff	B-Application
 '	O
and	O
produces	O
the	O
same	O
output	O
but	O
with	O
pretty	O
'	O
syntax	O
 '	O
highlighting	O
.	O
</s>
<s>
Utilities	O
that	O
compare	O
source	O
files	O
by	O
their	O
syntactic	O
structure	O
have	O
been	O
built	O
mostly	O
as	O
research	O
tools	O
for	O
some	O
programming	O
languages	O
;	O
some	O
are	O
available	O
as	O
commercial	B-Application
tools	O
.	O
</s>
<s>
In	O
addition	O
,	O
free	O
tools	O
that	O
perform	O
syntax-aware	O
diff	B-Application
include	O
:	O
</s>
<s>
C++	O
:	O
zograscope	O
,	O
AST-based	O
.	O
</s>
<s>
JavaScript	B-Language
:	O
astii	O
(	O
AST-based	O
)	O
.	O
</s>
<s>
spiff	O
is	O
a	O
variant	O
of	O
diff	B-Application
that	O
ignores	O
differences	O
in	O
floating	O
point	O
calculations	O
with	O
roundoff	O
errors	O
and	O
whitespace	O
,	O
both	O
of	O
which	O
are	O
generally	O
irrelevant	O
to	O
source	O
code	O
comparison	O
.	O
</s>
<s>
An	O
HPUX	B-Application
port	O
is	O
the	O
most	O
current	O
public	O
release	O
.	O
</s>
<s>
spiff	O
outputs	O
to	O
the	O
standard	O
output	O
in	O
standard	O
diff	B-Application
format	O
and	O
accepts	O
inputs	O
in	O
the	O
C	B-Language
,	O
Bourne	B-Device
shell	I-Device
,	O
Fortran	B-Application
,	O
Modula-2	B-Language
and	O
Lisp	B-Language
programming	I-Language
languages	I-Language
.	O
</s>
<s>
LibXDiff	O
is	O
an	O
LGPL	O
library	B-Library
that	O
provides	O
an	O
interface	O
to	O
many	O
algorithms	O
from	O
1998	O
.	O
</s>
<s>
An	O
improved	O
Myers	O
algorithm	O
with	O
Rabin	B-Algorithm
fingerprint	I-Algorithm
was	O
originally	O
implemented	O
(	O
as	O
of	O
the	O
final	O
release	O
of	O
2008	O
)	O
,	O
but	O
git	B-Application
and	O
libgit2	O
's	O
fork	O
has	O
since	O
expanded	O
the	O
repository	O
with	O
many	O
of	O
its	O
own	O
.	O
</s>
<s>
This	O
is	O
the	O
modern	O
version	O
of	O
LibXDiff	O
used	O
by	O
Vim	B-Application
.	O
</s>
