CodeBlanks Logo Icon CodeBlanks

Staged vs HEAD

Learn the staged difference with git diff --cached.

Compare staged changes

git diff --cached compares staged changes with the current commit. This allows you to review the changes that will go into the next commit. The --cached option performs the comparison using staged content.

git add index.html
git diff --cached

This command shows staged changes rather than changes that have not been staged.

Comparing with HEAD

HEAD refers to the latest commit at the current position in Git. git diff --cached compares staged changes with the contents of this commit. This lets you see which lines will be added or removed before creating a commit.

git diff --cached

-Old heading
+New heading

Plus and minus signs in the output represent staged changes.

Practice Display staged differences

Write git diff --cached to compare the current commit with staged changes.

Starter code

terminal
# Sahnelenmiş değişiklikleri göster
# Komutu buraya yaz

Sample solution

terminal
# Sahnelenmiş değişiklikleri göster
git diff --cached

Expected output

sahnelenmiş değişiklikler HEAD ile karşılaştırılır

Questions and answers

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

1 Before creating a commit, you want to compare staged changes with the current commit. Which command should you use?

  • git status
  • git diff --cached Correct answer
  • git diff
  • git log

Explanation: <code>git diff --cached</code> compares staged changes with the current commit.

2 Inspect staged differences

Question
git diff____ 
Answer
git diff--cached 

Explanation: <code>--cached</code> shows staged changes compared with the current commit.

3 Parts of staged comparison

Term Meaning
--cached Shows staged differences
HEAD Refers to the current commit
git add Adds a change to staging
git diff --cached Compares staging with HEAD

All lessons in Beginner