Module 2 · Git: the 20 everyday commands · Lesson 10 of 16
Save snapshots: add, commit, log, diff
Stage changes, make commits with good messages, read the history and compare versions.
In this lesson · about 22 minutes
- Stage files with git add (one file, or everything with git add .)
- Commit with a clear message using git commit -m
- Read history with git log and git log --oneline
- See exactly what changed with git diff and git diff --staged
Key terms
Say the meaning to yourself, then tap a card to check.
Good commit messages
Write the message as a short instruction that completes the sentence "This commit will…": Add opening hours to home page, Fix broken logo link. Avoid stuff, changes or asdf: in six months, the message is the only clue to why something changed.
Reading a diff
@@ -1,3 +1,4 @@ <h1>Sam's Coffee Corner</h1> -<p>Open 7am to 3pm</p> +<p>Open 7am to 4pm</p>
Lines starting with - (red) were removed, lines with + (green) were added. A changed line shows as one of each.
git diff on its own compares your working folder with the staging area. Once you have staged everything it shows nothing; then use git diff --staged.
Practice terminal · missions
Make Sam's first commits
Watch files move from the working folder box to the staging area box, and new dots appear in the commit history.
Missions 0 of 11
- 1Go into website and start a repository there, in one line.
- 2Stage just index.html.
- 3Check the status.
- 4Stage everything else in the folder.
- 5Commit with the message First version of the site
- 6Look at the history.
- 7Add a line to index.html: echo "Now serving pastries" >> index.html
- 8See exactly what changed.
- 9Stage the change, then check what is about to be committed.
- 10Commit it with a clear message.
- 11Show the history, one line per commit.
Type a command and press Enter. Try help to list commands. Tab finishes names, ↑ repeats.
No Git repository here yet.
You are in ~. Git pictures appear once you cd into a project that is a repository, or run git init or git clone.
- ~ (/home/sam)you are here
- documents
- notes.txt
- website
- index.html
- README.md
- style.css
Check your understanding0 of 4 correct
Quiz score: 0 of 4
Written by Noviq Academy in its own words. The practice terminal is a simulation that runs in your browser: it imitates Linux (Ubuntu-style output) and Git closely, but it is not a real computer, and real output can differ slightly. The servers, people, web addresses and GitHub addresses in the labs are made up. Linux is a trademark of Linus Torvalds; Git and GitHub belong to their owners. Read-aloud uses your device's built-in voices.