Git — Diff
Basic Diff
git diff
Diff Staged
git diff --staged
Diff Between Commits
git diff commit1 commit2
Diff Branches
git diff main..feature
Diff Options
# Word diff
git diff --word-diff
# Stat only
git diff --stat
# Specific file
git diff file.txt
Diff with Context
git diff -U3 # 3 lines of context
Diff Against Branch
git diff main
git diff origin/main
Diff Summary
| Command | Description |
|---|---|
| git diff | Working vs staged |
| git diff --staged | Staged vs last commit |
| git diff HEAD | Working vs last commit |
| git diff branch | Branch vs current |
Mini Practice
- View working changes
- View staged changes
- Compare commits
- Compare branches
Up Next
Continue with Reset — resetting changes.
Related Topics
Frequently Asked Questions about Diff
What is Diff in Git?
Diff is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Diff?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Diff.
Why is Diff important in Git?
Diff is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.