<s>
In	O
version	B-Architecture
control	I-Architecture
,	O
merging	O
(	O
also	O
called	O
integration	O
)	O
is	O
a	O
fundamental	O
operation	O
that	O
reconciles	O
multiple	O
changes	O
made	O
to	O
a	O
version-controlled	O
collection	O
of	O
files	O
.	O
</s>
<s>
Most	O
often	O
,	O
it	O
is	O
necessary	O
when	O
a	O
file	O
is	O
modified	O
on	O
two	O
independent	O
branches	B-General_Concept
and	O
subsequently	O
merged	O
.	O
</s>
<s>
In	O
some	O
cases	O
,	O
the	O
merge	B-General_Concept
can	O
be	O
performed	O
automatically	O
,	O
because	O
there	O
is	O
sufficient	O
history	O
information	O
to	O
reconstruct	O
the	O
changes	O
,	O
and	O
the	O
changes	O
do	O
not	O
conflict	B-Operating_System
.	O
</s>
<s>
Many	O
revision	B-Architecture
control	I-Architecture
software	I-Architecture
tools	O
include	O
merge	B-General_Concept
capabilities	O
.	O
</s>
<s>
There	O
are	O
two	O
types	O
of	O
merges	B-General_Concept
:	O
automatic	O
and	O
manual	O
.	O
</s>
<s>
This	O
is	O
what	O
Unix	O
tools	O
(	O
diff/patch	O
)	O
and	O
CVS	B-Application
tools	O
(	O
SVN	O
,	O
Git	B-Application
)	O
use	O
.	O
</s>
<s>
fully	O
resolved	O
AST	B-Data_Structure
.	O
</s>
<s>
This	O
allows	O
for	O
a	O
fine-grained	O
merge	B-General_Concept
that	O
avoid	O
spurious	O
conflicts	O
.	O
</s>
<s>
Automatic	O
merging	O
is	O
what	O
version	B-Architecture
control	I-Architecture
software	I-Architecture
does	O
when	O
it	O
reconciles	O
changes	O
that	O
have	O
happened	O
simultaneously	O
(	O
in	O
a	O
logical	O
sense	O
)	O
.	O
</s>
<s>
Manual	O
merging	O
is	O
also	O
required	O
when	O
automatic	O
merging	O
runs	O
into	O
a	O
change	O
conflict	B-Operating_System
;	O
for	O
instance	O
,	O
very	O
few	O
automatic	O
merge	B-General_Concept
tools	O
can	O
merge	B-General_Concept
two	O
changes	O
to	O
the	O
same	O
line	O
of	O
code	O
(	O
say	O
,	O
one	O
that	O
changes	O
a	O
function	O
name	O
,	O
and	O
another	O
that	O
adds	O
a	O
comment	O
)	O
.	O
</s>
<s>
In	O
these	O
cases	O
,	O
revision	B-Architecture
control	I-Architecture
systems	I-Architecture
resort	O
to	O
the	O
user	O
to	O
specify	O
the	O
intended	O
merge	B-General_Concept
result	O
.	O
</s>
<s>
The	O
more	O
notable	O
merge	B-General_Concept
algorithms	O
include	O
three-way	O
merge	B-General_Concept
,	O
recursive	O
three-way	O
merge	B-General_Concept
,	O
fuzzy	O
patch	B-Application
application	O
,	O
weave	O
merge	B-General_Concept
,	O
and	O
patch	B-Application
commutation	O
.	O
</s>
<s>
A	O
three-way	O
merge	B-General_Concept
is	O
performed	O
after	O
an	O
automated	O
difference	O
analysis	O
between	O
a	O
file	O
"	O
A	O
"	O
and	O
a	O
file	O
"	O
B	O
"	O
while	O
also	O
considering	O
the	O
origin	O
,	O
or	O
common	O
ancestor	O
,	O
of	O
both	O
files	O
"	O
C	O
"	O
.	O
</s>
<s>
Three	O
way	O
merge	B-General_Concept
can	O
be	O
done	O
on	O
raw	O
text	O
(	O
sequence	O
of	O
lines	O
)	O
or	O
on	O
structured	O
trees	O
.	O
</s>
<s>
The	O
three-way	O
merge	B-General_Concept
looks	O
for	O
sections	O
which	O
are	O
the	O
same	O
in	O
only	O
two	O
of	O
the	O
three	O
files	O
.	O
</s>
<s>
Sections	O
that	O
are	O
different	O
in	O
all	O
three	O
files	O
are	O
marked	O
as	O
a	O
conflict	B-Operating_System
situation	O
and	O
left	O
for	O
the	O
user	O
to	O
resolve	O
.	O
</s>
<s>
Three-way	O
merging	O
is	O
implemented	O
by	O
the	O
ubiquitous	O
diff3	B-Application
program	O
,	O
and	O
was	O
the	O
central	O
innovation	O
that	O
allowed	O
the	O
switch	O
from	O
file-locking	O
based	O
revision	B-Architecture
control	I-Architecture
systems	I-Architecture
to	O
merge-based	O
revision	B-Architecture
control	I-Architecture
systems	I-Architecture
.	O
</s>
<s>
It	O
is	O
extensively	O
used	O
by	O
the	O
Concurrent	B-Application
Versions	I-Application
System	I-Application
(	O
CVS	B-Application
)	O
.	O
</s>
<s>
Three-way	O
merge	B-General_Concept
based	O
revision	B-Architecture
control	I-Architecture
tools	O
are	O
widespread	O
,	O
but	O
the	O
technique	O
fundamentally	O
depends	O
on	O
finding	O
a	O
common	O
ancestor	O
of	O
the	O
versions	O
to	O
be	O
merged	O
.	O
</s>
<s>
There	O
are	O
awkward	O
cases	O
,	O
particularly	O
the	O
"	O
criss-cross	O
merge	B-General_Concept
"	O
,	O
where	O
a	O
unique	O
last	O
common	O
ancestor	O
of	O
the	O
modified	O
versions	O
does	O
not	O
exist	O
.	O
</s>
<s>
Fortunately	O
,	O
in	O
this	O
case	O
it	O
can	O
be	O
shown	O
that	O
there	O
are	O
at	O
most	O
two	O
possible	O
candidate	O
ancestors	O
,	O
and	O
recursive	O
three-way	O
merge	B-General_Concept
constructs	O
a	O
virtual	O
ancestor	O
by	O
merging	O
the	O
non-unique	O
ancestors	O
first	O
.	O
</s>
<s>
This	O
merge	B-General_Concept
can	O
itself	O
suffer	O
the	O
same	O
problem	O
,	O
so	O
the	O
algorithm	O
recursively	O
merges	B-General_Concept
them	O
.	O
</s>
<s>
This	O
technique	O
is	O
used	O
by	O
the	O
Git	B-Application
revision	B-Architecture
control	I-Architecture
tool	O
.	O
</s>
<s>
(	O
Git	B-Application
's	O
recursive	O
merge	B-General_Concept
implementation	O
also	O
handles	O
other	O
awkward	O
cases	O
,	O
like	O
a	O
file	O
being	O
modified	O
in	O
one	O
version	O
and	O
renamed	O
in	O
the	O
other	O
,	O
but	O
those	O
are	O
extensions	O
to	O
its	O
three-way	O
merge	B-General_Concept
implementation	O
;	O
not	O
part	O
of	O
the	O
technique	O
for	O
finding	O
three	O
versions	O
to	O
merge	B-General_Concept
.	O
)	O
</s>
<s>
Recursive	O
three-way	O
merge	B-General_Concept
can	O
only	O
be	O
used	O
in	O
situations	O
where	O
the	O
tool	O
has	O
knowledge	O
about	O
the	O
total	O
ancestry	O
directed	O
acyclic	O
graph	O
(	O
DAG	O
)	O
of	O
the	O
derivatives	O
to	O
be	O
merged	O
.	O
</s>
<s>
Consequently	O
,	O
it	O
cannot	O
be	O
used	O
in	O
situations	O
where	O
derivatives	O
or	O
merges	B-General_Concept
do	O
not	O
fully	O
specify	O
their	O
parent(s )	O
.	O
</s>
<s>
A	O
patch	B-Application
is	O
a	O
file	O
that	O
contains	O
a	O
description	O
of	O
changes	O
to	O
a	O
file	O
.	O
</s>
<s>
In	O
the	O
Unix	O
world	O
,	O
there	O
has	O
been	O
a	O
tradition	O
to	O
disseminate	O
changes	O
to	O
text	O
files	O
as	O
patches	B-Application
in	O
the	O
format	O
that	O
is	O
produced	O
by	O
"	O
diff	B-Application
-u	O
"	O
.	O
</s>
<s>
This	O
format	O
can	O
then	O
be	O
used	O
by	O
the	B-Application
patch	I-Application
program	I-Application
to	O
re-apply	O
(	O
or	O
remove	O
)	O
the	O
changes	O
into	O
(	O
or	O
from	O
)	O
a	O
text	O
file	O
,	O
or	O
a	O
directory	O
structure	O
containing	O
text	O
files	O
.	O
</s>
<s>
However	O
,	O
the	B-Application
patch	I-Application
program	I-Application
also	O
has	O
some	O
facilities	O
to	O
apply	O
the	O
patch	B-Application
into	O
a	O
file	O
that	O
is	O
not	O
exactly	O
similar	O
as	O
the	O
origin	O
file	O
that	O
was	O
used	O
to	O
produce	O
the	O
patch	B-Application
.	O
</s>
<s>
This	O
process	O
is	O
called	O
fuzzy	O
patch	B-Application
application	O
,	O
and	O
results	O
in	O
a	O
kind	O
of	O
asymmetric	O
three-way	O
merge	B-General_Concept
,	O
where	O
the	O
changes	O
in	O
the	O
patch	B-Application
are	O
discarded	O
if	O
the	B-Application
patch	I-Application
program	I-Application
cannot	O
find	O
a	O
place	O
in	O
which	O
to	O
apply	O
them	O
.	O
</s>
<s>
Like	O
CVS	B-Application
started	O
as	O
a	O
set	O
of	O
scripts	O
on	O
diff3	B-Application
,	O
GNU	B-Protocol
arch	I-Protocol
started	O
as	O
a	O
set	O
of	O
scripts	O
on	O
patch	B-Application
.	O
</s>
<s>
However	O
,	O
fuzzy	O
patch	B-Application
application	O
is	O
a	O
relatively	O
untrustworthy	O
method	O
,	O
sometimes	O
misapplying	O
patches	B-Application
that	O
have	O
too	O
little	O
context	O
(	O
especially	O
ones	O
that	O
create	O
a	O
new	O
file	O
)	O
,	O
sometimes	O
refusing	O
to	O
apply	O
deletions	O
that	O
both	O
derivatives	O
have	O
done	O
.	O
</s>
<s>
Patch	B-Application
commutation	O
is	O
used	O
in	O
Darcs	B-Protocol
to	O
merge	B-General_Concept
changes	O
,	O
and	O
is	O
also	O
implemented	O
in	O
git	B-Application
(	O
but	O
called	O
"	O
rebasing	O
"	O
)	O
.	O
</s>
<s>
Patch	B-Application
commutation	O
merge	B-General_Concept
means	O
changing	O
the	O
order	O
of	O
patches	B-Application
(	O
i.e.	O
</s>
<s>
In	O
effect	O
,	O
when	O
two	O
patches	B-Application
are	O
made	O
in	O
the	O
context	O
of	O
a	O
common	O
situation	O
,	O
upon	O
merging	O
,	O
one	O
of	O
them	O
is	O
rewritten	O
so	O
that	O
it	O
appears	O
to	O
be	O
done	O
in	O
the	O
context	O
of	O
the	O
other	O
.	O
</s>
<s>
Patch	B-Application
commutation	O
requires	O
that	O
the	O
exact	O
changes	O
that	O
made	O
derivative	O
files	O
are	O
stored	O
or	O
can	O
be	O
reconstructed	O
.	O
</s>
<s>
For	O
instance	O
,	O
if	O
patch	B-Application
A	O
adds	O
line	O
"	O
X	O
"	O
after	O
line	O
7	O
of	O
file	O
F	O
and	O
patch	B-Application
B	O
adds	O
line	O
"	O
Y	O
"	O
after	O
line	O
310	O
of	O
file	O
F	O
,	O
B	O
has	O
to	O
be	O
rewritten	O
if	O
it	O
is	O
rebased	O
on	O
A	O
:	O
the	O
line	O
must	O
be	O
added	O
on	O
line	O
311	O
of	O
file	O
F	O
,	O
because	O
the	O
line	O
added	O
in	O
A	O
offsets	O
the	O
line	O
numbers	O
by	O
one	O
.	O
</s>
<s>
Patch	B-Application
commutation	O
has	O
been	O
studied	O
a	O
great	O
deal	O
formally	O
,	O
but	O
the	O
algorithms	O
for	O
dealing	O
with	O
merge	B-General_Concept
conflicts	O
in	O
patch	B-Application
commutation	O
still	O
remain	O
open	O
research	O
questions	O
.	O
</s>
<s>
However	O
,	O
patch	B-Application
commutation	O
can	O
be	O
proven	O
to	O
produce	O
"	O
correct	O
"	O
merge	B-General_Concept
results	O
where	O
other	O
merge	B-General_Concept
strategies	O
are	O
mostly	O
heuristics	O
that	O
try	O
to	O
produce	O
what	O
users	O
want	O
to	O
see	O
.	O
</s>
<s>
The	O
Unix	O
program	O
flipdiff	O
from	O
the	O
"	O
patchutils	O
"	O
package	O
implements	O
patch	B-Application
commutation	O
for	O
traditional	O
patches	B-Application
produced	O
by	O
diff	B-Application
-u	O
.	O
</s>
<s>
Weave	O
merge	B-General_Concept
is	O
an	O
algorithm	O
that	O
does	O
not	O
make	O
use	O
of	O
a	O
common	O
ancestor	O
for	O
two	O
files	O
.	O
</s>
<s>
For	O
each	O
line	O
in	O
the	O
derivative	O
files	O
,	O
weave	O
merge	B-General_Concept
collects	O
the	O
following	O
information	O
:	O
which	O
lines	O
precede	O
it	O
,	O
which	O
follow	O
it	O
,	O
and	O
whether	O
it	O
was	O
deleted	O
at	O
some	O
stage	O
of	O
either	O
derivative	O
's	O
history	O
.	O
</s>
<s>
If	O
these	O
constraints	O
do	O
not	O
give	O
a	O
total	O
ordering	O
for	O
all	O
lines	O
,	O
then	O
the	O
lines	O
that	O
do	O
not	O
have	O
an	O
ordering	O
with	O
respect	O
to	O
each	O
other	O
are	O
additions	O
that	O
conflict	B-Operating_System
.	O
</s>
<s>
Weave	O
merge	B-General_Concept
was	O
apparently	O
used	O
by	O
the	O
commercial	O
revision	B-Architecture
control	I-Architecture
tool	O
BitKeeper	B-Protocol
and	O
can	O
handle	O
some	O
of	O
the	O
problem	O
cases	O
where	O
a	O
three-way	O
merge	B-General_Concept
produces	O
wrong	O
or	O
bad	O
results	O
.	O
</s>
<s>
It	O
is	O
also	O
one	O
of	O
the	O
merge	B-General_Concept
options	O
of	O
the	O
GNU	B-Protocol
Bazaar	I-Protocol
revision	B-Architecture
control	I-Architecture
tool	O
,	O
and	O
is	O
used	O
in	O
Codeville	O
.	O
</s>
