# git diff: unstaged, staged, and against a commit

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/git-diff-forms-full-en
`git diff` compares the working tree with the index; `git diff --cached` compares the index with `HEAD`. TE-12-A shows both. TE-12-B shows --stat and TE-12-C shows --exit-code with --quiet. No other form is tested.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-12-A, TE-12-B and TE-12-C. The expected non-zero exit is TE-12-C (exit status 1). Every row has a recorded log in the evidence archive. The evidence table lists the exit status and log hash of every row, and no Exit status line on this page is for the A row.)

### TE-12-A: git diff shows unstaged changes only; --cached shows staged changes

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' > f.txt; git add f.txt
```

Command:

```bash
echo plain=$(git diff | wc -l); echo cached=$(git diff --cached | wc -l)
```

Recorded output:

```
plain=0
cached=7
```

### TE-12-B: git diff --stat summarizes an unstaged change as one file with one insertion and one deletion

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' > f.txt
```

Command:

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

Recorded output:

```
 f.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
```

Exit status: 0. This status and the output match what was written before the run.

### TE-12-C: expected non-zero exit: git diff --exit-code --quiet exits with status 1 when there is a difference

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' > f.txt
```

Command:

```bash
git diff --exit-code --quiet
```

Recorded output: none, standard output was empty.

Exit status: 1. This status and the output match what was written before the run.

TE-12-B: by the setup, f.txt changed from one to two without being staged. git diff --stat printed f.txt | 2 +-, then 1 file changed, 1 insertion(+), 1 deletion(-). TE-12-C: git diff --exit-code --quiet printed nothing and exited with status 1, and the same change was still unstaged by the setup.

## Limits

The wrong form may show nothing or a different change set.

## Source

- https://git-scm.com/docs/git-diff

## Evidence

- `TE-12-A`: git diff shows unstaged changes only; --cached shows staged changes

- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-12-A` | git diff shows unstaged changes only; --cached shows staged changes | 0 | PASS | `4feb3d84ccf6` |
| `TE-12-B` | git diff --stat summarizes an unstaged change as one file with one insertion and one deletion | 0 | PASS | `f9acadefafe3` |
| `TE-12-C` | expected non-zero exit: git diff --exit-code --quiet exits with status 1 when there is a difference | 1 | PASS | `6cc59c881bd2` |

Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [git log: commits reachable from HEAD, and --all](https://kairos-2z6s.onrender.com/res/git-log-filters-full-en)
- [.gitignore patterns: which files Git treats as untracked](https://kairos-2z6s.onrender.com/res/gitignore-patterns-full-en)
- [Git Log -S: find the commit that added or removed a string](https://kairos-2z6s.onrender.com/res/git-log-s-full-en)
- [Git Grep: search tracked files](https://kairos-2z6s.onrender.com/res/git-grep-full-en)
- [Git Describe: name a commit from the nearest tag](https://kairos-2z6s.onrender.com/res/git-describe-full-en)
