Diff The Staged Changes
Part of the Version Control section of Coddy's Terminal journey — lesson 16 of 58.
Once you stage changes with git add, plain git diff stops showing them. To see what is queued up for the next commit, use:
git diff --staged(The flag --cached is an alias and does the same thing.) This is what you should run right before committing, to double-check exactly what will be saved.
The two diffs answer two different questions:
git diff: "what have I changed but not yet staged?"git diff --staged: "what will go into the next commit?"
If you have both unstaged edits and staged edits, the two commands show different sets of lines. Knowing which is which prevents you from committing the wrong version.
Challenge
EasyThe folder contains config.txt with the content port=80, already committed. Change it to port=8080, stage the change, then run git diff --staged.
Cheat sheet
git diff --staged shows changes that are staged (queued for the next commit). Use it to verify what will be saved before committing:
git diff --stagedThe two diff commands answer different questions:
git diff— changes not yet stagedgit diff --staged(alias:--cached) — changes staged for the next commit
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Version Control
2Getting Started
Initialize A RepositoryThe .git FolderConfigure Your IdentityGit StatusRecap - First Repo8Merging
What Is A MergeFast-Forward MergeThree-Way MergeMerge ConflictsResolve A ConflictRecap - Merge Master11Feature Branch Project
Project OverviewInitialize Main3Tracking Changes
The Staging AreaGit AddGit CommitModifying A Tracked FileGit LogRecap - First Commits6Recipe Site Project
Project OverviewInitialize And Ignore