Comparing two versions of a file sounds trivial until the result is a wall of red and green where almost nothing really changed. Different line endings, re-indented code, a re-sorted spreadsheet or a column inserted in the middle can make a diff tool report every line as different.
This guide explains how diff algorithms decide what changed, why the same edit can be shown in different ways, how to strip out the noise that hides real changes, and how comparing spreadsheets differs from comparing text. It closes with git options that make everyday diffs easier to read.
Line, word and character diffs
The unit of comparison changes what you see. Line diffs are the standard for code and config, because each line is usually one statement or setting. Word diffs suit prose, where a paragraph is a single very long line and a line diff would only tell you "this paragraph changed". Character diffs are best for short values such as IDs, hashes and numbers, where one wrong digit matters.
- Code, YAML, .env and CSV files: line diff, with word highlighting inside changed lines.
- Contracts, articles and documentation: word diff, or a line diff after wrapping text to one sentence per line.
- API keys, checksums, long numbers: character diff, or simply compare them as equal or not.
- JSON: format both sides with the same indentation and key order first, then line diff. Minified JSON is a single line, so any change marks the whole document as different.
Removing noise: whitespace, line endings and order
Most unhelpful diffs come from differences that do not matter to the content. Normalise them before comparing, or tell the tool to ignore them.
- Line endings: Windows uses CRLF (\r\n), Linux and macOS use LF (\n). A file converted from one to the other differs on every line while looking identical. Convert both to LF before comparing, and in git set a .gitattributes rule so line endings are normalised on commit.
- Trailing whitespace and indentation: re-indenting a block or an editor stripping trailing spaces marks lines as changed. Ignore whitespace for review, but remember it does matter in Python, YAML and Makefiles.
- Encoding and BOM: a UTF-8 byte order mark or a file saved in a different encoding changes the first line or every accented character.
- Order: if two exports contain the same records in a different order, a line diff reports almost everything as moved. Sort both sides the same way first, or use a key-based comparison.
- Volatile values: timestamps, generated IDs and build numbers change every run. Strip or mask them before comparing logs or test snapshots.
# .gitattributes: store text files with LF, check out per platform
* text=auto eol=lf
*.bat text eol=crlfComparing spreadsheets is a different problem
A spreadsheet is a grid, not a sequence of lines. The simplest comparison lines the two sheets up by position and reports each cell whose value differs. That works well when the structure is the same in both versions, such as an edited budget or a price list where only figures changed.
Position-based comparison falls apart when rows are inserted, deleted or re-sorted. Insert one row near the top and every cell below it is "different". In that case, compare by a key column instead: match rows by an ID, SKU or email address, then compare the other columns for each matched pair, and list keys that exist only on one side as added or removed.
- Compare values, not formatting. Number formats, colours and column widths change constantly and rarely matter. Decide whether 1000 and 1,000.00 should count as equal.
- Watch for values that look equal but are not: trailing spaces, numbers stored as text, dates stored as text versus real date serials, and leading zeros dropped from codes like 00123.
- Formulas versus results: two sheets can show the same number with different formulas, or the same formula with different inputs. Know which one you are comparing.
- For row-reordered data, sorting both sheets by the key column before a cell-by-cell comparison is a quick workaround.
- For large data sets, export both versions to CSV and compare in a database or script with a join on the key column.
git diff options worth knowing
If the files are in a git repository, git diff already includes most of what you need, and git diff --no-index compares any two files on disk even outside a repository.
git diff --word-diff # show changed words inline, good for prose
git diff -w # ignore all whitespace changes
git diff --ignore-cr-at-eol # ignore CRLF vs LF differences
git diff --color-moved # highlight blocks that moved, not changed
git diff --diff-algorithm=histogram # often clearer than the default
git diff --stat # summary of files and line counts
git diff --no-index a.txt b.txt # compare two files outside a repoA quick workflow
For text, configs, logs and API responses, paste or drop both versions into the Text Diff Checker. Turn on its whitespace option if indentation changes are not relevant, and hide unchanged lines on long files so only the differences remain. For JSON, format both sides the same way first so the diff shows real field changes. The comparison runs in the browser, which matters when the files contain credentials or customer data.
For workbooks and CSV exports, use Excel Compare to highlight changed, added and removed cells between two versions of a sheet, with options to ignore case and surrounding whitespace. If rows were re-sorted between versions, sort both files by the same key column before comparing.