Boneyard Tools

Line, word and character diffs, and when to use each

How line, word and character comparison differ, why an edit can show as a remove plus an add, and which mode fits prose versus code.

Three levels of granularity

A diff can compare text at different resolutions. Line mode looks only at whole lines and is the fastest, ideal for code and structured files where each line is a meaningful unit. Word mode breaks the text into words and highlights the exact ones that changed, which suits edited prose. Character mode goes finer still, marking individual characters, and is handy for catching a single typo or a changed digit. This tool lets you switch between all three so you can zoom in as far as the change demands.

Why a small edit can look like two changes

Line based diffs match whole lines exactly. When you change even one word in a line, that line no longer matches its original, so the algorithm records the old line as removed and the new line as added. In the unified view this appears as a minus line followed by a plus line. Side by side line mode softens this by aligning the pair as a single modified row and highlighting only the part that differs, and word or character mode narrows the highlight further to the exact tokens involved.

How the longest common subsequence keeps context

The engine finds the longest common subsequence, the longest ordered set of matching pieces shared by both texts. Everything on that path is treated as unchanged, which anchors the diff to the parts you did not touch and prevents small edits from cascading into a wall of differences. Because it respects order, a paragraph you moved elsewhere shows as a deletion in its old spot and an insertion in its new one rather than a confusing tangle, keeping the surrounding unchanged lines stable and readable.

Ignoring noise to focus on real changes

Not every difference is meaningful. Reindented code, trailing spaces or a change from lower to upper case can bury the edits you care about. Ignore whitespace collapses spacing differences so only substantive line changes remain, and Ignore case does the same for letter case. Combined with Collapse unchanged, which hides long stretches of matching lines and shows just a count, these options turn a noisy comparison into a short list of the edits that actually matter.

Frequently asked questions

Which mode should I use for comparing code?

Line mode is usually best for code because each line is a logical unit, and the side by side or unified views map cleanly to a patch. Switch to word or character mode only when you need to see exactly which token on a line changed.

What is a unified diff and why export one?

A unified diff is the standard text patch format that marks removed lines with a minus and added lines with a plus. Copy .diff or Download .diff produces one, which you can paste into a review, attach to a ticket, or apply with patch tools.

Does ignoring whitespace change the exported diff?

Yes. The exported unified diff reflects the current options, so with Ignore whitespace on, lines that differ only in spacing are treated as unchanged and will not appear as edits in the output.