About the Code Diff
Code Diff is a quick way to compare two versions of a function, config block, or script without committing anything to a repository. Paste the old and new code, and the tool lists every line that was kept, removed, or added.
How it works
Code Diff uses the same engine as the site's Text Diff tool. Both texts are split into lines and aligned with a longest-common-subsequence algorithm, the same idea behind git diff. It finds the largest set of lines the two versions share in order, so an inserted or deleted line shows up as a single change and the lines after it still match.
Within a block of changes, each removed line is paired with an added line and compared word by word, and the exact words that changed are highlighted. Options let you ignore whitespace or letter case, show only the changed lines with two lines of context, and switch between side-by-side and unified views.
How to use
- 1
Paste or open the earlier version in Original, and the newer one in Modified.
- 2
Read the result: removed lines in red, added lines in green, with changed words highlighted.
- 3
Switch between Side by side and Unified, or tick Ignore whitespace, Ignore case or Only changes.
- 4
Click Copy diff to copy the result with - and + markers.
Worked examples
A changed return value
Reviewing a one-line fix in a small JavaScript function.
Only the middle line differs, so it is the only one flagged.
Indentation-only change
A formatter changed two-space indentation to four spaces.
Whitespace is compared exactly, so a pure re-indent is reported as a change.
Frequently asked questions
Does this work for any programming language?+
Yes. Code is treated as plain text, so JavaScript, Python, PHP, SQL, YAML, or anything else compares the same way. There is no language-specific highlighting.
How is this different from Text Diff?+
It uses the same engine as Text Diff. The page is aimed at code, but the results are identical to comparing the same content in Text Diff.
Will indentation changes show up?+
By default yes, since spaces and tabs are part of each line. Tick Ignore whitespace to treat re-indented lines as unchanged.
Will lines I didn't touch show as changed?+
It shouldn't any more. Lines are aligned by content, not by position, so an inserted or deleted line shows as one change and the following lines still match.
Is my code sent to a server?+
No. The comparison runs in your browser, so the code you paste stays on your device.