Staging What You Mean To

Edit three real files at once. A commit is a choice — not "all the changes I happened to make."

Your recipe collection is growing. In one real sitting you add ingredients to the cookie recipe, write a new pasta recipe, and write a new soup recipe — three genuinely different files, all dirty at once.\n\nThe temptation is to stage everything and commit it all as one lump. This lesson does the opposite, on purpose: stage exactly two of the three, commit that pair with a message that describes what it actually contains, then come back for the third file separately. git status and git diff --staged are your real, live mirrors at every step, confirmed directly rather than assumed.

Three Real Files, One Working Session

# edit cookies.md, create pasta.md and soup.md
git status

git genuinely tracks each file's own state independently — one modified, two untracked — all visible in a single real status report.

Stage Only What Belongs Together

git add cookies.md pasta.md
git diff --staged

git diff --staged shows the exact real content queued for the next commit — both files, and only those two, even though a third file is also genuinely dirty on disk right now.

Commit, Then Come Back for the Rest

git commit -m "Add ingredients list and pasta recipe"
git status              # soup.md is still genuinely untracked
git add soup.md
git commit -m "Add chicken noodle soup recipe"

Two real, separate commits — each one containing exactly what its message describes, not an incidental dump of everything that happened to be dirty at the time.

Selective staging

Running git add on only some of the files that are currently dirty, even when other files are also genuinely modified or untracked at the same time. Confirmed directly in this lab: git diff --staged only ever shows the files actually staged, never the ones left out.

A commit as a choice

A commit genuinely only ever contains what was staged at the moment git commit ran — not "everything that changed today." Real, disciplined commits are built by choosing what belongs together, not by accepting whatever happens to be dirty.

📝 Edit Three Real Files

Add ingredients to cookies.md, and create pasta.md and soup.md — three genuinely different files, all dirty at once.

cd ~/recipes && printf 'Chocolate Chip Cookie Recipe\n\nIngredients: flour, sugar, butter, chocolate chips\n' > cookies.md
cd ~/recipes && printf 'Simple Tomato Pasta\n\nBoil pasta, add tomato sauce, serve hot.\n' > pasta.md
cd ~/recipes && printf 'Chicken Noodle Soup\n\nSimmer chicken, add noodles and vegetables.\n' > soup.md
cd ~/recipes && git status

student@lab:~$ cd ~/recipes && printf 'Chocolate Chip Cookie Recipe\n\nIngredients: flour, sugar, butter, chocolate chips\n' > cookies.md student@lab:~$ cd ~/recipes && printf 'Simple Tomato Pasta\n\nBoil pasta, add tomato sauce, serve hot.\n' > pasta.md student@lab:~$ cd ~/recipes && printf 'Chicken Noodle Soup\n\nSimmer chicken, add noodles and vegetables.\n' > soup.md student@lab:~$ cd ~/recipes && git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: cookies.md Untracked files: (use "git add <file>..." to include in what will be committed) pasta.md soup.md no changes added to commit (use "git add" and/or "git commit -a")

➕ Stage Only Two of the Three

Stage cookies.md and pasta.md together, and preview exactly what that commit would contain — leaving soup.md out for now.

cd ~/recipes && git add cookies.md pasta.md
cd ~/recipes && git diff --staged

student@lab:~$ cd ~/recipes && git add cookies.md pasta.md student@lab:~$ cd ~/recipes && git diff --staged diff --git a/cookies.md b/cookies.md index 07a904e..353f6dc 100644 --- a/cookies.md +++ b/cookies.md @@ -1 +1,3 @@ Chocolate Chip Cookie Recipe + +Ingredients: flour, sugar, butter, chocolate chips diff --git a/pasta.md b/pasta.md new file mode 100644 index 0000000..b675632 --- /dev/null +++ b/pasta.md @@ -0,0 +1,3 @@ +Simple Tomato Pasta + +Boil pasta, add tomato sauce, serve hot.

📸 Commit the Staged Pair

Commit cookies.md and pasta.md together, then confirm soup.md is still genuinely untracked and waiting.

cd ~/recipes && git status
cd ~/recipes && git commit -m 'Add ingredients list and pasta recipe'
cd ~/recipes && git status

student@lab:~$ cd ~/recipes && git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: cookies.md new file: pasta.md Untracked files: (use "git add <file>..." to include in what will be committed) soup.md student@lab:~$ cd ~/recipes && git commit -m 'Add ingredients list and pasta recipe' [master 6231b69] Add ingredients list and pasta recipe 2 files changed, 5 insertions(+) create mode 100644 pasta.md student@lab:~$ cd ~/recipes && git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) soup.md nothing added to commit but untracked files present (use "git add" to track)

➕ Stage and Commit the Third File

Now stage and commit soup.md on its own, and confirm the real, final history shows three genuinely separate, deliberate commits.

cd ~/recipes && git add soup.md && git commit -m 'Add chicken noodle soup recipe'
cd ~/recipes && git log --oneline

student@lab:~$ cd ~/recipes && git add soup.md && git commit -m 'Add chicken noodle soup recipe' [master 848110c] Add chicken noodle soup recipe 1 file changed, 3 insertions(+) create mode 100644 soup.md student@lab:~$ cd ~/recipes && git log --oneline 848110c (HEAD -> master) Add chicken noodle soup recipe 6231b69 Add ingredients list and pasta recipe 7fb33b3 Add chocolate chip cookie recipe

Lab 1.2.1 complete. Three real files, staged and committed on purpose, not by default:\n\n\n Three files edited at once : ✅ confirmed via git status\n Two staged and committed : ✅ confirmed via git diff --staged\n Third staged and committed separately : ✅ confirmed via git log\n

Enable JavaScript to run the live terminal and track your progress.