# Review an agent's diff in the terminal with git diff

> The git diff options that make a coding agent's change quick to review: stats, pathspecs, whitespace, moved code, renames, three dots, add -p and delta.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2026-11-30 | Topics: [AI](https://flaviocopes.com/tags/ai/), [Git](https://flaviocopes.com/tags/git/) | Canonical: https://flaviocopes.com/git-diff-review/

A coding agent finishes a task and tells you it changed 15 files. Before you accept anything, you want to know what it really did.

Plain `git diff` dumps everything at once, in file order, with the lockfile right in the middle. Git has plenty of options to cut that down, and most people never use them.

In this post, we'll review one agent change from start to finish, right in the terminal. I ran every command below on a real throwaway repository, so you can see what each option does to the same diff.

## The example change

The project is a tiny Express shop with a cart, a discount function, a few routes and tests.

The agent worked on the `agent/discount-cap` branch, where we asked it to stop the `FLAT5` discount code from making a cart total negative. It did that, and also:

- moved `applyDiscount()` from `src/cart.js` to a new `src/discount.js`
- renamed `src/utils.js` to `src/format.js`
- reindented `src/api.js` and the routes from 4 spaces to 2
- bumped Express, which rewrote `package-lock.json`
- touched a few other things it wasn't asked to touch

That mix is typical: a few lines of real fixes buried inside moves, renames and formatting. Our goal is to dig out the lines that change behavior.

If you run agents in parallel, each one usually gets its own branch in a [Git worktree](https://flaviocopes.com/git-worktrees/). Everything we'll run here works the same inside a worktree.

Here's the order we'll follow:

```mermaid
flowchart TD
  accTitle: Reviewing an agent's change in the terminal
  accDescr: Start with git status and the diff stats, hide the lockfile and whitespace noise, read moved code and renames, then accept hunks with git add -p or reject them with git restore -p, check the staged diff and commit.
  A["git status -sb"] --> B["git diff --stat<br/>without the lockfile"]
  B --> C["git diff -w<br/>hide whitespace"]
  C --> D["--color-words and<br/>--color-moved"]
  D --> E{"Is this hunk right?"}
  E -->|yes| F["git add -p"]
  E -->|no| G["git restore -p"]
  F --> H["git diff --staged --check"]
  G --> H
  H --> I["git commit"]
```

## Start with git status -sb

Let's start with `git status -sb`. It gives us the short format plus the branch line, one line per file:

```bash
git status -sb
```

```text
## agent/discount-cap
 M README.md
 M docs/CHANGELOG.md
 M package-lock.json
 M package.json
 M src/api.js
 M src/cart.js
 M src/config.js
 M src/index.js
 M src/routes/checkout.js
 M src/routes/products.js
 M src/stats.js
 D src/utils.js
 M test/cart.test.js
?? src/discount.js
?? src/format.js
?? test/discount.test.js
```

Notice the three `??` lines, which are new files the agent created without adding them. **`git diff` doesn't show untracked files at all**, so if you skip `git status`, you'll miss them completely:

```bash
git diff --stat
```

```text
 README.md              |   2 +-
 docs/CHANGELOG.md      |   5 ++
 package-lock.json      | 200 +++++++++++++++++++++++++----------------------
 package.json           |   4 +-
 src/api.js             |  24 +++---
 src/cart.js            |  15 +---
 src/config.js          |   2 +-
 src/index.js           |   3 +-
 src/routes/checkout.js |   6 +-
 src/routes/products.js |   9 ++-
 src/stats.js           |   8 +-
 src/utils.js           |  14 ----
 test/cart.test.js      |   6 +-
 13 files changed, 151 insertions(+), 147 deletions(-)
```

`src/discount.js` is missing, and `src/utils.js` looks deleted.

The fix is `git add -N` (intent to add). It records those paths in the index without their content, so `git diff` starts showing them as new files:

```bash
git add -N src/discount.js src/format.js test/discount.test.js
```

Now `git status` also detects the rename:

```text
## agent/discount-cap
 M README.md
 M docs/CHANGELOG.md
 M package-lock.json
 M package.json
 M src/api.js
 M src/cart.js
 M src/config.js
 A src/discount.js
 R src/utils.js -> src/format.js
 M src/index.js
 M src/routes/checkout.js
 M src/routes/products.js
 M src/stats.js
 M test/cart.test.js
 A test/discount.test.js
```

> Be careful with `git add -N .`, because a `.` pathspec also stages deletions. That moved `src/utils.js` into the index as deleted and made the rename disappear from `git diff`, so name the new files instead.

## Get the shape with --stat and friends

`--stat` gives us the table of contents of a diff. With the new files included, we get:

```bash
git diff --stat
```

```text
 README.md                   |   2 +-
 docs/CHANGELOG.md           |   5 ++
 package-lock.json           | 200 ++++++++++++++++++++++++--------------------
 package.json                |   4 +-
 src/api.js                  |  24 +++---
 src/cart.js                 |  15 +---
 src/config.js               |   2 +-
 src/discount.js             |   9 ++
 src/{utils.js => format.js} |   2 +-
 src/index.js                |   3 +-
 src/routes/checkout.js      |   6 +-
 src/routes/products.js      |   9 +-
 src/stats.js                |   8 +-
 test/cart.test.js           |   6 +-
 test/discount.test.js       |  11 +++
 15 files changed, 172 insertions(+), 134 deletions(-)
```

`--compact-summary` prints the same table with `(new)` and `(gone)` markers, making created files easy to spot:

```bash
git diff --compact-summary
```

```text
 README.md                   |   2 +-
 docs/CHANGELOG.md           |   5 ++
 package-lock.json           | 200 ++++++++++++++++++++++++--------------------
 package.json                |   4 +-
 src/api.js                  |  24 +++---
 src/cart.js                 |  15 +---
 src/config.js               |   2 +-
 src/discount.js (new)       |   9 ++
 src/{utils.js => format.js} |   2 +-
 src/index.js                |   3 +-
 src/routes/checkout.js      |   6 +-
 src/routes/products.js      |   9 +-
 src/stats.js                |   8 +-
 test/cart.test.js           |   6 +-
 test/discount.test.js (new) |  11 +++
 15 files changed, 172 insertions(+), 134 deletions(-)
```

When we only want the totals, `--shortstat` keeps it to one line:

```bash
git diff --shortstat
```

```text
 15 files changed, 172 insertions(+), 134 deletions(-)
```

`--name-status` prints one letter per file, plus a similarity score for renames. It's the easiest format to paste into a script or back into the agent's chat:

```bash
git diff --name-status
```

```text
M	README.md
M	docs/CHANGELOG.md
M	package-lock.json
M	package.json
M	src/api.js
M	src/cart.js
M	src/config.js
A	src/discount.js
R086	src/utils.js	src/format.js
M	src/index.js
M	src/routes/checkout.js
M	src/routes/products.js
M	src/stats.js
M	test/cart.test.js
A	test/discount.test.js
```

`R086` means Git considers `src/format.js` 86% similar to `src/utils.js`. Use `--name-only` when you only want the file paths.

`--dirstat` shows where the change is concentrated, directory by directory:

```bash
git diff --dirstat
```

```text
   5.2% src/routes/
  15.5% src/
   5.1% test/
```

By default, `--dirstat` counts changed lines and skips the repository root. Because the 200-line lockfile and the README don't get a row, the percentages don't add up to 100.

With `--dirstat=files,cumulative`, we count files instead and roll subdirectories into their parent:

```bash
git diff --dirstat=files,cumulative
```

```text
   6.6% docs/
  13.3% src/routes/
  60.0% src/
  13.3% test/
```

## Cut the noise with pathspecs

Everything after `--` is a **pathspec**, a filter that controls which files the diff covers.

A pathspec starting with `:!` excludes files. Here the lockfile is 200 of the 306 changed lines, so let's drop it first:

```bash
git diff --stat -- . ':!package-lock.json'
```

```text
 README.md                   |  2 +-
 docs/CHANGELOG.md           |  5 +++++
 package.json                |  4 ++--
 src/api.js                  | 24 ++++++++++++------------
 src/cart.js                 | 15 +++------------
 src/config.js               |  2 +-
 src/discount.js             |  9 +++++++++
 src/{utils.js => format.js} |  2 +-
 src/index.js                |  3 ++-
 src/routes/checkout.js      |  6 +++---
 src/routes/products.js      |  9 +++++----
 src/stats.js                |  8 ++++----
 test/cart.test.js           |  6 +++---
 test/discount.test.js       | 11 +++++++++++
 14 files changed, 62 insertions(+), 44 deletions(-)
```

Quote the pathspec, or your shell will try to expand the `!`. If you prefer the explicit form, `':(exclude)package-lock.json'` does the same thing.

You can stack several exclusions at once:

```bash
git diff --stat -- . ':!package-lock.json' ':!*.md'
```

A glob limits the diff to one kind of file:

```bash
git diff --stat -- '*.js'
```

```text
 src/api.js                  | 24 ++++++++++++------------
 src/cart.js                 | 15 +++------------
 src/config.js               |  2 +-
 src/discount.js             |  9 +++++++++
 src/{utils.js => format.js} |  2 +-
 src/index.js                |  3 ++-
 src/routes/checkout.js      |  6 +++---
 src/routes/products.js      |  9 +++++----
 src/stats.js                |  8 ++++----
 test/cart.test.js           |  6 +++---
 test/discount.test.js       | 11 +++++++++++
 11 files changed, 54 insertions(+), 41 deletions(-)
```

And a directory path limits it to that folder:

```bash
git diff --stat -- src/routes
```

```text
 src/routes/checkout.js | 6 +++---
 src/routes/products.js | 9 +++++----
 2 files changed, 8 insertions(+), 7 deletions(-)
```

The `package.json` diff is only 4 lines, so we can read that directly to see which versions changed. The lockfile follows from it.

## Hide whitespace with -w

`src/api.js` has 24 changed lines. Here's the start of it:

```bash
git diff src/api.js
```

```diff
-    api.post('/cart/summary', (req, res) => {
-        const { items, code } = req.body
-        if (!Array.isArray(items)) {
-            return res.status(400).json({ error: 'items must be an array' })
-        }
-        res.json(cartSummary(items, code))
-    })
+  api.post('/cart/summary', (req, res) => {
+    const { items, code } = req.body
+    if (!Array.isArray(items)) {
+      return res.status(422).json({ error: 'items must be an array' })
+    }
+    res.json(cartSummary(items, code))
+  })
```

It looks like a reindent from 4 spaces to 2. Is there anything else hiding in there?

Let's add `-w` (`--ignore-all-space`) to ignore whitespace when comparing lines:

```bash
git diff -w src/api.js
```

```diff
diff --git a/src/api.js b/src/api.js
index 07f05b9..7031e39 100644
--- a/src/api.js
+++ b/src/api.js
@@ -7,7 +7,7 @@ export function createApi() {
   api.post('/cart/summary', (req, res) => {
     const { items, code } = req.body
     if (!Array.isArray(items)) {
-            return res.status(400).json({ error: 'items must be an array' })
+      return res.status(422).json({ error: 'items must be an array' })
     }
     res.json(cartSummary(items, code))
   })
```

The agent changed the status code from 400 to 422 right inside the reindent. That's an API change clients might depend on, buried in 24 lines of formatting.

`-w` also works with `--stat`, so we can see which files are formatting only:

```bash
git diff -w --stat -- src
```

```text
 src/api.js                  |  2 +-
 src/cart.js                 | 15 +++------------
 src/config.js               |  2 +-
 src/discount.js             |  9 +++++++++
 src/{utils.js => format.js} |  2 +-
 src/index.js                |  1 +
 src/routes/checkout.js      |  2 +-
 src/routes/products.js      |  1 +
 src/stats.js                |  8 ++++----
 9 files changed, 22 insertions(+), 20 deletions(-)
```

`src/routes/products.js` dropped from 9 lines to 1, and that single line is an extra blank line:

```diff
@@ -4,6 +4,7 @@ const products = [
   { id: 3, name: 'Backpack', price: 4900 }
 ]
 
+
 export function productList(req, res) {
   res.json(products)
 }
```

`--ignore-blank-lines` hides hunks made only of blank lines. Combined with `-w`, the file disappears from the stat:

```bash
git diff -w --ignore-blank-lines --stat -- src/routes
```

```text
 src/routes/checkout.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
```

It only hides a hunk when every changed line in it is blank. A blank line next to a real change stays visible.

> Treat `-w` as a reading aid. Don't stage or commit from a `-w` view without checking the full diff too, because whitespace matters in Python, YAML and Makefiles.

## Find small edits with --word-diff and --color-words

A one-word change inside a long line is easy to miss because Git prints the whole line twice. `--word-diff` shows the changed words inline, using `[-removed-]` and `{+added+}` markers:

```bash
git diff --word-diff README.md
```

```text
Discount codes are [-checked-]{+validated+} on the server, and the cart total is always calculated in cents to avoid rounding errors.
```

It works on code too. Here the agent changed the tax rate, which is easy to miss in a line-based diff:

```bash
git diff --word-diff src/config.js
```

```text
@@ -1,3 +1,3 @@
export const TAX_RATE = [-0.22-]{+0.21+}
export const PORT = 3000
export const CURRENCY = 'EUR'
```

We never asked for a tax rate change, so it goes on our list of things to reject.

`--color-words` drops the bracket markers and highlights changes in red and green (it's a shorthand for `--word-diff=color`):

![Terminal output of git diff --color-words on README.md and src/config.js. In the README line, the removed word checked is red and the added word validated is green, right next to each other. In config.js, 0.22 is red and 0.21 is green on the TAX_RATE line](https://images.flaviocopes.com/git-diff-review/color-words.webp?v=a235d68e)

Git splits words on whitespace by default, so `0.22` and `0.21` show up as whole words. If you need finer splits, `--word-diff-regex` lets you define what counts as a word.

And if you're parsing output in a script, `--word-diff=porcelain` prints one token per line.

## Follow moved code with --color-moved

The agent moved `applyDiscount()` into its own file and changed one line along the way. In a normal diff, that looks like a wall of red in `src/cart.js` and a wall of green in `src/discount.js`, forcing you to compare them line by line.

`--color-moved` paints lines removed in one place and added in another with separate colors. With `dimmed-zebra`, untouched moved lines fade to gray so the real edits jump out:

```bash
git diff --color-moved=dimmed-zebra src/cart.js src/discount.js
```

![Terminal output of git diff with --color-moved=dimmed-zebra on src/cart.js and src/discount.js. The removed applyDiscount function in cart.js and the added copy in discount.js are mostly dimmed gray, while the return total - 500 line in red and the return Math.max(0, total - 500) line in green keep full color, along with the changed import lines and the shipping(discounted) to shipping(sub) change](https://images.flaviocopes.com/git-diff-review/color-moved.webp?v=1c3cf222)

The gray lines moved as is. Look at what stayed in full color:

- `return total - 500` became `return Math.max(0, total - 500)`, which is the fix we asked for.
- `shipping(discounted)` became `shipping(sub)`, which nobody asked for. Free shipping is now based on the subtotal before the discount.

You'll notice the last few lines of the function also kept their color. Move detection only triggers on blocks of at least 20 alphanumeric characters, and the `}` and `return total` lines after the edit are too short on their own.

Without a mode, `--color-moved` defaults to `zebra`, which alternates colors on moved blocks instead of dimming them. Setting `diff.colorMoved` in `~/.gitconfig` turns it on for every diff.

If a moved block was also reindented (say, a function moved inside an object), move detection misses it. Pass `--color-moved-ws=allow-indentation-change` to ignore indentation shifts when every line in the block moved by the same amount:

```bash
git diff --color-moved=dimmed-zebra --color-moved-ws=allow-indentation-change
```

## Rename detection with -M

Git doesn't store renames. Instead, it detects them by pairing a deleted file with an added file that shares similar content.

`git diff` enables this by default, so we already saw `src/{utils.js => format.js}` in the stat. `-M` (`--find-renames`) is the explicit flag, and `--no-renames` turns it off:

```bash
git diff --no-renames --stat -- src/utils.js src/format.js
```

```text
 src/format.js | 14 ++++++++++++++
 src/utils.js  | 14 --------------
 2 files changed, 14 insertions(+), 14 deletions(-)
```

With rename detection on, those 28 lines shrink to 2:

```bash
git diff -- src/utils.js src/format.js
```

```diff
diff --git a/src/utils.js b/src/format.js
similarity index 86%
rename from src/utils.js
rename to src/format.js
index ce4d3c1..f20b06a 100644
--- a/src/utils.js
+++ b/src/format.js
@@ -1,5 +1,5 @@
 export function formatPrice(cents, currency = 'EUR') {
-  return new Intl.NumberFormat('en-US', {
+  return new Intl.NumberFormat('it-IT', {
     style: 'currency',
     currency
   }).format(cents / 100)
```

The agent changed the price locale while renaming the file. That's another unrequested edit, and it's easy to miss when a rename appears as a 14-line deletion and a 14-line addition.

Notice that I passed both paths. If you put only `src/format.js` in the pathspec, Git can't see the deleted file to pair them up, so it prints a brand new file.

`-M` also accepts a similarity threshold (50% by default). With `-M100%`, Git only accepts exact renames, so this one falls apart:

```bash
git diff -M100% --stat -- src/utils.js src/format.js
```

```text
 src/format.js | 14 ++++++++++++++
 src/utils.js  | 14 --------------
 2 files changed, 14 insertions(+), 14 deletions(-)
```

## Better hunks with --diff-algorithm=histogram

In `src/stats.js`, the agent added a `weight()` function at the top and deleted the unused `revenue()` function. Here's what Git's default algorithm (Myers) produces:

```bash
git diff src/stats.js
```

```diff
@@ -1,15 +1,15 @@
-export function count(items) {
+export function weight(items) {
   let sum = 0
   for (const item of items) {
-    sum += item.quantity
+    sum += item.grams * item.quantity
   }
   return sum
 }
 
-export function revenue(items) {
+export function count(items) {
   let sum = 0
   for (const item of items) {
-    sum += item.price * item.quantity
+    sum += item.quantity
   }
   return sum
 }
```

That's the smallest possible diff, and it's misleading to read. Because the functions share most of their lines, it looks like `count()` was rewritten into `weight()` and `revenue()` into `count()`.

`--diff-algorithm=histogram` anchors on lines that appear less often, like function names:

```bash
git diff --diff-algorithm=histogram src/stats.js
```

```diff
@@ -1,3 +1,11 @@
+export function weight(items) {
+  let sum = 0
+  for (const item of items) {
+    sum += item.grams * item.quantity
+  }
+  return sum
+}
+
 export function count(items) {
   let sum = 0
   for (const item of items) {
@@ -5,11 +13,3 @@ export function count(items) {
   }
   return sum
 }
-
-export function revenue(items) {
-  let sum = 0
-  for (const item of items) {
-    sum += item.price * item.quantity
-  }
-  return sum
-}
```

Now the diff reflects what happened: one function added, one removed, and `count()` untouched. It has 16 lines instead of 8, and it's much easier to read.

`--diff-algorithm=patience` is the algorithm histogram extends, and on this file it gave the same output as Myers. I'd set histogram as my default, and remember `--histogram` and `--patience` work as short flags.

## More or less context with -U and --function-context

By default, Git shows 3 lines of context around each change, and `-U<n>` lets you adjust that number. Passing `-U0` prints only the changed lines, giving us a compact list of every edit:

```bash
git diff -U0 src/cart.js
```

```diff
@@ -1 +1,2 @@
-import { formatPrice } from './utils.js'
+import { formatPrice } from './format.js'
+import { applyDiscount } from './discount.js'
@@ -8,10 +8,0 @@ export function subtotal(items) {
-export function applyDiscount(total, code) {
-  if (code === 'WELCOME10') {
-    return total - total * 0.1
-  }
-  if (code === 'FLAT5') {
-    return total - 500
-  }
-  return total
-}
-
@@ -32 +23 @@ export function cartSummary(items, code) {
-    total: formatPrice(discounted + tax + shipping(discounted))
+    total: formatPrice(discounted + tax + shipping(sub))
```

To judge `shipping(sub)`, though, we need to know what `sub` and `discounted` are. `-W` (`--function-context`) expands the context to the whole enclosing function:

```bash
git diff -W src/cart.js
```

```diff
@@ -25,10 +16,10 @@ export function shipping(total) {
 export function cartSummary(items, code) {
   const sub = subtotal(items)
   const discounted = applyDiscount(sub, code)
   const tax = Math.round(discounted * TAX_RATE)
   return {
     subtotal: formatPrice(sub),
     tax: formatPrice(tax),
-    total: formatPrice(discounted + tax + shipping(discounted))
+    total: formatPrice(discounted + tax + shipping(sub))
   }
 }
```

Now the hunk makes sense on its own. `sub` is the total before the discount, so a cart that only reaches 50 euros before the discount now gets free shipping.

## Catch whitespace errors with --check

`--check` warns about trailing whitespace, space-before-tab indentation and leftover conflict markers. It also exits with a non-zero status when it finds a problem:

```bash
git diff --check
echo $?
```

```text
src/index.js:14: trailing whitespace.
+  console.log(`Shop running on http://localhost:${PORT}`) 
2
```

That exit code makes `--check` handy in a [Git hook](https://flaviocopes.com/git-hooks/), blocking an agent from committing bad lines. Here it also flagged a hunk we need to inspect: the agent added a `console.log` that prints the discount codes on startup.

## Accept hunks with git add -p, reject them with git restore -p

By now we know what to keep and what to throw away. Git can do that hunk by hunk, so we don't have to reject a whole file because of one bad line.

Git tracks changes across three places: the last commit, the index (staging area) and the working tree.

With no arguments, `git diff` compares the working tree with the index. `--staged` (a synonym of `--cached`) compares the index with the last commit:

```mermaid
flowchart LR
  accTitle: What each git diff command compares
  accDescr: git diff --staged compares the last commit with the index. git diff compares the index with the working tree. git diff HEAD compares the last commit with the working tree.
  H["HEAD<br/>last commit"] -->|"git diff --staged"| I["Index<br/>staging area"]
  I -->|"git diff"| W["Working tree<br/>the agent's files"]
  H -.->|"git diff HEAD"| W
```

`git add -p` shows each hunk in a file one by one and asks whether to stage it. In `src/cart.js`, we want the first hunk (the import changes and the moved function) and not the second (`shipping(sub)`):

```bash
git add -p src/cart.js
```

Git prints each hunk followed by a prompt:

```text
(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,s,e,p,?]?
```

Answer `y` to the first and `n` to the second. Use `s` to split a hunk into smaller pieces when changed lines aren't adjacent, or `e` to edit the hunk directly in your editor.

Now the file has both staged and unstaged changes, shown as `MM` in the short status:

```bash
git status -s src/cart.js
```

```text
MM src/cart.js
```

`git diff --staged` shows what we accepted:

```bash
git diff --staged --stat
```

```text
 src/cart.js | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
```

And `git diff` shows what's still left in the working tree:

```bash
git diff --stat src/cart.js
```

```text
 src/cart.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
```

`git restore -p` does the reverse. It prompts you for each unstaged hunk, and answering `y` discards that change from the working tree:

```bash
git restore -p src/cart.js
```

```text
@@ -20,6 +20,6 @@ export function cartSummary(items, code) {
   return {
     subtotal: formatPrice(sub),
     tax: formatPrice(tax),
-    total: formatPrice(discounted + tax + shipping(discounted))
+    total: formatPrice(discounted + tax + shipping(sub))
   }
 }
(1/1) Discard this hunk from worktree [y,n,q,a,d,e,p,?]?
```

Be sure to stage what you want to keep before you restore. Discarding an uncommitted hunk can't be undone.

We do the same for the `console.log` in `src/index.js`, switch the locale back to `en-US`, remove the changelog line about shipping, and stage the rest. Before committing, let's run our checks on the staged diff:

```bash
git diff --staged --check
git diff --staged --shortstat
```

```text
 14 files changed, 167 insertions(+), 131 deletions(-)
```

No whitespace errors, 14 files staged, and the tests pass with `node --test`, so we're ready to commit.

You can also send the rejected hunks back to the agent by pasting the remaining `git diff` output straight into the chat. Asking it to "revert these hunks and explain why you changed them" works far better than describing the lines in words.

## Compare branches with three dots, not two

Once the agent's work is committed on its branch, you review it against `main`. In the meantime someone added `docs/deploy.md` on `main`:

```text
* 849e61a Move applyDiscount to its own file and cap FLAT5 at zero
| * 7eebcab Document deploys
|/  
* 6c4b3a0 Add formatPercent helper
* c2c5097 Initial shop
```

With two dots, `git diff main..agent/discount-cap` compares the two branch tips (the same as `git diff main agent/discount-cap`). With three dots, `git diff main...agent/discount-cap` compares the merge base (where the branch started) with the branch tip:

```mermaid steps
flowchart LR
  accTitle: Two dots compare the two branch tips
  accDescr: git diff main..agent compares commit 7eebcab at the tip of main with commit 849e61a at the tip of the agent branch, so the commit added on main shows up reversed.
  A["c2c5097"] --> B["6c4b3a0"]
  B --> M["7eebcab<br/>main"]
  B --> G["849e61a<br/>agent/discount-cap"]
  M <-.->|"main..agent compares these"| G
  style M stroke-width:3px
  style G stroke-width:3px
%% step
flowchart LR
  accTitle: Three dots compare the merge base with the branch
  accDescr: git diff main...agent compares commit 6c4b3a0, where the agent branch started, with 849e61a at the tip of the agent branch, so only the agent's work shows up.
  A["c2c5097"] --> B["6c4b3a0<br/>merge base"]
  B --> M["7eebcab<br/>main"]
  B --> G["849e61a<br/>agent/discount-cap"]
  B -.->|"main...agent compares these"| G
  style B stroke-width:3px
  style G stroke-width:3px
```

Let's compare both on the `docs` folder. First, with two dots:

```bash
git diff --stat main..agent/discount-cap -- docs
```

```text
 docs/CHANGELOG.md | 4 ++++
 docs/deploy.md    | 3 ---
 2 files changed, 4 insertions(+), 3 deletions(-)
```

Now with three dots:

```bash
git diff --stat main...agent/discount-cap -- docs
```

```text
 docs/CHANGELOG.md | 4 ++++
 1 file changed, 4 insertions(+)
```

The two-dot version makes it look like the agent deleted `docs/deploy.md`, even though it never touched it. That file was added on `main` after the branch started, so the two-dot diff shows that commit in reverse.

On a busy `main` branch, that mixes a lot of unrelated noise into your review.

Three dots show only what the branch changed, matching what you'd see in a pull request. `git merge-base` prints the starting commit:

```bash
git merge-base main agent/discount-cap
```

```text
6c4b3a064e42a4f077af7c2fa403e836af76dad0
```

If you leave out the second branch name, Git defaults to `HEAD`, so `git diff main...` works directly from the agent's branch.

Keep in mind that `git log` flips the dot syntax. `git log main..agent/discount-cap` lists the commits on the branch that aren't on `main`, which is what we want there:

```bash
git log --oneline main..agent/discount-cap
```

```text
849e61a Move applyDiscount to its own file and cap FLAT5 at zero
```

For more on how branches come together after the review, check out [rebase vs merge](https://flaviocopes.com/git-rebase-vs-merge/).

## See a file's history with git log -p --follow

Sometimes a diff only makes sense once you see the history behind it. `git log` stops at a rename by default, so looking up `src/format.js` only returns one commit:

```bash
git log --oneline -- src/format.js
```

```text
849e61a Move applyDiscount to its own file and cap FLAT5 at zero
```

`--follow` traces history across the rename, back to when the file was `src/utils.js`:

```bash
git log --oneline --follow -- src/format.js
```

```text
849e61a Move applyDiscount to its own file and cap FLAT5 at zero
6c4b3a0 Add formatPercent helper
c2c5097 Initial shop
```

Add `-p` to include the patch for each commit. Among them, we get the commit from when the file was still `src/utils.js`:

```bash
git log -p --follow -- src/format.js
```

```diff
diff --git a/src/utils.js b/src/utils.js
index 601fd09..ce4d3c1 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -8,3 +8,7 @@ export function formatPrice(cents, currency = 'EUR') {
 export function formatQuantity(n) {
   return n === 1 ? '1 item' : `${n} items`
 }
+
+export function formatPercent(rate) {
+  return `${Math.round(rate * 100)}%`
+}
```

`--follow` only works on a single file at a time.

## Use delta as your pager

Everything we've run so far works with plain Git, though a dedicated diff pager makes long reviews much easier on the eyes. [delta](https://github.com/dandavison/delta) adds syntax highlighting, line numbers and word-level highlights inside changed lines.

On macOS, we can install it with Homebrew:

```bash
brew install git-delta
```

Then configure Git to use it in `~/.gitconfig`:

```ini
[core]
  pager = delta

[interactive]
  diffFilter = delta --color-only

[delta]
  navigate = true
  line-numbers = true
```

`interactive.diffFilter` brings delta's colors to `git add -p` and `git restore -p` as well. We pass `--color-only` there because interactive commands need the underlying diff structure untouched.

Turning on `navigate` lets you jump between files with `n` and `N` inside the pager.

Here are the rename and the tax rate change rendered through delta. The changed part of each line gets a brighter highlight, so `en-US` to `it-IT` jumps right out:

![delta output for src/config.js and the renamed src/format.js. Each file has a blue header, the rename is shown as renamed: src/utils.js to src/format.js, lines have old and new line numbers, and inside the changed lines only 22 versus 21 and en-US versus it-IT have a brighter red and green background](https://images.flaviocopes.com/git-diff-review/delta.webp?v=b8ce28d2)

`delta --side-by-side` (or `side-by-side = true` in the `[delta]` section) places the old and new versions next to each other, though it needs a wide terminal:

![delta side-by-side view of src/cart.js. The old file is on the left with the applyDiscount function highlighted in red, the new file is on the right with an empty gap where the function was, and at the bottom shipping(discounted) on the left and shipping(sub) on the right have the changed word highlighted](https://images.flaviocopes.com/git-diff-review/delta-side-by-side.webp?v=2966d3a6)

You can also pipe a single diff into delta without touching your config:

```bash
git diff src/cart.js | delta --side-by-side
```

If you prefer something closer to plain Git output, [diff-so-fancy](https://github.com/so-fancy/diff-so-fancy) is the main alternative. It highlights changed words without adding syntax colors or line numbers, and you wire it up in `core.pager` the same way.

## Quick reference on the example branch

Here's a quick recap of what each option showed us on `agent/discount-cap`:

| Command | What it strips or highlights | What we saw on this branch |
| --- | --- | --- |
| `git diff --stat` | File-level summary of everything | 15 files, 306 changed lines (200 in `package-lock.json`) |
| `git diff --stat -- . ':!package-lock.json'` | Excludes the lockfile | 14 files, 62 insertions, 44 deletions |
| `git diff -w src/api.js` | Ignores indentation and whitespace | 24 changed lines dropped to 1 real status change (`400` to `422`) |
| `git diff --color-words` | Highlights changed tokens inline | Caught `0.22` to `0.21` in `TAX_RATE` and `checked` to `validated` |
| `git diff --color-moved=dimmed-zebra` | Dims untouched moved lines | Exposed `Math.max(0, total - 500)` and `shipping(sub)` inside the move |
| `git diff --compact-summary main...HEAD` | Only commits on this branch since the merge base | 13 files changed, 61 insertions, 45 deletions (skips other `main` commits) |

## Aliases and defaults in ~/.gitconfig

Once you know which options you reach for on every agent review, save them in `~/.gitconfig` so you don't have to retype them:

```ini
[alias]
  st = status -sb
  overview = diff --compact-summary main...HEAD -- . ':!package-lock.json'
  ws = diff -w --ignore-blank-lines
  wd = diff --color-words

[diff]
  algorithm = histogram
  colorMoved = dimmed-zebra
  colorMovedWS = allow-indentation-change
```

Running `git overview` from the agent's branch gives us the whole branch at a glance, minus the lockfile:

```bash
git overview
```

```text
 README.md                   |  2 +-
 docs/CHANGELOG.md           |  4 ++++
 package.json                |  4 ++--
 src/api.js                  | 24 ++++++++++++------------
 src/cart.js                 | 13 ++-----------
 src/config.js               |  2 +-
 src/discount.js (new)       |  9 +++++++++
 src/{utils.js => format.js} |  0
 src/routes/checkout.js      |  6 +++---
 src/routes/products.js      |  9 +++++----
 src/stats.js                | 16 ++++++++--------
 test/cart.test.js           |  6 +++---
 test/discount.test.js (new) | 11 +++++++++++
 13 files changed, 61 insertions(+), 45 deletions(-)
```

`src/{utils.js => format.js} | 0` confirms the rename now carries no content change since we reverted the locale. And `src/stats.js` shows 16 lines instead of 8 because `diff.algorithm = histogram` applies to `--stat` too.

Notice that `overview` hardcodes `main`. If some of your repositories use `master`, turn it into a shell alias that takes the branch name as an argument, or define one alias per branch name.

`git ws` and `git wd` accept the same arguments as `git diff`, so `git ws main...` and `git wd README.md` work just as you'd expect.

If you're new to branches, staging and commits, the free [Git handbook](https://flaviocopes.com/ebooks/git-cheat-sheet/) covers the basics this post builds on. When several agents work at once, [Parallel coding agents](https://flaviocopes.com/parallel-agents/) shows how to keep their changes apart, and [the pull request workflow](https://flaviocopes.com/pull-requests-agent-review/) covers what happens after this terminal pass.
