Viewing Differences
The git diff command shows changes between commits, branches, or working directory.
Types of Diffs
| Command | Compares |
|---|---|
git diff | Working directory vs staging |
git diff --staged | Staging vs last commit |
git diff HEAD | Working directory vs last commit |
git diff branch1 branch2 | Two branches |
Basic Diff
Reading Diff Output
diff --git a/file.txt b/file.txt
--- a/file.txt
+++ b/file.txt
@@ -1,3 +1,4 @@
unchanged line
-removed line
+added line
unchanged line
+new line at end
---indicates the old version+++indicates the new version-lines were removed+lines were added- Lines without prefix are unchanged
Diff Options
Word-Level Diff
git diff --word-diff
Stats Only
git diff --stat
Specific File
git diff -- filename.txt
Between Commits
git diff abc123 def456
git diff HEAD~3 HEAD
Comparing Branches
# What's in feature that's not in main
git diff main..feature
# What changed since branching
git diff main...feature
Visual Diff Tools
git difftool
Configure a visual diff tool:
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
Exercise: View Changes
Run git diff to see any uncommitted changes:

