Diff Viewer

Compare two texts side-by-side and see the differences highlighted. Free online diff tool for code and documents.

Embed this tool
0
Added
0
Removed
1
Unchanged
Unified Diff
11

Advertisement

Ad

How Diff Algorithms Work

Diff algorithms are the backbone of version control systems like Git. They analyze two sequences of text and find the smallest set of changes needed to transform one into the other. The most common approach is the Longest Common Subsequence (LCS) algorithm, which identifies the longest sequence of lines that appear in both documents unchanged.

Once the LCS is found, everything outside of it is classified as either an addition or a deletion. Modern tools often use Myers' diff algorithm, which is optimized for speed and produces human-readable output by favoring contiguous blocks of changes.

Why Unified Diff?

Unified diff format shows both the original and modified line numbers in a single column, making it the standard for code reviews and patch files. Each changed line is prefixed with a + or - sign, while unchanged context lines are prefixed with a space. This compact representation is easy to read and compatible with tools like git diff and patch.

Frequently Asked Questions

A diff viewer is a tool that compares two versions of text or code and highlights the differences. It shows which lines were added, removed, or stayed the same, making it easy to review changes.

Related Tools