How to write good commit messages that your future self will thank you for
A commit message is a note to whoever reads the history later, which is often you while debugging under pressure. A few conventions make them much more useful.
Structure
- A short summary line, roughly 50 characters, in the imperative mood: "Fix race in cache refresh" rather than "Fixed stuff"
- A blank line
- A body that explains why the change was needed and any important context, wrapped at a reasonable width
What to include
- The problem being solved, not just the code that changed (the diff already shows that)
- Trade-offs or alternatives you rejected
- References to issue or ticket numbers
What to avoid
- "WIP", "fix", "updates" on commits that land in main
- Mixing unrelated changes in one commit, which makes reverting and bisecting harder
Some teams use Conventional Commits (prefixes like feat:, fix:, docs:) so tooling can generate changelogs and decide version bumps automatically. Others prefer free-form messages and squash merges where the pull request description becomes the commit message.
Does your team enforce a commit message format? And is it worth cleaning up messy local commits with an interactive rebase before pushing, or is that wasted effort?
Comments · 2
Good history is documentation for free. It also helps new team members understand why decisions were made.
I like a short summary line followed by detail. It reads like a headline plus an article.