Stage and commit changes
Review edits, choose what belongs in a commit, and record it.
- Use status, diff, add and commit to make a focused commit.
Git separates the working tree from the staging area (also called the index). git add copies selected changes into the staging area. A commit records what is staged, so review the staged diff before committing.
1git status --short
2 M README.md
3?? notes.txt
4
5git add README.md
6git diff --cached
7git commit -m "Clarify setup instructions"M README.md ?? notes.txt # The staged README changes are shown [main a1b2c3d] Clarify setup instructions
git add stages the file’s current contents. If you edit the file again after staging it, stage it again to include the newer edit. Use git add -p to choose individual hunks interactively.
Key takeaways
Use
git statusto see staged and unstaged changes.Review
git diff --cachedto inspect what the next commit will contain.A commit includes staged changes, not every edit in the working tree.
Lesson quiz
5 questions · pass with 4 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…