Um momento
0x10Lesson 2 of 6

Stage and commit changes

Review edits, choose what belongs in a commit, and record it.

12 min 5-question quiz
By the end of this lesson you can
  • 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.

terminal · git
1git status --short
2 M README.md
3?? notes.txt
4
5git add README.md
6git diff --cached
7git commit -m "Clarify setup instructions"
Output
 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 status to see staged and unstaged changes.

  • Review git diff --cached to 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…

Gostou da aula? 😆👍
Apoie nosso trabalho com uma doação: