Hone

Lessons · Git · writing a commit message

A message someone can use

A good commit message says what changed and why, in the imperative: 'Fix login timeout on slow networks'. Six months later it is the only explanation anyone will have.

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

Months later, when someone asks why a line looks like that, the tools that answer point at your message: git log lists them, and git blame (later on this path) shows which commit last touched a line. If it says 'stuff', the person debugging at 2am learns nothing, and that person is often you.

How to think about it

Subject under about fifty characters, imperative mood, specific. If the why does not fit, add a blank line and a paragraph. The diff shows what; the message is for why.

Worked example

git commit -m "Fix login timeout on slow networks"
Imperative, specific: what and why.
git commit -m "stuff"
Records the same code and explains nothing to the reader next year.
git log --oneline -2
Both side by side: one of them is useful.

Your turn

Write the subject.

git commit -m " the null check in parse"

The trap

A message that repeats what the diff shows (Changed file.py) wastes the only place the why can live.

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