Saving a snapshot with git add and git commit

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Saving a snapshot with git add and git commit

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which command stages a file called main.py so it is ready for the next snapshot?
A git commit main.py
B git add main.py
2. Which command records a snapshot of your staged files with a message?
A git commit -m "Add login check"
B git add -m "Add login check"
3. What is the correct order to save your work as a snapshot?
A git add first, then git commit -m
B git commit -m first, then git add
4. Which commit message is clearer for future developers?
A git commit -m "stuff"
B git commit -m "Fix divide by zero in average"
5. True or false: git add saves a permanent snapshot in the repository history.
A False - git add only stages changes
B True - git add records the snapshot

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1git add main.py Agit add .
2git commit -m "Add login check" BStages the changes in main.py so they are included in the next snapshot
3Stage every changed file in the folder so all of them go into the next snapshot CThe message is vague. It does not explain what changed, so the project history is hard to understand later.
4A clear commit message says what changed, written in a short present-tense phrase DSaves a snapshot of the staged files in the repository history with a message
5git commit -m Add login check Egit commit -m "Fix score calculation bug"
6git commit -m "stuff" FThe message is not wrapped in quotes, so git reads Add, login and check as separate arguments instead of one message.

Definitions

git commit -m "message"

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
git ___ main.py
2.
git add main.py git ______ -m "Add login check"
3.
git commit __ "Fix score bug"
4.
git add _ git commit -m "Update scoring"
5.
git add report.py ___ commit -m "Add header"

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A git status
B git ad main.py
C git commit -m "Add login form"
Question 2
A git add main.py
B git status
C git commit "Fix tax bug"
Question 3
A git status
B git add report.txt
C git commit -m Add summary
Question 4
A git status
B git commit data.csv
C git commit -m "Add scores"
Question 5
A git status
B git add app.py
C git add notes.txt
D git commit -m

Answer Key

Saving a snapshot with git add and git commit
Section A: Quick Questions
Q1
B — git add main.py
Q2
A — git commit -m "Add login check"
Q3
A — git add first, then git commit -m
Q4
B — git commit -m "Fix divide by zero in average"
Q5
A — False - git add only stages changes
Section B: Match the Pairs
Q1
git add main.py → Stages the changes in main.py so they are included in the next snapshot
Q2
git commit -m "Add login check" → Saves a snapshot of the staged files in the repository history with a message
Q3
Stage every changed file in the folder so all of them go into the next snapshot → git add .
Q4
A clear commit message says what changed, written in a short present-tense phrase → git commit -m "Fix score calculation bug"
Q5
git commit -m Add login check → The message is not wrapped in quotes, so git reads Add, login and check as separate arguments instead of one message.
Q6
git commit -m "stuff" → The message is vague. It does not explain what changed, so the project history is hard to understand later.
Section C: Definitions
Q1
git commit -m "message" — Records a snapshot of the files you staged with git add, saving it in the repository history with a short message that explains what changed.
Section D: Fill in the Blanks
Q1
git add main.py
Q2
git add main.py git commit -m "Add login check"
Q3
git commit -m "Fix score bug"
Q4
git add . git commit -m "Update scoring"
Q5
git add report.py git commit -m "Add header"
Section E: Spot the Error
Q1
B — The command is misspelled. Staging a file uses git add, so the line should be git add main.py.
Q2
C — The -m flag is missing. Without it git does not read the text as a message. It should be git commit -m "Fix tax bug".
Q3
C — A message with spaces must be wrapped in quotes. Without them git only takes Add as the message. It should be git commit -m "Add summary".
Q4
B — Files are staged with git add, not git commit. Line 2 should be git add data.csv. The commit then records the staged snapshot with a message.
Q5
D — The -m flag needs a message after it. It should be git commit -m "Update app" so the snapshot is saved with a short description.