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.
By Anaïs Sparesotto, web developer and head of education · Updated
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
Staged diff and summary
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
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.