Text Diff

Compare two versions of a text and see which lines were added, removed or changed, down to the word. Both texts stay on your device.

Runs in your browser. Your input is not sent anywhere.

Off by default. When on, the fields of this tool are kept in the local storage of this browser, unencrypted, until you turn it off.

Nothing to compare yet

Your result will appear here.

Keyboard shortcuts

Ctrl + Enter, ⌘ + Enter
Run the tool with the current input
Alt + Shift + C
Copy the result
Alt + Shift + X
Clear all fields

Shortcuts work while the focus is inside the tool. Every action is also available as a button.

What this tool does

The tool compares two texts line by line and shows the smallest set of lines that must be removed from the first text and added to it to get the second. The result can be copied or downloaded in the unified format, which the programs diff, patch and git use.

Lines are compared first. A line in which one word changed is shown as one removed and one added line, and within that pair the changed words, or characters if you prefer, are marked. The result can be shown in one column, as in a unified diff, or side by side.

How to use it

  1. Paste the earlier version into “Original text” and the later version into “Changed text”.
  2. If differences in spaces, tabs or case do not matter, set the options below the fields. Choose whether changed words or single characters are marked, and whether the result is shown in one column or side by side.
  3. Read the result. Removed lines carry a minus sign and the line number of the original, added lines a plus sign and the line number of the changed text. Side by side, the original is on the left and the changed text on the right.
  4. Select “Copy as unified diff” or “Download as unified diff” to take the result with you.

Lines may end with a line feed, with a carriage return and a line feed, or with a carriage return alone. The kind of line ending and a line ending after the last line are not compared.

How the result is derived

First the lines that both texts share at the start and at the end are set aside. The part in between is compared with the algorithm that Eugene W. Myers published in 1986. It finds a shortest edit script: a way to turn one sequence into the other with the fewest removals and additions.

The work and the memory of the algorithm grow with the number of differences, not only with the length of the texts. Two long texts with a few changes are compared quickly. If more than 1500 lines would have to be removed and added in total between the first and the last common line, the tool does not search for matching lines in between. It shows that part as removed and added as a whole and tells you so.

Within a block of changed lines, the first removed line is paired with the first added line, the second with the second, and so on. Each pair is compared again with the same algorithm, token by token. In word mode a token is a run of letters, digits and underscores in any script, a run of spaces and tabs, or a single other character; in character mode every character is a token, except that a run of spaces and tabs stays together. Tokens that differ are marked. The options for case and spaces apply here as they do to whole lines: a change of case, spaces at the end of a line and, with “Ignore changes in the amount”, indentation and the length of a run of spaces are not marked. Pairs without a single common token, pairs that differ in more than 500 tokens, and lines of more than 5000 tokens are shown without marks.

The table shows up to 2000 lines. The unified diff that you copy or download is always complete and does not depend on the view or the marks.

Worked example

Original text and changed text
Original      Changed
--------      -------
one           one
two           2
three         three
four          four
              five
Result in the unified format
--- original
+++ changed
@@ -1,4 +1,5 @@
 one
-two
+2
 three
 four
+five

The tool reports 2 lines added, 1 removed and 3 unchanged. Because “two” and “2” have nothing in common, that pair is shown without marks.

Within a line, the marks show what changed. For the line “title: The quick brown fox” changed to “title: The quick red fox!”, word mode marks brown on the removed line, and red and the exclamation mark on the added line. Character mode, for “color: #3142a6” changed to “colour: #3142A6”, marks the a on the removed line, and the u and the capital A on the added line.

Reference: reading a unified diff

Lines of a unified diff
Line starts withMeaning
---Name of the original file
+++Name of the changed file
@@ -1,4 +1,5 @@Start of a section: it covers 4 lines from line 1 of the original and 5 lines from line 1 of the changed text
A spaceUnchanged line, shown for context
-Line that exists only in the original
+Line that exists only in the changed text

A section, called a hunk, contains up to three unchanged lines before and after each change. Changes that are close to each other share a hunk. When a range covers exactly one line, the number of lines is left out.

The tool names the two sides “original” and “changed”, because it does not know file names. Replace them with the path of the file if you want to apply the result with the program patch.

Common mistakes

  • Swapping the two texts. Added and removed lines then change places.
  • Comparing text with different indentation. Every line differs, although nothing else changed. Use the option for spaces and tabs.
  • Comparing text whose lines were wrapped differently. A line-based comparison cannot see that the words are the same.
  • Expecting the comparison to understand the content. A moved paragraph is a removal in one place and an addition in another.
  • Reading an ignored difference as equality of the files. With the options set, lines can count as equal although their bytes differ.

Sources

Eugene W. Myers: An O(ND) Difference Algorithm and Its Variations. Algorithmica, volume 1, 1986, pages 251 to 266.

Frequently asked questions

Are my texts uploaded for the comparison?
No. Both texts are compared by a script in the page. They are not sent to a server and not stored, unless you turn on “Remember my input on this device”.
Does the tool show which words changed within a line?
Yes. A changed line appears as a removed line and an added line, and the words that differ are marked on both. Switch to “Mark changed characters” for code, numbers or identifiers where a single character matters.
Can I apply the result with patch or git apply?
The result is in the unified format. In our tests the program patch applied it to the original text and produced the changed text. Set the file names in the first two lines to the file you want to change.
Why are lines shown as unchanged although they differ?
One of the options to ignore case, spaces or tabs is set. Lines that count as equal under the options are shown as they are in the changed text.
How large can the texts be?
There is no fixed limit. Texts of more than 200,000 characters in total are compared when you select “Compare”, not while you type. What matters most for the speed is the number of differing lines.

Last updated: September 29, 2026