Skip to content
shellmap

List staged changes

Print files (or the full diff) of what's currently in the git index — what `git commit` will commit if you run it now.

How to list staged changes in each shell

Bashunix
git diff --cached --name-only

`--cached` and `--staged` are SYNONYMS — same output, different vintage (`--cached` is older). Drop `--name-only` for the full diff; use `--stat` for a one-line-per-file summary with insertions/deletions counts.

Zshunix
git diff --cached --name-only
Fishunix
git diff --cached --name-only
PowerShellwindows
git diff --cached --name-only
cmd.exewindows
git diff --cached --name-only

Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.

Gotchas & notes

  • **`--cached` vs `--staged`** — these flags are 100% synonyms; same code path, same output. `--cached` came first (2005-era convention from "the index is a cache"); `--staged` was added later for newcomers who found "staged" more intuitive. Use whichever you prefer; both are guaranteed stable. For brevity in shell aliases: `gds = git diff --staged` is common.
  • Pre-commit hook idiom: stage-only checking means the hook should look at `git diff --cached`, NOT `git diff` (working tree) — otherwise a hook flags issues in unstaged changes you never asked to commit. The canonical hook: `git diff --cached --name-only --diff-filter=ACM -z | xargs -0 eslint --` (filter to Added/Copied/Modified — exclude Deleted; use `-z`/`-0` NUL separation for path-with-space safety). For "lint only the staged HUNKS" (not the full file) use `git diff --cached -U0 | grep -E "^\+" | ...` or the `lint-staged` npm package.
  • Status-output equivalent: `git status --porcelain | grep "^[AMRDC]"` returns staged files only (the FIRST character of the two-char status is the index/staged status). The second character `[ MD]` is the worktree status. So `^[AMRDC] ` (capital + space) = "staged change with nothing pending in worktree"; `^[AMRDC][MD]` = "staged change WITH ADDITIONAL unstaged modification" (the file was edited after staging — you'll commit the OLD content, not the live file). This is a common confusion source — `git diff --cached` shows the OLD content; `git diff` shows the new-vs-old. Run BOTH before commit.
  • `git diff --cached --stat` gives a compact summary: `path/to/file.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)`. The summary line at the end is machine-parseable for CI gates: `git diff --cached --shortstat | awk '{print $4}'` extracts the insertions count. For per-file counts: `git diff --cached --numstat` → tab-separated `additions deletions filename` (suitable for `awk` or piping into pwsh `ConvertFrom-Csv -Delimiter "\t"`).

Related commands

Related tasks