Compare two text files and highlight the differences.
Diff is the process of comparing two pieces of text to find and display their differences. Originally a Unix utility, diff algorithms are now fundamental to version control systems, code review tools, and document comparison software. Different diff algorithms optimize for various use cases like minimal changes or semantic understanding.
Diff algorithms typically use techniques like Longest Common Subsequence (LCS) to find the minimal set of changes between two texts. Results show additions (new lines), deletions (removed lines), and modifications (changed lines). Advanced diffs can show character-level changes within modified lines.
Unified diff shows changes in a single column with +/- markers, more compact for patches. Side-by-side diff shows both versions in parallel columns, easier for visual comparison.
Most diff tools offer options to ignore whitespace changes. This is useful when comparing code with different formatting but identical logic.