fileformer
search⌘KtranslateENexpand_moreupload_fileConvert
Converters8 file families · 44 direct conversions
What changes in a conversionarrow_forward
home/developer-tools/diff-checker

Paste two versions. See exactly what changed.

Compare contracts, config files, code or any text. Changed lines are matched up and the exact words inside them are highlighted. Everything is compared in your browser; it all stays on your device.

gavelContract clausesettingsConfig filecodeCode
space_barIgnore whitespacetext_fieldsIgnore casehighlightHighlight wordsswap_horizSwap
3 changed1 added0 removed5 unchanged
Side by sideUnified
check_circle
1The Tenant shall pay rent of £1,150 per month,1The Tenant shall pay rent of £1,195 per month,
2in advance, on the 1st day of each month.2in advance, on the 1st day of each month.
33
4The deposit of £1,300 will be held in a4The deposit of £1,300 will be held in a
5government-approved scheme.5government-approved scheme.
66
7Eitherparty may end this agreement by giving7TheLandlord may end this agreement by giving
8twomonths written notice.8onemonth written notice.
9Pets are not permitted without written consent.
~/how-fine-a-comb

The same edit looks different at line, word and letter level.

Line diffs are what code review tools show: fast, but a one-letter typo marks the whole line. Word diffs suit prose. Letter diffs catch a changed digit in a price, but turn a rewritten sentence into confetti. We use lines, then words inside changed lines.

LineWordLetter
before
Delivery within 5 working days for £4.99.
after
Delivery within 3 working days for £4.95.
highlighted chars14highlight blocks4real edits2
Exactly the two changed words are marked: the delivery time and the price.
~/looks-identical

"Nothing changed", yet the diff says otherwise.

Some differences can't be seen on screen. Each pair below looks the same but isn't. Reveal shows the hidden characters, and the fix is usually one of the options in the toolbar above.

Tab vs spaces
return sum; return sum;
visibilityReveal charactersIndented with four spaces in one file and a tab in the other.Fix: Ignore whitespace
Trailing space
port: 8080port: 8080
visibilityReveal charactersAn invisible space at the end of the line.Fix: Ignore whitespace
Line endings
level: infolevel: info
visibilityReveal charactersWindows ends lines with two characters, Mac and Linux with one.We normalise these automatically
Look-alike letters
PaypalPаypal
visibilityReveal charactersThe second “a” is a Cyrillic letter; a classic phishing trick.Word-level highlighting exposes it
~/what-people-compare

Six comparisons, and the settings that suit each.

Each sets the options in the toolbar above. The three with samples also load an example.

gavelContract versionswords on · strictSpot a changed figure or a quietly added clause before you sign.
settingsConfig filesignore whitespace · unifiedIndentation noise hidden, so only real setting changes show.
codeCode snippetswords on · side by sideSee changed arguments and expressions inside a line.
edit_noteEssay draftsignore case · words onFocus on wording, not capitalisation fixes.
datasetCSV exportsstrict · unifiedFind the rows that changed between two exports.
translateTranslationsside by sideCheck a translated file kept every line of the original.
~/shortest-path

A diff is the shortest path across a grid.

Put the old text down the side and the new text along the top. Moving right inserts a character, moving down deletes one, and a diagonal step is free wherever the two characters match. Eugene Myers' 1986 algorithm, still the default in GNU diff and git, finds a path with the fewest non-diagonal steps. It explores outwards one edit at a time, keeping only the furthest point reached on each diagonal. Edit the two strings; the path below is computed live.

Myers paperkittendiffreversed
CBABAC●·╲·╲··A●╲·╲···B●····╲·C·●●·╲··A·╲·●···B·╲·╲●··B··╲·●··A·····●●
on the shortest patha free diagonal starts hereold text ↓ · new text →
edit distance D5deleted · inserted3 · 2longest common subsequence4
ABCBABBAC
d \ k-5-4-3-2-1012345
00
101
2223
33455
434577
534575
Each row is one more edit. A cell is the furthest x reached on diagonal k = x − y. Myers needs only this one row of numbers per step, and stops at the first row whose path reaches the bottom-right corner: D = 5.
~/shortest-is-not-clearest

The shortest diff isn't always the one a person would write.

Myers matches as many lines as possible, including lone braces and blank lines that happen to line up, so code edits can come out interleaved. Patience diff, by Bram Cohen, first anchors on lines that appear exactly once in both files, usually function signatures. It then diffs the gaps between them. Both run here, line by line, on the same files.

Reordered functions (JS)Frobnitz (C)Your texts above
differenceThey disagree. Myers keeps 7 lines and changes 19, spread over 7 blocks. Patience keeps 6, changes 21, in 2 blocks. Patience’s diff is longer, but each block is a whole unit, the way a person would describe the edit.
Myersminimal edit script · 7 blocks · −6 +13
−function add(a, b) {
+function mul(a, b) {
if (a == null) {
− return b;
+ return 0;
}
− return a + b;
+ return a * b;
}
−function mul(a, b) {
+function sub(a, b) {
if (a == null) {
− return 0;
+ return -b;
}
− return a * b;
+ return a - b;
}
+
+function add(a, b) {
+ if (a == null) {
+ return b;
+ }
+ return a + b;
+}
Patienceanchored on unique lines · 2 blocks · −7 +14
−function add(a, b) {
− if (a == null) {
− return b;
− }
− return a + b;
−}
−
function mul(a, b) {
if (a == null) {
return 0;
}
return a * b;
+}
+
+function sub(a, b) {
+ if (a == null) {
+ return -b;
+ }
+ return a - b;
+}
+
+function add(a, b) {
+ if (a == null) {
+ return b;
+ }
+ return a + b;
}
~/patch-files

Your two texts, as a patch that rebuilds one from the other.

The unified format behind git diff, GitHub and code review records each change as a hunk: a header saying where it starts and how long it is, the changed lines, and a few unchanged lines of context so the patch can still be placed if the file moves a little. This is a real patch of the two texts at the top of the page. It's applied back to the original right here to prove it rebuilds the new version exactly.

CONTEXT LINES3 (the default)
MyersPatience
downloadchanges.patch
hunks1lines added+4lines removed−3patch size467 B
--- a/original.txt
+++ b/changed.txt
@@ -1,8 +1,9 @@
-The Tenant shall pay rent of £1,150 per month,
+The Tenant shall pay rent of £1,195 per month,
in advance, on the 1st day of each month.
The deposit of £1,300 will be held in a
government-approved scheme.
-Either party may end this agreement by giving
-two months written notice.
+The Landlord may end this agreement by giving
+one month written notice.
+Pets are not permitted without written consent.
READING THE FIRST HUNK HEADER@@ -1,8 +1,9 @@In the old file this hunk starts at line 1 and covers 8 lines; in the new file it starts at line 1 and covers 9. A count of 1 is left out, and a count of 0 means the hunk only inserts or deletes there.
verifiedApplied and verifiedApplying the patch to the original rebuilt the changed text exactly, line for line: 9 lines.
~/reference

Diff algorithms, output formats and the switches that change them.

N and M are the line counts of the two files, and D is the number of lines that differ. That's why diffing two nearly identical large files is fast.

algorithmyearbycostused inidea
Hunt: McIlroy1976J. W. Hunt, M. D. McIlroyO((r + N) log N)original Unix diffBuilds candidate matches from equivalence classes of identical lines; r is the number of matching pairs.
Heckel1978Paul HeckelO(N + M)early move detectionAnchors on lines that occur once in each file, then grows matches outwards. Patience echoes it.
Myers1986Eugene W. MyersO((N + M) · D)GNU diff, git defaultGreedy breadth-first search for the shortest edit script, as in the edit graph above.
Myers, linear space1986Eugene W. MyersO((N + M) · D) time, O(N + M) memoryGNU diff, git --minimalDivide and conquer around a “middle snake”, so huge files don’t need a huge trace.
Patience2006Bram CohenO(N log N) plus fallbackBazaar, git --patienceLongest increasing run of unique common lines, found with patience sorting.
Histogram2011Shawn Pearce, JGitusually faster than patienceJGit, git --histogramExtends patience to lines that are rare but not unique, choosing the lowest-count line as an anchor.

Five output formats for the same change

Normaldiff
2c2< rent £1,150---> rent £1,195
The original 1974 format: ed-style commands with old and new lines.
Contextdiff -c
*** 1,3 **** The Tenant! rent £1,150--- 1,3 ----! rent £1,195
From BSD in 1981: both versions in full, with ! marking changed lines.
Unifieddiff -u
@@ -1,3 +1,3 @@ The Tenant-rent £1,150+rent £1,195
Interleaves old and new in one block. Used by git, patch and code review.
gitgit diff
diff --git a/x b/xindex 3f1a..9b2c 100644@@ -1,3 +1,3 @@
Unified, plus headers for file mode, renames, copies and binary changes.
ed scriptdiff -e
2crent £1,195.
Commands an ed editor can run to turn the old file into the new one.

git diff switches worth knowing

--minimalSpends extra time to guarantee the smallest possible diff.
--patienceUses patience diff: clearer results for reordered code.
--histogramPatience extended to low-frequency lines; often the best default for code.
--word-diffShows changes inside lines as [-old-]{+new+}.
-wIgnores all whitespace when comparing lines.
--ignore-blank-linesSkips hunks that only add or remove blank lines.
--color-movedColours blocks that were moved rather than changed.
-MDetects renamed files by content similarity, 50% by default.

From Unix diff to moved-code detection

1974diff in UnixDoug McIlroy’s diff ships with the 5th Edition of Research Unix.
1976Hunt: McIlroyBell Labs technical report 41 describes the algorithm behind it.
1985patchLarry Wall releases patch, which applies a diff to a file and copes with small offsets.
1986Myers“An O(ND) Difference Algorithm and Its Variations” appears in Algorithmica.
1990Unified formatWayne Davison’s compact unified diff is added to GNU diff.
2006Patience diffBram Cohen describes it on his blog; Bazaar adopts it.
2011Histogram diffAdded to JGit, then to git 1.7.7.
2017Moved codegit 2.15 adds --color-moved for blocks that changed place.