Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

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]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I edited a few files and used git add on some of them. How can I see exactly what is staged for my next commit, separately from edits I have not staged?

Geez

Use two diff views, because they compare different parts of your working state:

  • Run git diff --cached to inspect staged changes. git diff --staged is an alternative spelling. This compares the index with HEAD and shows changes staged for the next commit. [S1]
  • Run git diff to inspect unstaged edits. It compares the working tree with the index. [S1]

Read the staged view to review what is prepared for the commit, then read the plain view to see what remains unstaged. Don’t treat the plain git diff output as a complete preview of the commit: it shows the difference between your working tree and the index, not the staged comparison with HEAD.

Follow-up question

What if I staged a file, then kept editing it? Will Git show one combined change or separate parts?

Geez

The staged and unstaged views can show separate parts of the same file. The staged diff shows the index compared with HEAD; the unstaged diff shows the working tree compared with the index. [S1]

For example, suppose you stage a heading correction, then add a paragraph to that same file without staging the later edit. Use git diff --cached to review the heading change prepared for the commit, and git diff to review the paragraph edit that remains unstaged. This is an illustrative example, not output from a particular repository.

Review each view on its own. A file appearing in the staged view does not mean every current edit to that file is staged. Checking both helps distinguish what is prepared for the next commit from later edits. [S1]

Follow-up question

Can you give me a simple review sequence to use before I commit?

Geez

Try this sequence:

  1. Run git diff --cached and read the staged changes as the contents prepared for your next commit.
  2. Run git diff and read the unstaged changes as edits outside the index.
  3. If you see the same file in both views, inspect both outputs: they can represent different edits in that file.
  4. If the staged view contains something you did not intend to include, pause and review it before committing. Don’t rely on the unstaged view to show what is staged.

The point is not that every unstaged edit must be included or discarded. The two views help you make that decision separately: first assess the proposed commit, then assess the edits that are still outside it. [S1]

Follow-up question

What if both commands print nothing? And is there an important exception to keep in mind?

Geez

If both comparisons show no changes, they show no differences at those two boundaries when you ran them. That does not, by itself, tell you whether an earlier commit was correct. The staged view is normally described as a comparison with HEAD, but Git documents an exception for staged-diff behavior on an unborn branch. [S1]

For a straightforward pre-commit check, remember the distinction: git diff --cached (or git diff --staged) is for changes staged for the next commit; git diff is for working-tree edits not staged in the index. Review both when you need to separate the two. [S1]

A practical checklist

  • Run git diff --cached or git diff --staged to review staged changes.

  • Run git diff to 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.

  1. [S1] Git - git-diff Documentation
    git-scm.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work