Text 3-Way Merge
Merge two divergent text versions against a common base with diff3-style conflict markers.
Overview
Merge two divergent versions of a text against a common ancestor and produce a single combined result. Where both sides changed the same region in incompatible ways, the output marks the conflict with diff3-style markers so you can resolve it manually.
Developers handling code merges outside of git, technical writers reconciling parallel edits to a shared document, and anyone working in a branched-document workflow reach for it. Three-way merge is what powers most version-control tooling, and seeing it as a standalone operation is useful for non-developers too.
How it works
The classic three-way merge takes a "base" version (the common ancestor) and two "branches" (your changes and the other side's). The algorithm runs a line-level diff between base and each branch, identifying which regions changed on which side. Where only one side changed a region, that change is kept. Where both sides changed the same region the same way, the change is kept. Where both sides changed the same region in different ways, the result is wrapped in conflict markers (<<<<<<<, =======, >>>>>>>) for you to resolve.
This is the same algorithm git, mercurial, and subversion use for text merges — the diff3 utility was published in the 1980s and remains the standard.
Examples
Base:
hello
world
Mine:
hello
brave world
Theirs:
hello
cruel world
Result (conflict):
hello
<<<<<<< MINE
brave world
=======
cruel world
>>>>>>> THEIRS
FAQ
What happens when there's no conflict?
If the two branches change different regions, both changes are applied and the merge succeeds cleanly. Conflict markers only appear where the same region was edited differently on both sides.
Can I merge changes word-by-word instead of line-by-line?
The diff3 algorithm works on lines. For finer granularity, run the merge on a version of the text where you've split into shorter units (one word per line), then reassemble.
Is this the same as diff?
Diff shows differences between two files; three-way merge combines three files into one. The merge depends on diff internally but answers a different question.