
Last checked by the TextEditor.com team
What a diff is
Diff is short for difference. It is a program that takes two versions of a text and shows which lines changed. James Hunt and Douglas McIlroy wrote the first diff at Bell Labs in 1976 for Unix. It looks for the longest run of lines that both versions share, in the same order. Every line outside that run was added or removed.
Eugene Myers published a faster way to find that run in 1986. Most tools, including Git and this page, still use his method. Try it: change a word in either box and watch the result.
| 1 | - | Bring milk | 1 | + | Bring oat milk |
| 2 | - | Bring eggs | |||
| 3 | Bring bread | 2 | Bring bread | ||
| 3 | + | Bring apples |
1 addition, 1 deletion, 1 changed line
How to read a side by side diff
The original is on the left and the changed version on the right. Each side keeps its own line numbers, so a line can be number 7 on the left and number 9 on the right.
| 4 | Open from 9 to 5. | 4 | Open from 9 to 5. | ||
| 5 | - | Closed on Sunday. | |||
| 5 | + | Open on Sunday until noon. | |||
| 6 | - | Call | 6 | + | Call 555 0199 to book. |
| … 12 unchanged lines | |||||
- No sign, plain row: the line is the same in both versions.
- Minus sign, warm tint: the line was removed. The right side is empty.
- Plus sign, green tint: the line was added. The left side is empty.
- Both signs, marked words: the line was edited. Only the marked words differ.
- Folded row: with "Only differences" on, unchanged runs fold into one row. Click it to see them.
The unified view puts both texts in one column, removed lines first, then added lines. It is the same layout that Git and code review tools use. The arrows above the result jump from change to change, which helps in a long document.
Line, word or character
By default the tool compares lines, then marks the changed words inside each changed line. That is the right choice for code, lists and anything with short lines. For prose, pick "word": the whole text is one stream, so a sentence that moved to another line is not a change. Pick "character" for short strings like a name, an address or a serial number, where one wrong letter matters.
| The quick brown |
By word, two words changed. By character, only the letters that differ are marked, so "jumps" and "jumped" share "jump".
What people compare
- Essay drafts. Paste the version you sent and the version that came back to see every edit. The word counter tells you how much longer the new draft is.
- Contracts and terms. A new version of a contract often changes one number or one word. Turn on "Ignore whitespace" so a reformatted paragraph does not hide the real change.
- Code and config files. Open both files, compare by line, then copy the unified diff into a bug report. For editing, use the code editor.
- Translations. Compare the first draft with the proofread version to learn what the reviewer changed.
- Lists. Two exports of the same list, a price list from last month and this month, or a guest list before and after edits. "Ignore case" and "Trim line ends" remove the noise from copy and paste.
Typing a draft first? The plain text editor saves it in your browser, and you can paste it here later.
The unified diff format
"Copy as unified diff" gives you the result as text in the format that the Unix diff command prints with the -u flag. Git, code review tools and the patch program all read it, and it pastes well into an email or a bug report.
--- original.txt +++ changed.txt @@ -4,3 +4,3 @@ Open from 9 to 5. -Closed on Sunday. +Open on Sunday until noon. Call 555 0100 to book.
- --- and +++ name the original and the changed file.
- @@ -4,3 +4,3 @@ is a hunk header: this part starts at line 4 and covers 3 lines in the original, and starts at line 4 and covers 3 lines in the changed text.
- A space starts an unchanged line, a minus a removed line, a plus an added one. Unchanged lines around a change give the reader some context.
What a diff can't tell you
A diff matches lines in order. A paragraph that moved to another place shows up as removed in one spot and added in another, even if not one word changed. A paragraph with new line breaks but the same words shows as changed in line mode. Switch to word mode and it disappears.
The ignore options cover case, spacing and blank lines. The tool does not know that "colour" and "color" mean the same thing, and it does not understand Word formatting. For .docx files, copy the text out of Word, or open the file in the Word editor and copy it from there.
Speed is not a problem for normal documents. Two texts of 5,000 lines compare in well under a second. Above 200 KB the live update stops and you press Compare instead.
Get two texts ready to compare
- Put lines in orderc b a → a b cSort lines from A to Z, by number or at random.
- Remove repeated linesa a b → a bKeeps the first copy of each line and drops the rest.
- Clean up pasted texta b → a bThe text cleaner removes extra spaces and hidden characters.
- Count words and charactersHello world → 2 wordsThe word counter also checks the limits of social media.