What a Text Diff Shows
A text diff lists the smallest set of edits that turns one text into another. Everything the two versions share is kept as context, and only the parts that differ are marked: removed parts come from Text A, added parts come from Text B. A diff checker saves you from reading two long versions line by line and hoping you spot the change.
Here is the Example from this page. Text A is a short project update. In Text B the status and deadline changed, one task was removed, one was added and the note moved from Monday to Tuesday. In Lines mode the tool gives this patch:
--- text-a.txt
+++ text-b.txt
@@ -1,9 +1,9 @@
Project update
Owner: Ana Silva
-Status: on track
-Deadline: March 3
+Status: at risk
+Deadline: March 10
Tasks:
- write the draft
-- review the budget
- send the invite
-Notes: call the venue on Monday
+- book the room
+Notes: call the venue on TuesdayThe summary reads: 4 lines added, 4 lines removed, 5 lines unchanged. 55.6% similar. On the page, the words that changed inside each pair of lines are marked too, so you see on and track replaced by at and risk without comparing the lines yourself.
How the Comparison Works
The tool splits both texts into units: lines, words or characters. It then finds the longest run of units the two texts share in the same order, using the Myers difference algorithm, the same idea behind git diff and the classic Unix diff. Units outside that shared run are the changes.
- Common lines at the start and end are matched first, so a small edit in a long file is found quickly.
- Lines that appear in only one text are set aside before the main search, because they can never match.
- The search uses memory in proportion to the text size, not the square of it, so a 2 MB file does not exhaust the browser.
- Each removed line is paired with a similar added line nearby, and those two lines get a word level comparison of their own.
When two large texts differ in a great many places, the tool stops refining the busiest areas after a fixed amount of work and marks those blocks as changed in full. Every change is still shown, and a note says when this happened.
Compare Two Texts by Line, Word or Character
Lines mode is right for code, configuration files, lists and logs. Words mode is better for paragraphs, where one edited word would otherwise mark a whole long line. For example, comparing The cat sat on the mat. with The cat sat on the red mat! in Words mode gives:
The cat sat on the {+red +}mat[-.-]{+!+}That is 2 words added, 1 word removed, 6 words unchanged. 80% similar. Punctuation counts as its own word, so a changed full stop is easy to see. Characters mode catches the smallest edits. Comparing Invoice INV-20481 with Invoice INV-20418 gives Invoice INV-204[-8-]1{+8+}, which shows two swapped digits at once.
What Each Option Does
- Ignore case: Hello and hello count as the same.
- Ignore whitespace: in Lines mode every space and tab inside a line is ignored, so
x = 1;matchesx=1;. In Words and Characters mode any run of spaces, tabs and line breaks counts as one space. - Trim trailing spaces: spaces and tabs at the end of a line are ignored. Leading indentation still counts.
- Ignore blank lines: empty and whitespace-only lines are left out of the comparison. Line numbers still refer to the original text.
- Unchanged lines around each change: how much context the result and the patch keep around each change, from 0 lines to the full text.
- Wrap long lines: wraps long lines in the result instead of scrolling sideways.
With Ignore case and Trim trailing spaces on, a query written as SELECT id, name / FROM users with a trailing space and the same query in lower case give: No differences once the ignore options are applied. The page says so plainly rather than claiming the texts are identical.
Reading a Unified Diff Patch
The patch uses the unified diff format that git, GitHub and most code review tools understand. The first two lines name the files. Each block starts with a header such as @@ -1,9 +1,9 @@, which means the block covers 9 lines starting at line 1 in Text A and 9 lines starting at line 1 in Text B. Lines starting with a space are context, - means removed and + means added.
If you open files, their names go into the header. If one text ends with a line break and the other does not, the patch adds the standard marker line:
--- text-a.txt
+++ text-b.txt
@@ -1,2 +1,2 @@
timeout = 30
-retries = 3
\ No newline at end of file
+retries = 3When any ignore option is on, context lines are copied from Text A and lines the options hid are left out, so such a patch is for reading and may not apply cleanly with a patch tool.
When to Use a Diff Checker and Its Limits
Use it to check what an editor changed in a contract or article, compare two exports of a configuration file, review a generated file before you commit it, or find the one changed value in two long logs. If order does not matter and you only want to know which items appear in one list and not the other, Compare Two Lists answers that more directly.
- Each text can be up to 2,000,000 characters, and Lines mode compares up to 300,000 lines per text.
- The view draws the first 2,000 rows. Copy and Download always include every change.
- Windows (CRLF) and Unix (LF) line breaks are treated as equal, and a note says when the two texts use different ones.
- It compares plain text. Word documents, PDFs and images are not read.
- Moved blocks show as removed in one place and added in another. The tool does not detect moves.
Messy spacing can hide the real changes. Run both texts through Remove Extra Spaces first, or put lines in a stable order with Sort Lines when order does not matter. Remove Duplicate Lines helps when repeated lines make the diff noisy.
Diff Two Files From the Command Line
The patch on this page matches what these commands print, so you can move between the browser and the terminal.
diff -u text-a.txt text-b.txt
git diff --no-index text-a.txt text-b.txt
git diff --no-index --word-diff=plain text-a.txt text-b.txtThe last command prints the same [- -] and {+ +} markers that Words mode copies. In Python, difflib.unified_diff produces a unified diff from two lists of lines.
Privacy
Both texts are compared in your browser, in a background worker on this page. They are not uploaded, stored or logged. See the Privacy Policy for details.