Summary - Diff
- Git course
- Beginner
- Lesson 36/80
- 5 min
Combine diff options to inspect the change flow.
Compare changes correctly
To inspect changes in Git, you need to know which areas are being compared. git diff shows the difference between the working tree and the staging area. git diff --cached compares staged changes with the current commit, HEAD.
git diff
git diff --cachedThese two commands let you review both unstaged changes and changes prepared for a commit.
Practice Inspect both groups of changes
First inspect unstaged differences in the working tree with git diff, then inspect staged differences with git diff --cached. Write the two commands on separate lines.
Starter code
# Sahnelenmemiş farkları göster
# İlk komutu yaz
# Sahnelenmiş farkları göster
# İkinci komutu yazSample solution
# Sahnelenmemiş farkları göster
git diff
# Sahnelenmiş farkları göster
git diff --cachedExpected output
önce çalışma ağacı farkı, sonra HEAD ile sahne farkı gösterilir
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 A file contains both staged and unstaged changes. Which pair of commands should you use to inspect both groups separately?
- git commit and git log
- git status and git log
- git diff and git diff --cached Correct answer
- git init and git add
Explanation: <code>git diff</code> shows unstaged changes, while <code>git diff --cached</code> shows staged changes.
2 Complete the HEAD comparison option
git diff --____
git diff --cached
Explanation: <code>--cached</code> is used to compare staged changes with the current commit.
3 Comparison workflow
| Term | Meaning |
|---|---|
git diff |
Compares working tree with staging |
git diff --cached |
Compares staging with HEAD |
HEAD |
Current commit position |
Staged |
Change prepared for a commit |