How can I tell staged changes from unstaged changes in Git?
Quick answer
Run git diff --cached or git diff --staged to review changes staged for the next commit. Run git diff to review unstaged edits. The staged view compares the index with HEAD; the unstaged view compares the working tree with the index. Review both, especially if you have made staged and unstaged edits to the same file. [S1]
The question, the details, the next step.
A practical checklist
Run
git diff --cachedorgit diff --stagedto review staged changes.Run
git diffto review unstaged edits.Inspect both views if the same file has staged and unstaged changes.
Pause and review the staged view if it includes an unintended change.
A few more useful answers
Are `git diff --cached` and `git diff --staged` different?
They are alternative spellings for viewing staged changes compared with HEAD. [S1]
Does `git diff` show what is prepared for my commit?
Not by itself: it compares the working tree with the index and shows unstaged edits. Use git diff --cached or git diff --staged to review staged changes. [S1]
Can one file have staged and unstaged changes at the same time?
Yes. The staged and unstaged comparisons can show separate changes in the same file. Review both views to distinguish what is prepared for the commit from later edits. [S1]
Sources
References used for this guide.
- [S1] Git - git-diff Documentation git-scm.com · Checked
