Text Diff
Compare two texts side-by-side or inline with added and removed line highlighting.
What this tool does
Text diffing is the process of comparing two versions of text and highlighting the additions, deletions, and modifications. This tool supports both side-by-side and inline (unified) views, making it easy to spot changes between file versions, draft revisions, or configuration updates. The algorithm used is the Longest Common Subsequence (LCS), which produces minimal-edit diffs in O(N×M) time.
The side-by-side view shows both versions in parallel with color-coded changes, while the inline view prefixes each line with +, -, or = to indicate added, removed, or unchanged content. For large files, the tool efficiently computes diffs using dynamic programming, though files above a few thousand lines may experience noticeable delays.
Usage Example
--- Before
+++ After
@@ -1,5 +1,5 @@
function greet(name) {
- return "Hello, " + name;
+ return `Hello, ${name}!`;
}
greet("World");
-// Output: Hello, World
+// Output: Hello, World!Common Edge Cases
- Line endings (LF vs CRLF) are treated as different characters, so a file edited on Windows and then on Unix may show every line as changed. Normalize line endings before diffing.
- Trailing whitespace differences are highlighted even when semantically irrelevant. Use a trim option if you want to ignore these.
- Binary files cannot be meaningfully diffed as text. Most diff tools refuse to show changes for files containing null bytes.
- Very long files with many small changes produce unreadable diffs. Consider using patience diff or histogram diff algorithms for better grouping.
- Word-level and character-level diffs are useful for prose, but line-level diffs are standard for code. Match the granularity to the use case.
FAQ
- What is the difference between side-by-side and inline diff?
- Side-by-side shows both versions in parallel columns, making it easy to compare corresponding lines. Inline shows changes sequentially with + and - prefixes, which is more compact and works well in terminal output.
- Can I diff more than two files at once?
- Not directly. Multi-file diffs require 3-way merge tools like kdiff3 or Beyond Compare. For three or more files, compute diffs pairwise and combine the results manually.
- Is the diff output suitable for code review?
- Yes, but most teams prefer to review code changes in version control tools (git diff, GitHub PR view) which add context like the commit message, author, and file history.