Understanding Diff Output: Unified vs Split View
Diffs are the lingua franca of software collaboration — every pull request, every code review, every "what changed?" conversation runs on them. Yet many developers read diffs by pattern-matching on red and green without ever learning what the headers and markers actually mean. This guide dissects the unified diff format line by line, explains how split (side-by-side) view presents the same information differently, and shows when each view makes you a faster reviewer.
Anatomy of a Unified Diff
Unified format is what git diff and diff -u print. Here is a complete small example with every part labelled below:
--- a/config/database.yml +++ b/config/database.yml @@ -12,6 +12,7 @@ production: adapter: postgresql host: db.internal - pool: 5 + pool: 20 + timeout: 5000 encoding: utf8
- The --- and +++ headers name the two versions being compared:
---is the old file (conventionally prefixeda/),+++is the new file (b/). - The @@ hunk header —
@@ -12,6 +12,7 @@— gives the coordinates: this hunk starts at line 12 and spans 6 lines in the old file, and starts at line 12 spanning 7 lines in the new file. The text after the second @@ (hereproduction:) is a hint showing the enclosing section or function. - Lines starting with a minus exist only in the old version (removed).
- Lines starting with a plus exist only in the new version (added).
- Lines starting with a space are unchanged context, included so you can orient yourself. Git shows 3 context lines by default (
-U5shows five).
A key insight: unified diffs have no concept of a "changed" line. Changing pool: 5 to pool: 20 is expressed as remove-old plus add-new. When you see a minus line immediately followed by a similar plus line, mentally merge them into "modified".
Split View: The Same Data, Side by Side
Split view (also called side-by-side view) draws the old file in a left column and the new file in a right column, aligning unchanged lines horizontally:
OLD (left) | NEW (right)
------------------------------+------------------------------
adapter: postgresql | adapter: postgresql
host: db.internal | host: db.internal
- pool: 5 | + pool: 20
| + timeout: 5000
encoding: utf8 | encoding: utf8Nothing new is being computed — it is the same set of additions and removals rendered in two columns. The win is that modified lines sit directly opposite each other, so your eyes compare them without jumping between a red block above and a green block below.
When Each View Shines
- Unified wins for small, scattered changes — a one-line fix in five files reads faster as a compact vertical stream.
- Unified wins on narrow screens — split view halves your horizontal space, which forces wrapping or scrolling on laptops and phones.
- Unified reads like the final code — ignore the minus lines and you are reading the new file in order, which helps when judging overall flow.
- Split wins for heavily edited lines — renamed variables, changed parameters, and reworded sentences are much easier to compare side by side.
- Split wins for config and data files — aligned columns make value changes (5 → 20) pop out instantly.
Most reviewers settle on split view for focused review of big changes and unified for quick scans — and switch freely between them.
Reading GitHub Pull Request Diffs
GitHub's "Files changed" tab renders unified view by default, with a toggle to split view in the settings gear (your choice is remembered). A few features worth knowing:
- Word-level highlighting — within a modified line pair, GitHub shades the exact characters that changed, doing the remove/add merging for you.
- Expandable context — click the arrows on hunk headers to reveal the hidden unchanged lines between or around hunks.
- Viewed checkboxes — mark files as viewed to collapse them and track review progress in large PRs.
- Rich diffs — for Markdown and some formats, GitHub can show a rendered before/after instead of raw text.
Whitespace-Only Noise and How to Silence It
Re-indent a file or convert tabs to spaces, and the diff explodes: hundreds of lines marked changed with zero change in meaning. Real logic changes drown in the noise. Every serious diff tool has a mute button for this:
# git: ignore all whitespace differences git diff -w # ignore only changes in the amount of whitespace git diff -b # classic diff diff -u -w old.txt new.txt
- On GitHub, tick Hide whitespace in the Files changed settings, or append
?w=1to the URL. - Better still, keep reformatting commits separate from logic commits so reviewers can skip the noisy one entirely.
If you are comparing two pasted texts rather than commits, the Dev Brains AI Diff Checker gives you a clean line-by-line comparison in your browser. And if you are curious how the tool decides what is added and removed in the first place, read how diff algorithms work.
Frequently Asked Questions
The @@ lines are hunk headers. A header like @@ -12,5 +12,7 @@ means this hunk covers 5 lines starting at line 12 in the old file, and 7 lines starting at line 12 in the new file. Everything until the next @@ header belongs to that hunk.
Use split view when reviewing heavily modified lines, since old and new versions sit side by side for easy comparison. Use unified view for small changes, narrow screens, or when you want to read the new code in its natural flow. GitHub lets you toggle between them per pull request.
In git, use git diff -w to ignore all whitespace. On GitHub, append ?w=1 to the diff URL or use the "Hide whitespace" checkbox in the Files changed tab. This is essential after reformatting or re-indenting code, where hundreds of lines change without any logic changing.