🔍
Developer Tools
March 19, 20266 min readBy BrowseryTools Team

How to Compare Text Files and Find Differences Without Any Software

Learn how text diff algorithms work, how to read unified diff output, the difference between line-level and word-level diffs, and how git diff works under the hood.

difftext comparisongitcode reviewfile comparison

Every developer has faced this situation: two versions of a file that should be identical, but something changed. Maybe it is a config file that was manually edited on a server. Maybe it is a contract that came back from a lawyer with undisclosed changes. Maybe it is a translation file that a vendor returned and you need to verify nothing was accidentally deleted. In all these cases, the answer is the same: run a diff.

You can compare any two blocks of text instantly using the BrowseryTools Text Diff tool — free, no sign-up, everything stays in your browser.

Why Text Diffing Matters

Text diffing is not just a developer tool. Any situation where two versions of a document exist and differences need to be surfaced is a diffing problem:

  • Code review — understanding what changed between two versions of source code before approving a merge
  • Contract and legal document comparison — identifying exactly which clauses were added, removed, or modified between drafts
  • Configuration management — confirming that a deployed config file matches the version in source control
  • Translated content verification — checking that a translated document covers all the same sections as the original
  • Data validation — comparing CSV exports from two systems to find discrepancies
  • Proofreading — catching unintended changes between a document draft and its published version

How Diff Algorithms Work

The core problem a diff algorithm solves is: given two sequences A and B, find the minimum set of edits (insertions and deletions) required to transform A into B. This is formally the Longest Common Subsequence (LCS) problem. The diff then reports what was not in the LCS — the lines unique to A (deletions) and the lines unique to B (insertions).

Two algorithms dominate practical implementations:

  • Myers diff (1986) — the algorithm behind the original Unix diffcommand and Git. Eugene Myers designed it to find the shortest edit script (the diff with the fewest total insertions and deletions) in O(ND) time, where N is the total size of both inputs and D is the number of differences. It is fast and produces minimal diffs, but can produce unintuitive output when large blocks of code are moved.
  • Patience diff — developed by Bram Cohen (creator of BitTorrent) and used by Bazaar, later popularized by Kaleidoscope. Instead of working line by line, patience diff first matches unique lines that appear exactly once in both files. This produces output that preserves function and block boundaries much better than Myers diff for source code. Git supports it viagit diff --patience.

Reading Unified Diff Output

The unified diff format is the standard output of git diff and most diff tools. Once you understand the notation, it becomes instantly readable.

--- a/config.yml       (original file)
+++ b/config.yml       (modified file)
@@ -10,7 +10,8 @@     (hunk header)
 server:
   host: localhost
-  port: 3000
+  port: 8080
+  timeout: 30
   debug: false

The key elements to read:

  • Lines starting with - — present in the original, removed in the new version (shown in red)
  • Lines starting with + — not in the original, added in the new version (shown in green)
  • Lines with no prefix (space) — unchanged context lines, shown for orientation
  • The @@ hunk header — reads as "starting at line 10, showing 7 lines from the original; starting at line 10, showing 8 lines from the new version." The format is@@ -start,count +start,count @@.

Word-Level vs Line-Level vs Character-Level Diff

The granularity of a diff determines how useful it is for a given task.

  • Line-level diff — the default for source code. Each line is treated as an atomic unit. Fast and appropriate for code where lines are short and meaningful. If a single word changes in a long paragraph, the entire line shows as changed.
  • Word-level diff — appropriate for prose and documentation. Changed words within a line are highlighted individually, giving much clearer signal in text-heavy documents. Most document comparison tools (Microsoft Word Track Changes, Google Docs version history) operate at word level.
  • Character-level diff — highlights individual character changes within words. Most useful for detecting subtle typos, whitespace changes, invisible characters (zero-width spaces, non-breaking spaces), or encoding differences. Essential for comparing data that looks identical visually but differs at the byte level.

The BrowseryTools Text Diff tool highlights differences inline, making it easy to spot changes at a glance without reading the unified diff format manually.

Git Diff Under the Hood

When you run git diff, Git computes the Myers diff between the object versions stored in its object database. A few useful flags change the behavior:

git diff                      # unstaged changes vs last commit
git diff --staged             # staged changes vs last commit
git diff HEAD~3               # current state vs 3 commits ago
git diff main...feature       # what feature branch adds to main
git diff --word-diff          # word-level highlighting
git diff --patience           # use patience algorithm (better for code)
git diff --stat               # summary: files changed, insertions, deletions

Understanding git diff main...feature specifically: the triple-dot notation shows what the feature branch has added since it diverged from main, excluding any changes that have happened on main since the branch point. This is almost always what you want for pull request review, rather than the double-dot main..feature which compares the current tips of both branches directly.

Practical Use Cases

Comparing Config Files

Config files (YAML, TOML, JSON, .env) are frequent sources of production bugs when deployed versions diverge from source-controlled versions. Before debugging a mysterious production issue, diffing the live config against the expected config often surfaces the cause immediately.

Contract and Document Comparison

When a contract draft comes back from the other party, never trust a summary of what changed. Export both versions to plain text and run a diff. Lawyers are known to change defined terms, add liability caps, or alter notice periods in ways that a quick read misses. A word-level diff makes every change visible.

Translated Document Verification

When working with translated content, compare the translated document's structure against the source. A structural diff of section headings and paragraph counts reveals whether any sections were accidentally omitted or merged during translation.

Diff Tools Compared

  • git diff — built-in, line-level, unified diff format, no GUI. The baseline for all code work.
  • vimdiff — terminal-based side-by-side diff inside Vim. Powerful for quick comparisons without leaving the terminal; steep learning curve.
  • Beyond Compare — commercial desktop tool with folder sync, binary diff, and three-way merge. The gold standard for non-developer document comparison.
  • Meld — free, cross-platform GUI diff tool with three-way merge support. The best free alternative to Beyond Compare.
  • BrowseryTools Text Diff — instant, browser-based, no installation. Best for quick one-off comparisons, especially for text you would not want to paste into an online service.

🛠️

Try the Tools — 100% Free, No Sign-Up

Everything runs in your browser. No uploads. No accounts. No ads.

Explore All Tools →