Text Diff

Compute a unified diff between two blocks of text (line-based).

How to read the unified diff

Text A and text B are compared line by line. For a configuration file in which one value changed and one line was added, the result is:

--- A
+++ B
@@ -1,3 +1,4 @@
 host = db.example.com
-port = 5432
+port = 6432
 user = app
+sslmode = require
  • --- A and +++ B name the two inputs.
  • @@ -1,3 +1,4 @@ is the hunk header: the hunk covers 3 lines of A starting at line 1 and 4 lines of B starting at line 1.
  • A line that begins with - exists only in A; a line with + exists only in B. A changed line appears as a - line followed by a + line.
  • A line that begins with a space is unchanged context. Up to 3 unchanged lines are shown around each change.

When two texts that look equal differ

  • Trailing spaces and tabs. A space at the end of a line makes the line different. So does a tab where the other text has spaces.
  • Line endings. A file from Windows ends lines with CR LF, a file from Linux or macOS with LF.
  • Look-alike characters. A non-breaking space, a curly quote pasted from a word processor, or a Cyrillic а in place of a Latin a are different characters with the same appearance.
  • Reordered lines. The comparison follows line order. Two lists with the same entries in a different order differ; sort both first when only the set of lines matters.

An empty result means the two texts are identical, character for character.

Related tools

Monitor Text Diff automatically

Compute a unified diff between two blocks of text (line-based). NetTests can run this check on a schedule, preserve historical results, compare changes over time, and alert you the moment something breaks.

Start monitoring free → See all monitoring products

Frequently Asked Questions

What is a unified diff?

A unified diff shows changes between two texts in a compact format: lines preceded by - were removed, lines with + were added, and lines with no prefix are unchanged context. The @@ -1,4 +1,5 @@ hunk header shows which lines in the original (-) and new (+) text are affected. This is the standard format used by Git and most version control systems.

What is this useful for?

Comparing configuration files before and after a change, reviewing edits to documents or scripts, generating patch files, spotting unintended whitespace changes, and verifying that a processed/transformed version of text matches expectations. It's also helpful for comparing Application Programming Interface (API) responses or log snippets.

Is the diff case-sensitive?

Yes — by default, the comparison is case-sensitive and whitespace-significant. A line reading Hello differs from hello. Trailing whitespace differences are also flagged. Normalize your input (trim, lowercase) before comparing if you only care about content, not formatting.