How to Compare Two Text Files (Diff)

Whether you're reviewing a code change, checking two config files, or proofreading edits, comparing text is something developers do constantly. Here's how diffing works.

What a diff shows

A diff highlights the differences between two pieces of text, line by line:

  • Added lines (in the new version) — usually green with a +.
  • Removed lines (from the old version) — usually red with a -.
  • Unchanged lines — shown for context.

A simple example

Old:

host: localhost
port: 8080

New:

host: localhost
port: 9090

A diff shows port: 8080 removed and port: 9090 added — the one line that changed jumps out immediately.

Line diff vs word diff

  • Line diff — compares whole lines. Best for code and config.
  • Word/character diff — highlights the exact characters that changed within a line. Better for prose.

Why it beats reading manually

For anything longer than a few lines, spotting differences by eye is slow and error-prone. A diff tool finds every change instantly and never misses a stray character.

Common uses

  • Reviewing code changes before committing
  • Comparing two versions of a config file (pair with the config validator)
  • Checking what an API response changed between two calls
  • Proofreading document edits

Try it

Paste both versions into the diff checker to see exactly what was added and removed.

Got a config file to check?

Open the config toolkit →