Lesson01
beginnerSee What Changed with git diff
Goal
Read a diff to decide what belongs in the next commit, and commit only that.
You fixed a bug in src/price.js, and while debugging you also flipped a flag in src/config.js. Both files show up as modified, but only the fix should be committed.
git status says *which* files changed. git diff shows *what* changed in them.
Objectives
0/3- Stage the bug fix in
src/price.js, and only that. (Current objective) - Commit the fix.
src/price.jsis then unchanged since the last commit. (Not started) src/config.jsstill has its debugging change, uncommitted and unstaged. (Not started)
Your task nowStep 1 of 3
Stage the bug fix in src/price.js, and only that.
Need help?
Reference
Reading a diff
$ git diff
diff --git a/src/price.js b/src/price.js index 3b18e51..8f1c2a0 100644 --- a/src/price.js +++ b/src/price.js @@ -1,3 +1,3 @@ export function total(items) { - return items.reduce((sum, item) => sum + item.price); + return items.reduce((sum, item) => sum + item.price, 0); }
--- is the old version and +++ the new one. @@ -1,3 +1,3 @@ says the excerpt starts at line 1 and spans 3 lines on each side. Lines starting with - were removed, lines starting with + were added, and the rest are unchanged context.
Which diff shows what
git diff
- Working tree compared with the staging area
- Changes you have not staged yet
git diff --staged
- Staging area compared with the last commit
- Exactly what
git commitwould record
Preparing your workspace…
Repository Graph
Click a commit to inspect it
Working Tree
Not a Git repository yet
No unstaged changes
Your working tree matches the staging area.
Staging Area
Files prepared for the next commit
No staged changes
Use git add to prepare files for your next commit.
Repository
Committed history
No commits yet
Use git commit to record staged changes.
