Skip to main content
DevConverter
Home/String/Text Diff

Text Diff

Compare two texts and highlight additions and deletions line by line, word by word, or character by character.

About this tool

A diff (from 'difference') algorithm computes the minimum set of edits — insertions and deletions — needed to transform one text into another. The most widely used algorithm is Myers' diff, introduced in 1986, which operates in O(ND) time where N is the text length and D is the number of edits. Git uses a variation of this algorithm to compute diffs between file versions.

Diffs are typically displayed in one of two formats. Unified format (used by git diff) shows changes in a single pane: lines prefixed with - were removed, lines prefixed with + were added, and unchanged lines shown for context are unprefixed. Side-by-side format shows the two versions in adjacent columns with differences highlighted. Side-by-side is generally easier to read for large changes; unified format is more compact and is the standard for patch files.

Text comparison has several options that affect the results. Ignoring whitespace differences (extra spaces, indentation changes) reduces noise when a formatting-only change was made. Case-insensitive comparison helps when comparing content from different sources with inconsistent capitalization. Comparing at the word or character level rather than the line level provides more granular information for prose text but may produce less useful output for code. The choice of granularity depends on whether the content is primarily code or natural language.