Hone

Lessons · Git · recording a snapshot

Recording a snapshot

git commit records the staged changes as one snapshot with a message. Nothing unstaged goes in, and the commit stays on your machine until you push.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

A commit is the unit of history: what can be reviewed, reverted, blamed and released. Small, well-described commits are the difference between a history you can use and one you scroll past.

How to think about it

Stage what belongs together, check it with git diff --staged (the next lesson: it prints what you have staged), then commit with a message that says what and why. -a stages every modified tracked file first, which is handy and easy to overdo.

Worked example

git commit -m "Add the report"
Records the staged changes as one snapshot with that message.
git log --oneline -1
The new commit: a short hash and the subject.
git commit -am "Fix typo"
-a stages every modified tracked file first; new files still need add.

Your turn

Record the staged work.

git commit -m ""

The trap

A commit is local. Until you push, it exists only on your machine, and a lost laptop takes it with it.

Practise recording a snapshot on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.