Text Diff Checker

Paste two versions of a text to see exactly which lines and words changed. Export the result as a unified diff.

0 lines
0 lines

Paste text into both boxes (or click Load example) to see the differences.

What this diff checker is for

When two versions of a text look almost the same, spotting what changed by eye is slow and unreliable. This tool compares an Original and a Modified text line by line and marks every removed line in red and every added line in green. Inside lines that were edited, the exact words that changed get a darker highlight, so a port number that went from 8080 to 8443 stands out immediately.

It is useful whenever you do not have both versions in a Git repository: comparing a configuration file from two servers, checking what a colleague changed in a pasted SQL query, reviewing edits to a contract or translation, or looking at two API responses side by side. For structured JSON, the JSON diff tool compares keys and values regardless of formatting, which is often more useful than a line diff.

How to use it

  1. Paste the old version into Original and the new version into Modified. Click Load example to try it with a small YAML file.
  2. The diff updates as you type. Choose Side by side to see both versions in two columns, or Inline for a single column like a pull request.
  3. Tick Ignore whitespace or Ignore case if indentation or capitalisation changes are noise for you.
  4. Tick Only changes to hide long unchanged stretches and keep three lines of context around each change.
  5. Click Copy unified diff or Download .patch to save the result. Swap sides reverses the direction of the comparison.

Worked example

The built-in example changes a server configuration: the port goes from 8080 to 8443, a tls: true line is added, the logging level and format change, and the export feature is removed. The tool reports +4 added, −4 removed and 6 unchanged, and the unified diff it exports is:

--- a/original.txt
+++ b/modified.txt
@@ -1,10 +1,10 @@
 server:
   host: 0.0.0.0
-  port: 8080
+  port: 8443
   timeout: 30
+  tls: true
 logging:
-  level: info
-  format: text
+  level: debug
+  format: json
 features:
   - search
-  - export

Because all the changes are within three lines of each other, they end up in a single hunk. The header @@ -1,10 +1,10 @@ means the hunk starts at line 1 and covers 10 lines in both the old and the new file.

Reading the result

  • Red lines (−) exist only in the original. Green lines (+) exist only in the modified text. White lines are identical in both.
  • Line numbers refer to each side: the left (or first) number is the line in the original, the right (or second) is the line in the modified text.
  • Darker highlights inside a red/green pair mark the words or symbols that changed. Pairs are formed in order inside each block of changes.
  • In the patch, a line \ No newline at end of file means the text did not end with a line break, exactly as git prints it.

Limitations

  • The comparison is line-based. A paragraph rewrapped onto different lines shows up as many changed lines even if the words are the same.
  • Moved blocks are shown as a removal in one place and an addition in another; there is no move detection.
  • Each side is limited to 2,000,000 characters and 100,000 lines, and the screen shows the first 5,000 rows. If two large texts differ almost everywhere, the search for the minimal diff stops after a few seconds and the remaining region is shown as one block (still correct, just less granular).
  • When ignore options are on, the patch treats lines that differ only in whitespace or case as unchanged, so applying it will not reproduce those particular edits.
  • Line endings are normalised: a file with Windows CRLF line breaks compares equal to the same file with LF line breaks.

Tips

  • Format code or JSON the same way on both sides before comparing; otherwise formatting noise hides the real changes. The JSON formatter helps with that.
  • Keep the original on the left. If the colours look backwards, click Swap sides.
  • The patch header names the files a/original.txt and b/modified.txt. Change both paths to your real file name, then run git apply changes.patch in the repository folder.

Frequently Asked Questions

What algorithm does this diff checker use?

It uses the Myers O(ND) difference algorithm, the same family of algorithm behind git diff and GNU diff. It finds the smallest set of added and removed lines that turns the original text into the modified one.

Can I apply the downloaded .patch file with git or patch?

Yes. The export is a standard unified diff with ---/+++ headers, @@ hunk headers and 3 lines of context, so git apply or patch -p1 will apply it to a file named original.txt with the original content (edit the header paths to target another file). If Ignore whitespace or Ignore case is on, lines that differ only in those ways are treated as unchanged and are not part of the patch.

What does Ignore whitespace do exactly?

Two lines are considered equal if they only differ in leading or trailing spaces, or in the length of runs of spaces and tabs inside the line. It is similar to combining git diff -b with trimming the line ends; removing a space entirely between two words still counts as a change.

How large can the texts be?

Each side can have up to 2,000,000 characters and 100,000 lines. Typical files of a few thousand lines are compared almost instantly; the view shows up to 5,000 rows, and the downloadable patch always contains the complete diff.

Why are some changed lines shown as removed and added instead of modified?

A line diff only knows that a line disappeared and another appeared. When a block of removed lines sits next to a block of added lines, the tool pairs them in order and highlights the changed words inside each pair, which is usually what you want for small edits.

Is my text uploaded to a server?

No. The comparison runs entirely in your browser with JavaScript. Neither text is sent to StackUtils or any third party, so it is safe to compare configuration files or private documents.