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-onlyFishunix
git diff --cached --name-onlyPowerShellwindows
git diff --cached --name-onlycmd.exewindows
git diff --cached --name-onlyEquivalents 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
- List modified files in a git repo— Print the paths of files with uncommitted changes (staged or unstaged) — for pre-commit hooks, CI lint-only-changed gates, and "what am I about to commit".
- Count files changed since a commit— Get the number of distinct files that differ between a reference commit (a tag, SHA, or `origin/main`) and the working tree — for CI gates and PR-size summaries.
- Show the current git branch— Print the name of the branch HEAD points at — used in shell prompts, CI build labels, and "deploy what's on the branch" scripts.