---
title: "How do I write a good commit message?"
description: "A good commit message has a short imperative subject line, a blank line, and a body that explains why the change was made. Here is the format, examples, and how to write it without -m."
url: https://www.danny.engineering/answer/git/how-do-i-write-a-good-commit-message
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["Git"]
---

# How do I write a good commit message?

## The short answer


Write a short subject line in the imperative mood, about 50 characters, with no full stop. Leave a blank line. Then write a body, wrapped at around 72 characters, that explains why the change was needed and anything a reviewer would not see from the diff.


```bash
Fix double charge when checkout is retried

The payment request had no idempotency key, so a retry after a
timeout created a second charge. Send the order ID as the key so
the provider ignores duplicates.

Fixes #482
```


## Why it happens


The diff already shows what changed. What it cannot show is why: the bug you saw, the option you rejected, the constraint you were working around. Six months later, someone running `git blame` or `git log` on that line needs exactly that context, and often that someone is you.


The format is not arbitrary either. Many Git tools treat the first line as a title. `git log --oneline`, `git shortlog`, `git rebase -i`, email patches and pull request lists all show only the subject, and some truncate it. The blank line is how Git separates the subject from the body.


## How to fix it


### Follow the seven conventions

1. Separate the subject from the body with a blank line.
2. Keep the subject to about 50 characters, and treat 72 as a hard limit.
3. Capitalise the subject.
4. Do not end the subject with a full stop.
5. Use the imperative mood: "Add", "Fix", "Remove", not "Added" or "Fixes".
6. Wrap the body at about 72 characters.
7. Use the body to explain what and why, not how.

A quick test for the imperative mood: the subject should complete the sentence "If applied, this commit will ...". "If applied, this commit will fix double charge when checkout is retried" reads correctly. It also matches the messages Git writes itself, such as "Merge branch" and "Revert".


### Write the message in your editor, not with -m


`git commit -m` makes it tempting to write a one-line message. Run `git commit` on its own and Git opens your editor, where a subject and body are easy to write. Set the editor once.


```bash
git config --global core.editor "code --wait"
# or: nano, vim, "zed --wait", and so on
```


If you prefer the command line, each `-m` becomes a separate paragraph.


```bash
git commit -m "Fix double charge when checkout is retried" \
  -m "The payment request had no idempotency key, so a retry after a timeout created a second charge."
```


### Keep each commit to one logical change


A good message is much easier when the commit does one thing. If your subject needs "and", consider splitting it. `git add -p` lets you stage parts of a file so you can commit related changes separately.


```bash
git add -p
git commit
```


### Use Conventional Commits if your team does


Some projects prefix the subject with a type, so tools can generate changelogs and version numbers. The common types are `feat`, `fix`, `docs`, `refactor`, `test` and `chore`, with an optional scope in brackets.


```bash
feat(cart): add saved-for-later list
fix(checkout): prevent double charge on retry
```


In this style the description usually starts with a lower-case letter. Follow whatever your project already does; consistency matters more than either style.


### Add trailers for links and credit


Lines at the end of the body in the form `Key: value` are called trailers. Hosts and tools understand several of them.


```bash
Fixes #482
Co-authored-by: Sam Lee <sam@example.com>
```


## Common pitfalls

- **Vague subjects.** "Fix bug", "Update", "WIP" and "changes" tell readers nothing. Name the behaviour that changed.
- **Describing the code instead of the reason.** "Change timeout to 30" is in the diff. "Raise timeout because the export job takes 20 seconds" is not.
- **Very long subjects.** They are cut off in most tools. Move the detail to the body.
- **Relying only on an issue link.** Links break and trackers move. Summarise the reason in the message itself.
- **Leaving "fix typo" commits in a pull request.** Squash or fix them up before merging so the history stays readable.

## Related reading

- [git-scm.com: git commit (discussion of message format)](https://git-scm.com/docs/git-commit#_discussion)
- [git-scm.com: Contributing to a project](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project)
