Git diff: compare your changes
git diff shows you exactly what has changed in your files, line by line. Essential for reviewing your work before committing.
gitquest — enquête
The different modes of git diff
git diffUnstaged changes (working dir vs staging)
git diff --stagedStaged changes (staging vs last commit)
git diff HEADAll changes (working dir vs last commit)
git diff a..bDifferences between two branches or commits
Git diff in practice
Reading unstaged and staged changes.
Unstaged diff
gitquest — diff
# View unstaged changes
$git diff
diff --git a/index.html b/index.html
--- a/index.html
+++ b/index.html
@@ -5,7 +5,7 @@
- <title>My Site</title>
+ <title>GitQuest - Learn Git</title>
# - = removed line, + = added line
Staged diff and summary
gitquest — diff --staged
# View staged changes (ready to commit)
$git diff --staged
diff --git a/style.css b/style.css
--- a/style.css
+++ b/style.css
+.navbar { background: #1a1a2e; }
+.navbar a { color: #e94560; }
# Summary of changes
$git diff --stat
index.html | 2 +-
style.css | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
Reading git diff output
diff --git a/file b/fileHeader: which file is being compared
--- a/file / +++ b/filea/ = old version, b/ = new version
@@ -5,7 +5,8 @@Position in the file: line 5, 7 lines before / 8 lines after
- removed line+ added lineLines without a prefix are unchanged context
Part of the Git Basics guide
A
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about git diff
Learn to read diffs in GitQuest
Investigations ask you to analyze changes to solve problems.
Start practicing now