Git Staged vs Unstaged: Understanding the Staging Area

2024/01/01 2026/05/16
Git Staged vs Unstaged: Understanding the Staging Area

In Git, staged changes are modifications you have explicitly marked (via git add) to be included in your next commit, while unstaged changes are edits sitting in your working directory that Git tracks but will not commit until you stage them. Understanding the difference between git staged and git unstaged files is fundamental to controlling your version history and collaborating effectively with others.

Git’s Three Areas: Working Directory, Staging Area, Repository

Git organizes your project into three distinct zones. Every file transition flows through these areas in sequence:

AreaDescriptionKey Command
Working DirectoryThe files you see and edit on diskEdit with any editor
Staging Area (Index)A snapshot of changes queued for the next commitgit add
Repository (.git)The permanent history of committed snapshotsgit commit

When you modify a file, the change exists only in your working directory. It is unstaged. When you run git add, the change moves to the staging area and becomes staged. Finally, git commit records the staged snapshot into the repository.

Working Directory  --(git add)-->  Staging Area  --(git commit)-->  Repository

This three-area architecture gives you fine-grained control. You can edit ten files but commit only three of them by staging just the ones you want.

Staged Changes Explained

A git staged change is any modification, addition, or deletion that has been added to the staging area. Once staged, Git knows this change should be part of the next commit.

How to stage changes

# Stage a single file
git add example.txt

# Stage multiple files
git add src/app.js src/utils.js

# Stage all changes in the current directory
git add .

# Stage parts of a file interactively
git add -p example.txt

Viewing staged changes

Use git diff --staged (or the synonym git diff --cached) to see exactly what will go into your next commit:

$ git diff --staged
diff --git a/example.txt b/example.txt
index e69de29..d95f3ad 100644
--- a/example.txt
+++ b/example.txt
@@ -0,0 +1 @@
+Hello World

You can also verify which files are staged with git status:

$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   example.txt

The section labeled “Changes to be committed” lists all your staged files.

Unstaging a file

If you staged something by mistake, remove it from the staging area without losing your edits:

# Modern syntax (Git 2.23+)
git restore --staged example.txt

# Classic syntax
git reset HEAD example.txt

Both commands move the file back to the unstaged state while preserving your working directory changes.

Unstaged Changes Explained

A git unstaged change is any modification in your working directory that has not been added to the staging area. Git sees the file has changed compared to the last staged or committed version, but it will not include these changes in a commit until you explicitly stage them.

Common causes of unstaged changes

  • Editing a tracked file after your last git add
  • Modifying a file that was already staged (creating a partially staged state)
  • Deleting a file without using git rm

Viewing unstaged changes

Use git diff (without flags) to see modifications that exist only in your working directory:

$ git diff
diff --git a/example.txt b/example.txt
index d95f3ad..4b5fa63 100644
--- a/example.txt
+++ b/example.txt
@@ -1 +1,2 @@
 Hello World
+This line is unstaged

And git status shows them under “Changes not staged for commit”:

$ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   example.txt

Discarding unstaged changes

If you want to throw away working directory changes and revert a file to its last staged or committed state:

# Discard changes in a single file
git restore example.txt

# Discard all unstaged changes (use with caution)
git restore .

Commands for Managing Staged and Unstaged Files

Here is a quick-reference table of the most important commands for working with the staging area:

TaskCommand
Stage a filegit add <file>
Stage all changesgit add . or git add -A
View staged diffgit diff --staged
View unstaged diffgit diff
Unstage a filegit restore --staged <file>
Discard unstaged changesgit restore <file>
Show file statusgit status
Stage and commit togethergit commit -a -m "message"
Interactive partial staginggit add -p <file>

The git commit -a shortcut stages all tracked modified files and commits them in one step. However, it does not add untracked (new) files, so you still need git add for those.

Common Workflows

Workflow 1: Selective commit

You edited three files but only want to commit two:

# Check what changed
git status

# Stage only the files you want
git add feature.js tests/feature.test.js

# Verify what's staged
git diff --staged

# Commit
git commit -m "feat: add feature with tests"

The third file remains unstaged and will not appear in the commit.

Workflow 2: Partially staging a file

Sometimes a single file contains changes for two different logical commits. Use git add -p to stage specific hunks:

$ git add -p app.js
diff --git a/app.js b/app.js
@@ -10,6 +10,7 @@
 function init() {
+  logger.info("starting");   // Stage this? [y/n/q]
 }
@@ -25,6 +26,7 @@
 function cleanup() {
+  // TODO: refactor later   // Stage this? [y/n/q]
 }

You can answer y for the first hunk and n for the second, giving you a commit that only includes the logging change.

Workflow 3: Reviewing before committing

A best practice is to always review staged changes before committing:

# Stage your work
git add .

# Review the exact diff that will be committed
git diff --staged

# If everything looks good, commit
git commit -m "fix: resolve null pointer in parser"

This habit prevents accidental commits of debug code, console logs, or unrelated changes.

Workflow 4: Amending after forgetting to stage

If you committed but forgot to include a file:

# Stage the forgotten file
git add forgotten-file.js

# Amend the previous commit (only if not yet pushed)
git commit --amend --no-edit

This adds the staged change to your most recent commit without creating a new one.

Summary

The distinction between git staged and git unstaged changes is central to Git’s design philosophy of giving developers full control over what goes into each commit. The staging area acts as a buffer where you assemble the perfect snapshot before permanently recording it in history. By mastering commands like git add, git diff --staged, git diff, and git restore --staged, you gain precise control over your project’s version history and keep your commit log clean and meaningful.

Further reading:

B
BenZ Software Developer

Software developer passionate about technology. Sharing programming experiences and learning notes.