{"slug": "review-an-agent-s-diff-in-the-terminal-with-git-diff", "title": "Review an agent's diff in the terminal with git diff", "summary": "A terminal-focused guide by Flavio shows how to review a coding agent's changes with git diff options, using a real throwaway Express shop repository where the agent on branch agent/discount-cap changed 15 files, including 151 insertions and 147 deletions across 13 tracked files. The guide recommends starting with git status -sb to catch untracked files that git diff omits, then using git add -N on the three new files (src/discount.js, src/format.js, test/discount.test.js) so they appear in the diff and the src/utils.js to src/format.js rename is detected. It warns that git add -N . also stages deletions, which made the rename disappear from git diff.", "body_md": "# Review an agent's diff in the terminal with git diff\n\nBy [Flavio](https://flaviocopes.com/about/)\n\nThe 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.\n\nA coding agent finishes a task and tells you it changed 15 files. Before you accept anything, you want to know what it really did.\n\nPlain `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.\n\nIn 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.\n\n## The example change\n\nThe project is a tiny Express shop with a cart, a discount function, a few routes and tests.\n\nThe 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:\n\n- moved `applyDiscount()` from`src/cart.js` to a new`src/discount.js`\n- renamed `src/utils.js` to`src/format.js`\n- reindented `src/api.js` and the routes from 4 spaces to 2\n- bumped Express, which rewrote `package-lock.json`\n- touched a few other things it wasn’t asked to touch\n\nThat 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.\n\nIf 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.\n\nHere’s the order we’ll follow:\n\n## Start with git status -sb\n\nLet’s start with `git status -sb`. It gives us the short format plus the branch line, one line per file:\n\n```\ngit status -sb\n## agent/discount-cap\n M README.md\n M docs/CHANGELOG.md\n M package-lock.json\n M package.json\n M src/api.js\n M src/cart.js\n M src/config.js\n M src/index.js\n M src/routes/checkout.js\n M src/routes/products.js\n M src/stats.js\n D src/utils.js\n M test/cart.test.js\n?? src/discount.js\n?? src/format.js\n?? test/discount.test.js\n```\n\nNotice 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:\n\n```\ngit diff --stat\nREADME.md              |   2 +-\n docs/CHANGELOG.md      |   5 ++\n package-lock.json      | 200 +++++++++++++++++++++++++----------------------\n package.json           |   4 +-\n src/api.js             |  24 +++---\n src/cart.js            |  15 +---\n src/config.js          |   2 +-\n src/index.js           |   3 +-\n src/routes/checkout.js |   6 +-\n src/routes/products.js |   9 ++-\n src/stats.js           |   8 +-\n src/utils.js           |  14 ----\n test/cart.test.js      |   6 +-\n 13 files changed, 151 insertions(+), 147 deletions(-)\n```\n\n`src/discount.js` is missing, and `src/utils.js` looks deleted.\n\nThe 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:\n\n```\ngit add -N src/discount.js src/format.js test/discount.test.js\n```\n\nNow `git status` also detects the rename:\n\n```\n## agent/discount-cap\n M README.md\n M docs/CHANGELOG.md\n M package-lock.json\n M package.json\n M src/api.js\n M src/cart.js\n M src/config.js\n A src/discount.js\n R src/utils.js -> src/format.js\n M src/index.js\n M src/routes/checkout.js\n M src/routes/products.js\n M src/stats.js\n M test/cart.test.js\n A test/discount.test.js\n```\n\nBe 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.\n\n## Get the shape with —stat and friends\n\n`--stat` gives us the table of contents of a diff. With the new files included, we get:\n\n```\ngit diff --stat\nREADME.md                   |   2 +-\n docs/CHANGELOG.md           |   5 ++\n package-lock.json           | 200 ++++++++++++++++++++++++--------------------\n package.json                |   4 +-\n src/api.js                  |  24 +++---\n src/cart.js                 |  15 +---\n src/config.js               |   2 +-\n src/discount.js             |   9 ++\n src/{utils.js => format.js} |   2 +-\n src/index.js                |   3 +-\n src/routes/checkout.js      |   6 +-\n src/routes/products.js      |   9 +-\n src/stats.js                |   8 +-\n test/cart.test.js           |   6 +-\n test/discount.test.js       |  11 +++\n 15 files changed, 172 insertions(+), 134 deletions(-)\n```\n\n`--compact-summary` prints the same table with `(new)` and `(gone)` markers, making created files easy to spot:\n\n```\ngit diff --compact-summary\nREADME.md                   |   2 +-\n docs/CHANGELOG.md           |   5 ++\n package-lock.json           | 200 ++++++++++++++++++++++++--------------------\n package.json                |   4 +-\n src/api.js                  |  24 +++---\n src/cart.js                 |  15 +---\n src/config.js               |   2 +-\n src/discount.js (new)       |   9 ++\n src/{utils.js => format.js} |   2 +-\n src/index.js                |   3 +-\n src/routes/checkout.js      |   6 +-\n src/routes/products.js      |   9 +-\n src/stats.js                |   8 +-\n test/cart.test.js           |   6 +-\n test/discount.test.js (new) |  11 +++\n 15 files changed, 172 insertions(+), 134 deletions(-)\n```\n\nWhen we only want the totals, `--shortstat` keeps it to one line:\n\n```\ngit diff --shortstat\n15 files changed, 172 insertions(+), 134 deletions(-)\n```\n\n`--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:\n\n```\ngit diff --name-status\nM\tREADME.md\nM\tdocs/CHANGELOG.md\nM\tpackage-lock.json\nM\tpackage.json\nM\tsrc/api.js\nM\tsrc/cart.js\nM\tsrc/config.js\nA\tsrc/discount.js\nR086\tsrc/utils.js\tsrc/format.js\nM\tsrc/index.js\nM\tsrc/routes/checkout.js\nM\tsrc/routes/products.js\nM\tsrc/stats.js\nM\ttest/cart.test.js\nA\ttest/discount.test.js\n```\n\n`R086` means Git considers `src/format.js` 86% similar to `src/utils.js`. Use `--name-only` when you only want the file paths.\n\n`--dirstat` shows where the change is concentrated, directory by directory:\n\n```\ngit diff --dirstat\n5.2% src/routes/\n  15.5% src/\n   5.1% test/\n```\n\nBy 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.\n\nWith `--dirstat=files,cumulative`, we count files instead and roll subdirectories into their parent:\n\n```\ngit diff --dirstat=files,cumulative\n6.6% docs/\n  13.3% src/routes/\n  60.0% src/\n  13.3% test/\n```\n\n## Cut the noise with pathspecs\n\nEverything after `--` is a **pathspec**, a filter that controls which files the diff covers.\n\nA pathspec starting with `:!` excludes files. Here the lockfile is 200 of the 306 changed lines, so let’s drop it first:\n\n```\ngit diff --stat -- . ':!package-lock.json'\nREADME.md                   |  2 +-\n docs/CHANGELOG.md           |  5 +++++\n package.json                |  4 ++--\n src/api.js                  | 24 ++++++++++++------------\n src/cart.js                 | 15 +++------------\n src/config.js               |  2 +-\n src/discount.js             |  9 +++++++++\n src/{utils.js => format.js} |  2 +-\n src/index.js                |  3 ++-\n src/routes/checkout.js      |  6 +++---\n src/routes/products.js      |  9 +++++----\n src/stats.js                |  8 ++++----\n test/cart.test.js           |  6 +++---\n test/discount.test.js       | 11 +++++++++++\n 14 files changed, 62 insertions(+), 44 deletions(-)\n```\n\nQuote the pathspec, or your shell will try to expand the `!`. If you prefer the explicit form, `':(exclude)package-lock.json'` does the same thing.\n\nYou can stack several exclusions at once:\n\n```\ngit diff --stat -- . ':!package-lock.json' ':!*.md'\n```\n\nA glob limits the diff to one kind of file:\n\n```\ngit diff --stat -- '*.js'\nsrc/api.js                  | 24 ++++++++++++------------\n src/cart.js                 | 15 +++------------\n src/config.js               |  2 +-\n src/discount.js             |  9 +++++++++\n src/{utils.js => format.js} |  2 +-\n src/index.js                |  3 ++-\n src/routes/checkout.js      |  6 +++---\n src/routes/products.js      |  9 +++++----\n src/stats.js                |  8 ++++----\n test/cart.test.js           |  6 +++---\n test/discount.test.js       | 11 +++++++++++\n 11 files changed, 54 insertions(+), 41 deletions(-)\n```\n\nAnd a directory path limits it to that folder:\n\n```\ngit diff --stat -- src/routes\nsrc/routes/checkout.js | 6 +++---\n src/routes/products.js | 9 +++++----\n 2 files changed, 8 insertions(+), 7 deletions(-)\n```\n\nThe `package.json` diff is only 4 lines, so we can read that directly to see which versions changed. The lockfile follows from it.\n\n## Hide whitespace with -w\n\n`src/api.js` has 24 changed lines. Here’s the start of it:\n\n```\ngit diff src/api.js\njs\n-    api.post('/cart/summary', (req, res) => {\n-        const { items, code } = req.body\n-        if (!Array.isArray(items)) {\n-            return res.status(400).json({ error: 'items must be an array' })\n-        }\n-        res.json(cartSummary(items, code))\n-    })\n+  api.post('/cart/summary', (req, res) => {\n+    const { items, code } = req.body\n+    if (!Array.isArray(items)) {\n+      return res.status(422).json({ error: 'items must be an array' })\n+    }\n+    res.json(cartSummary(items, code))\n+  })\n```\n\nIt looks like a reindent from 4 spaces to 2. Is there anything else hiding in there?\n\nLet’s add `-w` (`--ignore-all-space`) to ignore whitespace when comparing lines:\n\n```\ngit diff -w src/api.js\ndiff --git a/src/api.js b/src/api.js\nindex 07f05b9..7031e39 100644\n--- a/src/api.js\n+++ b/src/api.js\n@@ -7,7 +7,7 @@ export function createApi() {\n   api.post('/cart/summary', (req, res) => {\n     const { items, code } = req.body\n     if (!Array.isArray(items)) {\n-            return res.status(400).json({ error: 'items must be an array' })\n+      return res.status(422).json({ error: 'items must be an array' })\n     }\n     res.json(cartSummary(items, code))\n   })\n```\n\nThe 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.\n\n`-w` also works with `--stat`, so we can see which files are formatting only:\n\n```\ngit diff -w --stat -- src\nsrc/api.js                  |  2 +-\n src/cart.js                 | 15 +++------------\n src/config.js               |  2 +-\n src/discount.js             |  9 +++++++++\n src/{utils.js => format.js} |  2 +-\n src/index.js                |  1 +\n src/routes/checkout.js      |  2 +-\n src/routes/products.js      |  1 +\n src/stats.js                |  8 ++++----\n 9 files changed, 22 insertions(+), 20 deletions(-)\n```\n\n`src/routes/products.js` dropped from 9 lines to 1, and that single line is an extra blank line:\n\n``` js\n@@ -4,6 +4,7 @@ const products = [\n   { id: 3, name: 'Backpack', price: 4900 }\n ]\n \n+\n export function productList(req, res) {\n   res.json(products)\n }\n```\n\n`--ignore-blank-lines` hides hunks made only of blank lines. Combined with `-w`, the file disappears from the stat:\n\n```\ngit diff -w --ignore-blank-lines --stat -- src/routes\nsrc/routes/checkout.js | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n```\n\nIt only hides a hunk when every changed line in it is blank. A blank line next to a real change stays visible.\n\nTreat `-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.\n\n## Find small edits with —word-diff and —color-words\n\nA 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:\n\n```\ngit diff --word-diff README.md\nDiscount codes are [-checked-]{+validated+} on the server, and the cart total is always calculated in cents to avoid rounding errors.\n```\n\nIt works on code too. Here the agent changed the tax rate, which is easy to miss in a line-based diff:\n\n```\ngit diff --word-diff src/config.js\njs\n@@ -1,3 +1,3 @@\nexport const TAX_RATE = [-0.22-]{+0.21+}\nexport const PORT = 3000\nexport const CURRENCY = 'EUR'\n```\n\nWe never asked for a tax rate change, so it goes on our list of things to reject.\n\n`--color-words` drops the bracket markers and highlights changes in red and green (it’s a shorthand for `--word-diff=color`):\n\nGit 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.\n\nAnd if you’re parsing output in a script, `--word-diff=porcelain` prints one token per line.\n\n## Follow moved code with —color-moved\n\nThe 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.\n\n`--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:\n\n```\ngit diff --color-moved=dimmed-zebra src/cart.js src/discount.js\n```\n\nThe gray lines moved as is. Look at what stayed in full color:\n\n- `return total - 500` became`return Math.max(0, total - 500)` , which is the fix we asked for.\n- `shipping(discounted)` became`shipping(sub)` , which nobody asked for. Free shipping is now based on the subtotal before the discount.\n\nYou’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.\n\nWithout 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.\n\nIf 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:\n\n```\ngit diff --color-moved=dimmed-zebra --color-moved-ws=allow-indentation-change\n```\n\n## Rename detection with -M\n\nGit doesn’t store renames. Instead, it detects them by pairing a deleted file with an added file that shares similar content.\n\n`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:\n\n```\ngit diff --no-renames --stat -- src/utils.js src/format.js\nsrc/format.js | 14 ++++++++++++++\n src/utils.js  | 14 --------------\n 2 files changed, 14 insertions(+), 14 deletions(-)\n```\n\nWith rename detection on, those 28 lines shrink to 2:\n\n```\ngit diff -- src/utils.js src/format.js\ndiff --git a/src/utils.js b/src/format.js\nsimilarity index 86%\nrename from src/utils.js\nrename to src/format.js\nindex ce4d3c1..f20b06a 100644\n--- a/src/utils.js\n+++ b/src/format.js\n@@ -1,5 +1,5 @@\n export function formatPrice(cents, currency = 'EUR') {\n-  return new Intl.NumberFormat('en-US', {\n+  return new Intl.NumberFormat('it-IT', {\n     style: 'currency',\n     currency\n   }).format(cents / 100)\n```\n\nThe 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.\n\nNotice 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.\n\n`-M` also accepts a similarity threshold (50% by default). With `-M100%`, Git only accepts exact renames, so this one falls apart:\n\n```\ngit diff -M100% --stat -- src/utils.js src/format.js\nsrc/format.js | 14 ++++++++++++++\n src/utils.js  | 14 --------------\n 2 files changed, 14 insertions(+), 14 deletions(-)\n```\n\n## Better hunks with —diff-algorithm=histogram\n\nIn `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:\n\n```\ngit diff src/stats.js\n@@ -1,15 +1,15 @@\n-export function count(items) {\n+export function weight(items) {\n   let sum = 0\n   for (const item of items) {\n-    sum += item.quantity\n+    sum += item.grams * item.quantity\n   }\n   return sum\n }\n \n-export function revenue(items) {\n+export function count(items) {\n   let sum = 0\n   for (const item of items) {\n-    sum += item.price * item.quantity\n+    sum += item.quantity\n   }\n   return sum\n }\n```\n\nThat’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()`.\n\n`--diff-algorithm=histogram` anchors on lines that appear less often, like function names:\n\n```\ngit diff --diff-algorithm=histogram src/stats.js\njs\n@@ -1,3 +1,11 @@\n+export function weight(items) {\n+  let sum = 0\n+  for (const item of items) {\n+    sum += item.grams * item.quantity\n+  }\n+  return sum\n+}\n+\n export function count(items) {\n   let sum = 0\n   for (const item of items) {\n@@ -5,11 +13,3 @@ export function count(items) {\n   }\n   return sum\n }\n-\n-export function revenue(items) {\n-  let sum = 0\n-  for (const item of items) {\n-    sum += item.price * item.quantity\n-  }\n-  return sum\n-}\n```\n\nNow 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.\n\n`--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.\n\n## More or less context with -U and —function-context\n\nBy 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:\n\n```\ngit diff -U0 src/cart.js\njs\n@@ -1 +1,2 @@\n-import { formatPrice } from './utils.js'\n+import { formatPrice } from './format.js'\n+import { applyDiscount } from './discount.js'\n@@ -8,10 +8,0 @@ export function subtotal(items) {\n-export function applyDiscount(total, code) {\n-  if (code === 'WELCOME10') {\n-    return total - total * 0.1\n-  }\n-  if (code === 'FLAT5') {\n-    return total - 500\n-  }\n-  return total\n-}\n-\n@@ -32 +23 @@ export function cartSummary(items, code) {\n-    total: formatPrice(discounted + tax + shipping(discounted))\n+    total: formatPrice(discounted + tax + shipping(sub))\n```\n\nTo judge `shipping(sub)`, though, we need to know what `sub` and `discounted` are. `-W` (`--function-context`) expands the context to the whole enclosing function:\n\n```\ngit diff -W src/cart.js\n@@ -25,10 +16,10 @@ export function shipping(total) {\n export function cartSummary(items, code) {\n   const sub = subtotal(items)\n   const discounted = applyDiscount(sub, code)\n   const tax = Math.round(discounted * TAX_RATE)\n   return {\n     subtotal: formatPrice(sub),\n     tax: formatPrice(tax),\n-    total: formatPrice(discounted + tax + shipping(discounted))\n+    total: formatPrice(discounted + tax + shipping(sub))\n   }\n }\n```\n\nNow 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.\n\n## Catch whitespace errors with —check\n\n`--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:\n\n```\ngit diff --check\necho $?\nsrc/index.js:14: trailing whitespace.\n+  console.log(`Shop running on http://localhost:${PORT}`) \n2\n```\n\nThat 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.\n\n## Accept hunks with git add -p, reject them with git restore -p\n\nBy 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.\n\nGit tracks changes across three places: the last commit, the index (staging area) and the working tree.\n\nWith no arguments, `git diff` compares the working tree with the index. `--staged` (a synonym of `--cached`) compares the index with the last commit:\n\n`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)`):\n\n```\ngit add -p src/cart.js\n```\n\nGit prints each hunk followed by a prompt:\n\n```\n(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,s,e,p,?]?\n```\n\nAnswer `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.\n\nNow the file has both staged and unstaged changes, shown as `MM` in the short status:\n\n```\ngit status -s src/cart.js\nMM src/cart.js\n```\n\n`git diff --staged` shows what we accepted:\n\n```\ngit diff --staged --stat\nsrc/cart.js | 13 ++-----------\n 1 file changed, 2 insertions(+), 11 deletions(-)\n```\n\nAnd `git diff` shows what’s still left in the working tree:\n\n```\ngit diff --stat src/cart.js\nsrc/cart.js | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n```\n\n`git restore -p` does the reverse. It prompts you for each unstaged hunk, and answering `y` discards that change from the working tree:\n\n```\ngit restore -p src/cart.js\n@@ -20,6 +20,6 @@ export function cartSummary(items, code) {\n   return {\n     subtotal: formatPrice(sub),\n     tax: formatPrice(tax),\n-    total: formatPrice(discounted + tax + shipping(discounted))\n+    total: formatPrice(discounted + tax + shipping(sub))\n   }\n }\n(1/1) Discard this hunk from worktree [y,n,q,a,d,e,p,?]?\n```\n\nBe sure to stage what you want to keep before you restore. Discarding an uncommitted hunk can’t be undone.\n\nWe 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:\n\n```\ngit diff --staged --check\ngit diff --staged --shortstat\n14 files changed, 167 insertions(+), 131 deletions(-)\n```\n\nNo whitespace errors, 14 files staged, and the tests pass with `node --test`, so we’re ready to commit.\n\nYou 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.\n\n## Compare branches with three dots, not two\n\nOnce the agent’s work is committed on its branch, you review it against `main`. In the meantime someone added `docs/deploy.md` on `main`:\n\n```\n* 849e61a Move applyDiscount to its own file and cap FLAT5 at zero\n| * 7eebcab Document deploys\n|/  \n* 6c4b3a0 Add formatPercent helper\n* c2c5097 Initial shop\n```\n\nWith 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:\n\nLet’s compare both on the `docs` folder. First, with two dots:\n\n```\ngit diff --stat main..agent/discount-cap -- docs\ndocs/CHANGELOG.md | 4 ++++\n docs/deploy.md    | 3 ---\n 2 files changed, 4 insertions(+), 3 deletions(-)\n```\n\nNow with three dots:\n\n```\ngit diff --stat main...agent/discount-cap -- docs\ndocs/CHANGELOG.md | 4 ++++\n 1 file changed, 4 insertions(+)\n```\n\nThe 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.\n\nOn a busy `main` branch, that mixes a lot of unrelated noise into your review.\n\nThree dots show only what the branch changed, matching what you’d see in a pull request. `git merge-base` prints the starting commit:\n\n```\ngit merge-base main agent/discount-cap\n6c4b3a064e42a4f077af7c2fa403e836af76dad0\n```\n\nIf you leave out the second branch name, Git defaults to `HEAD`, so `git diff main...` works directly from the agent’s branch.\n\nKeep 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:\n\n```\ngit log --oneline main..agent/discount-cap\n849e61a Move applyDiscount to its own file and cap FLAT5 at zero\n```\n\nFor more on how branches come together after the review, check out [rebase vs merge](https://flaviocopes.com/git-rebase-vs-merge/).\n\n## See a file’s history with git log -p —follow\n\nSometimes 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:\n\n```\ngit log --oneline -- src/format.js\n849e61a Move applyDiscount to its own file and cap FLAT5 at zero\n```\n\n`--follow` traces history across the rename, back to when the file was `src/utils.js`:\n\n```\ngit log --oneline --follow -- src/format.js\n849e61a Move applyDiscount to its own file and cap FLAT5 at zero\n6c4b3a0 Add formatPercent helper\nc2c5097 Initial shop\n```\n\nAdd `-p` to include the patch for each commit. Among them, we get the commit from when the file was still `src/utils.js`:\n\n```\ngit log -p --follow -- src/format.js\ndiff --git a/src/utils.js b/src/utils.js\nindex 601fd09..ce4d3c1 100644\n--- a/src/utils.js\n+++ b/src/utils.js\n@@ -8,3 +8,7 @@ export function formatPrice(cents, currency = 'EUR') {\n export function formatQuantity(n) {\n   return n === 1 ? '1 item' : `${n} items`\n }\n+\n+export function formatPercent(rate) {\n+  return `${Math.round(rate * 100)}%`\n+}\n```\n\n`--follow` only works on a single file at a time.\n\n## Use delta as your pager\n\nEverything 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.\n\nOn macOS, we can install it with Homebrew:\n\n```\nbrew install git-delta\n```\n\nThen configure Git to use it in `~/.gitconfig`:\n\n```\n[core]\n  pager = delta\n\n[interactive]\n  diffFilter = delta --color-only\n\n[delta]\n  navigate = true\n  line-numbers = true\n```\n\n`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.\n\nTurning on `navigate` lets you jump between files with `n` and `N` inside the pager.\n\nHere 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:\n\n`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:\n\nYou can also pipe a single diff into delta without touching your config:\n\n```\ngit diff src/cart.js | delta --side-by-side\n```\n\nIf 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.\n\n## Quick reference on the example branch\n\nHere’s a quick recap of what each option showed us on `agent/discount-cap`:\n\n| Command | What it strips or highlights | What we saw on this branch | \n|---|---|---|\n| `git diff --stat` | File-level summary of everything | 15 files, 306 changed lines (200 in `package-lock.json` ) | \n| `git diff --stat -- . ':!package-lock.json'` | Excludes the lockfile | 14 files, 62 insertions, 44 deletions | \n| `git diff -w src/api.js` | Ignores indentation and whitespace | 24 changed lines dropped to 1 real status change ( `400` to`422` ) | \n| `git diff --color-words` | Highlights changed tokens inline | Caught `0.22` to`0.21` in`TAX_RATE` and`checked` to`validated` | \n| `git diff --color-moved=dimmed-zebra` | Dims untouched moved lines | Exposed `Math.max(0, total - 500)` and`shipping(sub)` inside the move | \n| `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) | \n\n## Aliases and defaults in ~/.gitconfig\n\nOnce you know which options you reach for on every agent review, save them in `~/.gitconfig` so you don’t have to retype them:\n\n```\n[alias]\n  st = status -sb\n  overview = diff --compact-summary main...HEAD -- . ':!package-lock.json'\n  ws = diff -w --ignore-blank-lines\n  wd = diff --color-words\n\n[diff]\n  algorithm = histogram\n  colorMoved = dimmed-zebra\n  colorMovedWS = allow-indentation-change\n```\n\nRunning `git overview` from the agent’s branch gives us the whole branch at a glance, minus the lockfile:\n\n```\ngit overview\nREADME.md                   |  2 +-\n docs/CHANGELOG.md           |  4 ++++\n package.json                |  4 ++--\n src/api.js                  | 24 ++++++++++++------------\n src/cart.js                 | 13 ++-----------\n src/config.js               |  2 +-\n src/discount.js (new)       |  9 +++++++++\n src/{utils.js => format.js} |  0\n src/routes/checkout.js      |  6 +++---\n src/routes/products.js      |  9 +++++----\n src/stats.js                | 16 ++++++++--------\n test/cart.test.js           |  6 +++---\n test/discount.test.js (new) | 11 +++++++++++\n 13 files changed, 61 insertions(+), 45 deletions(-)\n```\n\n`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.\n\nNotice 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.\n\n`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.\n\nIf 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.\n\nWant me to talk about your product? You can [sponsor this site](https://flaviocopes.com/sponsor/).", "url": "https://wpnews.pro/news/review-an-agent-s-diff-in-the-terminal-with-git-diff", "canonical_source": "https://flaviocopes.com/git-diff-review/", "published_at": "2026-11-30 14:00:00+00:00", "updated_at": "2026-11-30 14:46:39.549666+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools"], "entities": ["Flavio", "git diff", "git status", "git add -N", "Express", "src/discount.js", "src/format.js", "agent/discount-cap"], "also_reported_by": [], "takeaway": "Run git status -sb first and git add -N on each new file by name, not '.', so untracked files appear in git diff and renames are detected without staging deletions.", "recommendation": {"advice": "After an agent finishes, run git status -sb to catch untracked files, then git add -N each new file by name so git diff shows them and detects renames; avoid git add -N . because it stages deletions.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/review-an-agent-s-diff-in-the-terminal-with-git-diff", "markdown": "https://wpnews.pro/news/review-an-agent-s-diff-in-the-terminal-with-git-diff.md", "text": "https://wpnews.pro/news/review-an-agent-s-diff-in-the-terminal-with-git-diff.txt", "jsonld": "https://wpnews.pro/news/review-an-agent-s-diff-in-the-terminal-with-git-diff.jsonld"}}