How diff algorithms compare text
Our diff checker implements the Myers diff algorithm (used by Git) with a patience-mode fallback for structured text. The Myers algorithm finds the shortest edit script between two sequences in O(ND) time, where N is total text length and D is the number of differences. For most file comparisons, this completes in milliseconds. For large files (10,000+ lines), patience mode reduces spurious matches on repeated lines like import statements or closing braces.
The tool also highlights intra-line changes (word-level or character-level diff) so you can spot spelling fixes or variable renames within a modified line. This is powered by a secondary diff pass on each changed line segment, splitting on whitespace and punctuation boundaries.
Real-world diffing workflows
Before refactoring, diff the original and refactored versions to confirm the only changes are structural (renames, extracted functions) — the behavioral output should be identical. This is especially useful when modernizing legacy jQuery code to vanilla JS or React hooks.
When reviewing pull requests, paste the raw diff into this tool and toggle unified/split view to catch non-obvious changes like whitespace-only modifications or accidental semicolon insertion that could introduce ASI bugs. The character-level diff helps spot differences in long hex strings or UUIDs that are easy to miss.
How to use the Diff Checker
Step 1: Paste the original text into the left panel (or "before" field). This can be a file, code snippet, configuration, or any text content you want to compare.
Step 2: Paste the modified text into the right panel (or "after" field). This is the version you want to compare against the original.
Step 3: The tool automatically highlights differences — removed lines in red, added lines in green, and modified content with inline character-level highlighting.
Step 4: Switch between unified and split view depending on your preference. Unified view interleaves both versions with +/- markers; split view shows them side by side.
Step 5: Use the whitespace toggle if differences seem unexpected. Trailing spaces, tabs, and line endings (CRLF vs LF) often cause false-positive differences that are not meaningful.
Step 6: Copy the diff output for sharing with teammates, including in pull request descriptions, code review comments, or documentation.
Common mistakes and how to fix them
Error: Comparing files with different line endings. Windows uses CRLF while Unix uses LF. These appear as differences even though the content is identical. Convert both texts to the same line ending format before comparing.
Error: False positives from trailing whitespace. Extra spaces at the end of lines show as changes but are invisible. Enable the "Show whitespace" option to identify these, or strip trailing whitespace before diffing.
Error: Comparing minified code without formatting. Minified files show as one long changed line, making it hard to spot meaningful differences. Format both versions first using the Code Minifier or SQL Formatter before comparing.
Error: Missing context for large diffs. When comparing very large files, the diff output can be overwhelming. Focus on specific sections by trimming both texts to the relevant portion before comparing.
Error: Encoding differences causing false differences. Files saved with UTF-8 BOM vs without BOM, or different character encodings, may show as different even when content is the same. Ensure both texts use the same encoding.
Tips and best practices
Use unified diff format when sharing changes with teammates. It includes 3 lines of context around each change, which helps reviewers understand the surrounding code without needing to see the full file.
For configuration files like YAML or JSON, sort keys in both versions before diffing. This avoids false positives caused by key reordering that does not change the actual configuration values.
Combine the diff checker with the Code Minifier for comparing minified assets. Format both versions first, diff to identify changes, then re-minify after making adjustments.
When reviewing code changes, focus on the character-level diff within modified lines to catch subtle changes like variable renames, off-by-one errors, or accidental semicolon insertion.
Use the diff output to generate commit messages. A clear diff shows exactly what changed, making it easy to write descriptive commit messages that document the purpose of each modification.