Git
Staging
Version Control
Code Changes
Git Commands

How do I show the changes which have been staged?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Staged changes in Git are the exact contents of your next commit, not just a list of files you touched. Reviewing that staged snapshot before committing is one of the easiest ways to catch accidental file additions, partial staging mistakes, and commits that mix unrelated work.

Understand What “Staged” Means

Git works with three important states:

  1. the working tree, which is what is on disk right now
  2. the index, which holds the staged content for the next commit
  3. HEAD, which is the last committed snapshot

When you ask to see staged changes, you are asking Git to compare the index against HEAD. That is why the correct command is not plain git diff.

Use git diff --cached

The standard command is:

bash
git diff --cached

You can also use:

bash
git diff --staged

In modern Git, these are equivalent. They show the patch that would become a commit if you ran git commit immediately.

If you want a quick summary before reading the full patch, these are useful:

bash
git diff --cached --name-only
git diff --cached --name-status
git diff --cached --stat

These summary views help catch accidental file additions or large changes before you inspect the full diff in detail.

Know the Difference Between Staged and Unstaged Diffs

These commands answer different questions:

  • 'git diff shows working tree versus index'
  • 'git diff --cached shows index versus HEAD'
  • 'git diff HEAD shows all uncommitted changes versus HEAD'

Example:

bash
1# edit two files
2git add src/parser.py
3
4git diff
5git diff --cached

If both commands show output, you have partially staged work. That is normal and often useful, but you should understand it before committing.

Review One Path at a Time

If the staged patch is large, narrow the diff to one file or directory:

bash
git diff --cached -- src/parser.py
git diff --cached -- docs/

This makes staged review manageable during bigger refactors and helps keep the commit focused.

Use Patch Mode for Precise Staging

When one file contains several unrelated edits, patch mode is the best way to stage only the hunks that belong in the next commit.

bash
git add -p
git diff --cached

After staging interactively, always inspect the staged diff again. That confirms the index contains exactly what you meant to commit, not just what you happened to select quickly.

Unstage Mistakes Without Losing Work

If you staged the wrong file or the wrong hunk, remove it from the index while keeping the working tree changes.

bash
git restore --staged src/secret.txt

To unstage everything:

bash
git restore --staged .

This is much safer than trying to reconstruct the working tree from memory after an accidental git add ..

Build a Pre-Commit Routine

A simple review routine catches most staging mistakes:

  1. run git status -sb
  2. inspect unstaged work with git diff
  3. inspect commit-ready work with git diff --cached
  4. run tests or linters
  5. commit with a focused message

This takes very little time compared with the time lost cleaning up a bad commit later.

Common Pitfalls

The biggest mistake is running git diff and assuming it shows staged content. Another is using git add . and committing immediately without checking what actually entered the index.

Developers also forget that one file can be both staged and unstaged at the same time, which makes partial-state mistakes easy to miss.

Summary

  • Use git diff --cached or git diff --staged to inspect what the next commit will contain.
  • Keep working tree, index, and HEAD conceptually separate.
  • Use summary views for quick checks and full patch views for accuracy.
  • Unstage mistakes with git restore --staged without losing the underlying edits.
  • Make staged-diff review part of every normal commit workflow.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions