Detecting System Modifications
The git diff command is your scanner—it shows exactly what changed between different states of your files. Essential for reviewing work before committing.
Basic Diff Usage
See unstaged changes:
git diff
This compares your working directory to the staging area.
See Staged Changes
git diff --staged
Shows what's in the staging area vs. last commit.
Reading Diff Output
diff --git a/navigation.js b/navigation.js
index 3a8f2c1..7b9d4e2 100644
--- a/navigation.js
+++ b/navigation.js
@@ -10,7 +10,7 @@ function calculateCourse() {
const distance = Math.sqrt(dx*dx + dy*dy);
- const speed = 1000; // meters per second
+ const speed = 1500; // increased for faster travel
return distance / speed;
---and+++: Old and new file versions-lines: Removed (shown in red)+lines: Added (shown in green)@@ -10,7 +10,7 @@: Line numbers context
Compare Specific Files
git diff navigation.js
Compare Commits
git diff commit1 commit2
git diff HEAD~2 HEAD # Compare 2 commits ago to now
Compare Branches
git diff main feature-branch
Useful Diff Options
--stat: Show summary statistics--color-words: Highlight changed words, not lines--name-only: Just list changed files
Why Use Diff?
- Review your work before committing
- Understand what teammates changed
- Verify fixes worked correctly
- Catch accidental changes
Next: Reviewing History
You can now see what changed. Next, we'll explore git log to review your complete mission history.