Code shows what the program does. Only the commit message and the pull request can tell the next person why it changed, and that is usually the part they need.
Anatomy of a commit message
- A summary line of about 50 characters, in the imperative mood: "Add retry to payment client", not "Added" or "Adding".
- A blank line.
- A body, wrapped near 72 characters, saying why the change was needed, what approach was taken and what alternatives were rejected.
Retry payment requests on timeout
Card provider calls time out a few times a day. Without a retry the
customer sees an error even though the charge usually succeeds a few
seconds later.
Retry up to twice with exponential backoff, only for idempotent
requests that carry an idempotency key.Habits that help
- Make one logical change per commit, so each can be understood, reverted or cherry-picked alone.
- Do not mix refactoring with behaviour changes in the same commit.
- Reference the issue or ticket, but still explain the reason in words.
- Avoid messages like "fix", "wip" or "changes". Future you will not know what they meant.
Small pull requests
Reviews work best below a few hundred changed lines. Large pull requests get skimmed, and skimmed reviews miss bugs. Split work into steps that each leave the system working: prepare the refactor, add the feature behind a flag, then enable it.
A useful pull request description
- What changed, in a sentence or two.
- Why: the problem or the goal, with a link to the ticket.
- How to test: commands or steps, and what you verified.
- Risks and rollout: migrations, flags, anything that needs care.
- Screenshots for visible changes.
Be reviewer-friendly
Review your own diff first and remove debug code. Point reviewers at the risky parts. Answer comments politely, and prefer follow-up commits during review, squashing at the end if your team prefers it.
Takeaway
Write for the person who will read this in a year: say why, keep changes small and describe how to verify them.
Comments