Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

What is the difference between Git’s working tree, staging area, and commits?

Quick answer

The working tree is the files you currently edit on disk. The staging area, or index, holds changes selected for the next commit. A commit records changes in repository history. Use git status to see paths that differ across these layers, git diff for unstaged changes, git diff --cached for staged changes, and git log to inspect recorded commits. [S1] [S2] [S3]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I edited a file, but Git seems to show the change in different places. What are the working tree, staging area, and commit?

Geez

Think of them as three layers in a simple workflow:

edit files in working tree → stage selected changes in the index → commit staged changes to history

The working tree is your checked-out files on disk, including edits you have not selected for a commit. The staging area, also called the index, holds changes prepared for the next commit. A commit records changes in repository history. So saving a file changes its working-tree state; staging selects changes; committing records the staged selection. Git status distinguishes paths that differ between the current commit and index, paths that differ between the index and working tree, and untracked paths. [S1]

Follow-up question

Can you show that with one sample file? I want to know what each command tells me without changing the file.

Geez

Assume you have a tracked file called notes.txt and you edit one line. Start with:

git status

This reports whether paths differ between the commit, index, and working tree, and identifies untracked paths. [S1] To focus on the contents of the unstaged edit, run:

git diff -- notes.txt

That compares the working tree with the staging area, showing changes not yet staged. [S2] These commands are for inspecting state; they do not stage or commit the edit. One nuance: the Git reference notes that git status may refresh cached index metadata, so it can make an index bookkeeping update; treat it as an inspection command, not an absolute guarantee of no writes. [S1]

Follow-up question

I staged just one of my edits. How do I check what will actually go into the next commit?

Geez

Compare both layers rather than relying on a single status summary. git diff --cached -- notes.txt shows the staged difference between the index and the last commit—the staged content that would be committed. git diff -- notes.txt shows any remaining unstaged difference between the working tree and index. [S2]

For example, suppose you changed two lines but staged only one. The cached diff should show the selected line; the regular diff can show the other line still waiting in the working tree. Review both before committing. If the result is not what you intended, pause and decide which changes to stage; the commands above inspect differences but do not select them.

Follow-up question

And after I commit, how can I tell the change is in history rather than only staged?

Geez

Use git status to check whether the working tree or index still differs from the current commit, and use git log to inspect recorded history. Git log lists commits reachable through parent links from the selected revision, in reverse chronological order by default. [S3]

A practical check for notes.txt is:

  1. Run git status and review the reported state.
  2. Run git log to see the commit history.
  3. Before committing, run git diff --cached -- notes.txt to inspect staged content.

A log entry shows a recorded commit; it does not by itself prove that a particular line is present. The commands’ general behavior does not determine a specific repository’s output; results depend on repository state and command options.

A practical checklist

  • Run git status to distinguish staged, unstaged, and untracked paths.

  • Use git diff -- path/to/file to inspect unstaged content.

  • Use git diff --cached -- path/to/file to inspect staged content before committing.

  • Compare both diffs if a file has a mixture of staged and unstaged edits.

  • After committing, inspect git log and check status for remaining changes.

A few more useful answers

Does saving a file stage it?

No. Saving edits the working-tree file; staging is a separate selection step. Check the difference with git diff.

What does Git report as untracked?

git status reports untracked paths separately from paths with differences between the commit, index, and working tree. Review its output to see which paths it identifies as untracked. [S1]

Does `git log` show changes that are only staged?

Git log displays recorded commits in history. To inspect staged content that would be committed, use git diff --cached. [S2] [S3]

Sources

References used for this guide.

  1. [S1] Git status: differences among commit, index, and working tree
    git-scm.com · Checked
  2. [S2] Git diff: inspect working-tree and staged changes
    git-scm.com · Checked
  3. [S3] Git log: inspect commit history
    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