Diff checker

Paste the original on the left and the changed version on the right. Added and removed lines are shown as you type, with the words that changed marked inside them, and you can copy the result as a unified diff.

Paste or type. Nothing is uploaded: the comparison runs in this page.
Compare
View

Paste a text into both boxes to compare them.

Checking a config before and after a change, or two plans' terms? When you are choosing where to run it: From €3.02 a month today, among 2,226 servers.

Works in your browser: nothing you type is sent anywhere.

How the diff checker works

Both texts are split into lines, and the page finds the longest run of lines the two have in common, in order (the longest common subsequence). Everything else is a change: lines only in the original are removed, lines only in the changed text are added. It uses Eugene Myers' algorithm, the same one behind GNU diff and git diff, so it finds the smallest set of changes.

When a block of removed lines sits right next to a block of added ones, they are paired up in order and compared again word by word. The words that differ are marked, so a changed port number or path stands out in a long line. If two paired lines have little in common, the whole line is shown as changed instead.

Ignore spaces treats runs of spaces and tabs as one space and skips them at the ends of lines, which helps after re-indenting. Ignore case compares letters without upper and lower case. Line endings (Windows CRLF or Unix LF) never count as a difference. Long unchanged stretches are folded, with three lines of context kept around each change.

Example

The sample is an nginx site moved from plain HTTP to HTTPS. The original has 11 lines and the changed version 12. The diff finds 7 unchanged lines, 4 removed and 5 added. In the listen line only “80” became “443 ssl”, and in the root line only “html” became “example”, so those words are marked. As a unified diff it reads:

changes.diff
--- original.conf
+++ changed.conf
@@ -1,11 +1,12 @@
 server {
-    listen 80;
+    listen 443 ssl;
+    http2 on;
     server_name example.com www.example.com;
-    root /var/www/html;
+    root /var/www/example;
 
+    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
+
     location / {
         try_files $uri $uri/ =404;
     }
-
-    access_log /var/log/nginx/access.log;
 }

Lines starting with a minus are removed, with a plus added, with a space unchanged context. The header @@ -1,11 +1,12 @@ means the block covers lines 1 to 11 of the original and 1 to 12 of the changed text. The patch command can apply a file like this to the original: patch original.conf changes.diff.

Questions

How do I compare two texts for differences?

Paste the older version into the left box and the newer one into the right box. The differences appear right away: removed lines in red, added lines in green, with the changed words marked inside them. Use Swap if you pasted them the wrong way round.

Is my text uploaded anywhere?

No. The comparison runs in your browser with JavaScript, and the text never leaves this page. That makes it safe for configs, logs and code you would not paste into a site that sends text to a server. Closing the tab removes it.

What does ignore whitespace do in a diff?

It treats lines as equal when they differ only in spacing: several spaces or tabs count as one space, and spaces at the start or end of a line are ignored. It is useful after a file was re-indented or tabs were turned into spaces. The words inside changed lines are compared the same way.

How do I compare two files on the command line?

On Linux and macOS: diff -u old.conf new.conf, or git diff --no-index old.conf new.conf for colours and word marks (add --word-diff). On Windows: fc old.conf new.conf in cmd, or Compare-Object (Get-Content old.conf) (Get-Content new.conf) in PowerShell. Add -w to diff to ignore whitespace.

What does @@ -1,11 +1,12 @@ mean in a diff?

It is the header of a block (a hunk) in a unified diff. -1,11 means the block starts at line 1 of the old file and covers 11 lines; +1,12 means it starts at line 1 of the new file and covers 12. Below it, lines starting with - were removed, + were added, and a space means unchanged context.