CodeBlanks Logo Icon CodeBlanks

Working vs staged

Learn the difference between the working tree and the stage.

Working tree and staging area

In Git, the working tree is the current state of the files you edit. The staging area holds changes added with git add and prepared for the next commit. git diff shows the differences between the working tree and the staged content.

git add index.html
git diff

A file can have both staged and unstaged changes at the same time.

Two different states of changes

When you edit a file and add it to the staging area with git add, that change becomes staged. If you edit the same file again, the new change remains in the working tree.

# First edit
git add index.html

# Second edit
git diff

In this case, git diff shows only the part of the second edit that has not yet been staged.

Practice Compare staging area and working tree

Use git diff to view unstaged differences between file edits. Do not add another option to the command.

Starter code

terminal
# Çalışma ağacı ile sahneyi karşılaştır
# Komutu buraya yaz

Sample solution

terminal
# Çalışma ağacı ile sahneyi karşılaştır
git diff

Expected output

çalışma ağacı ve sahne arasındaki fark gösterilir

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 You staged one change in a file and then made another edit to the same file. What does git diff show?

  • The difference between the staging area and working tree Correct answer
  • The entire commit history
  • The file's original creation state
  • Only staged changes

Explanation: <code>git diff</code> shows the unstaged difference between staged content and the current working tree.

2 Add the file to the staging area

Question
git add ____
Answer
git add index.html

Explanation: <code>git add index.html</code> adds the current changes in index.html to the staging area.

3 Where changes are stored

Term Meaning
Working tree Content not yet staged
Staging area Content prepared for a commit
git add Moves changes to staging
git diff Shows working tree and staged diffs

All lessons in Beginner