General
From git diff to a Clean Commit Message in 30 Seconds
Table of contents
The 30-second workflowWorked exampleWhyTestedSubject-line rules that survive reviewWhy the body matters more than the subjectLet a tool draft it, then check the intentThe commit message is the last thing you write and the first thing a reviewer reads. Written tired, it comes out as "fix stuff" or "update code" — and six months later,
Say your diff looks like this — a small change to a user endpoint:
Step 1 — intent. Before: requesting a missing user crashed the handler (calling
Step 2 — type and scope. This fixes broken behavior, so the type is
Step 3 — subject.
Imperative mood ("return", not "returns" or "returned"), under 50 characters after the prefix, no trailing period. A reviewer scanning
Step 4 — body (the why).
Step 5 — PR description. Same material, one extra line:
Total writing time: about half a minute, because steps 3–5 reuse the same two facts (what changed, why) instead of inventing new text each time.
Reviewers can always see *what* changed — the diff shows them. What they cannot see is *why*: which bug report, which edge case, which alternative you rejected. That context exists only in your head at commit time, and it is exactly what someone debugging this code in six months will need. Two honest lines of why are worth more than a perfectly formatted subject with no body.
If you want the full format reference — types, scopes, breaking-change footers — our Conventional Commits guide covers the spec in depth, and how to write commit messages that aren't rejected covers the English side. Teams that want this enforced automatically can also add a pre-commit hook so the message gets checked before it lands.
The mechanical part — turning a diff into a typed subject, a body, and a PR description — is exactly what the free commit & PR generator does: paste the diff, get the draft. One honest caveat: a generator can see what changed, but it cannot know why you changed it. Read the draft, fix the why-line so it matches your actual reason, and then commit. That ten-second check is the difference between a message that helps your future self and one that merely looks tidy.
git log cannot tell you why anything changed. This is a 30-second workflow for going from a raw git diff to a commit message and PR description that reviewers actually read, with a worked example.Have a diff open right now? Paste it in and get a Conventional Commits message plus a PR description draft — free, no account.
Generate my commit message →Free, no signup for your first checks.The 30-second workflow
- Read the diff for intent, not lines. Run
git diff(orgit diff --staged) and answer one question: what behavior changed? Ignore formatting noise; find the one change that matters. - Classify it. Bug fix, new feature, refactor, docs, test, chore? That single word becomes the Conventional Commits type, and it tells reviewers how carefully to read.
- Write the subject. Type, optional scope, then an imperative summary: what this commit does, not what you did.
- Add the why. Two or three lines in the body: the bug report, the edge case, the tradeoff. The diff already shows the what; only you know the why.
- Reuse it for the PR. Subject becomes the PR title; the why becomes the PR description's first paragraph. Add a "how I tested it" line and you are done.
Worked example
Say your diff looks like this — a small change to a user endpoint:
diff --git a/api/users.py b/api/users.py
--- a/api/users.py
+++ b/api/users.py
@@ -42,7 +42,9 @@ def get_user(user_id):
user = db.query(User).get(user_id)
- return user.to_dict()
+ if user is None:
+ raise NotFoundError(f"user {user_id} not found")
+ return user.to_dict()
Step 1 — intent. Before: requesting a missing user crashed the handler (calling
.to_dict() on None) and returned a 500 with a stack trace. After: it raises a clean not-found error. The behavior change is "missing user now returns 404 instead of crashing."Step 2 — type and scope. This fixes broken behavior, so the type is
fix. The change lives in the API layer, so the scope is api.Step 3 — subject.
fix(api): return 404 instead of crashing on missing user
Imperative mood ("return", not "returns" or "returned"), under 50 characters after the prefix, no trailing period. A reviewer scanning
git log --oneline knows exactly what this commit does without opening it.Step 4 — body (the why).
fix(api): return 404 instead of crashing on missing user
GET /users/{id} with an unknown id raised AttributeError on
None.to_dict() and surfaced as a 500. Raise NotFoundError so the
error handler returns a clean 404 with the id in the message.
Step 5 — PR description. Same material, one extra line:
## What
Missing-user requests now return 404 instead of a 500 crash.Why
Clients were seeing stack traces for a routine not-found case.Tested
Manual: GET /users/999999 returns 404 with error body.
Existing user-endpoint tests pass.
Total writing time: about half a minute, because steps 3–5 reuse the same two facts (what changed, why) instead of inventing new text each time.
Subject-line rules that survive review
- Imperative mood. "Add", "fix", "remove" — as if completing the sentence "this commit will…".
- One change per subject. If you need "and" twice, the commit probably should have been two commits.
- Say what and where, not how. "fix(api): return 404 on missing user" beats "fix(api): add None check in get_user" — the how is visible in the diff.
- Keep it short. Around 50 characters for the summary keeps
git log --onelinereadable; details belong in the body.
Why the body matters more than the subject
Reviewers can always see *what* changed — the diff shows them. What they cannot see is *why*: which bug report, which edge case, which alternative you rejected. That context exists only in your head at commit time, and it is exactly what someone debugging this code in six months will need. Two honest lines of why are worth more than a perfectly formatted subject with no body.
If you want the full format reference — types, scopes, breaking-change footers — our Conventional Commits guide covers the spec in depth, and how to write commit messages that aren't rejected covers the English side. Teams that want this enforced automatically can also add a pre-commit hook so the message gets checked before it lands.
Let a tool draft it, then check the intent
The mechanical part — turning a diff into a typed subject, a body, and a PR description — is exactly what the free commit & PR generator does: paste the diff, get the draft. One honest caveat: a generator can see what changed, but it cannot know why you changed it. Read the draft, fix the why-line so it matches your actual reason, and then commit. That ten-second check is the difference between a message that helps your future self and one that merely looks tidy.
📌 Prices and tool count in this article may be outdated. Lint now ships 16 tools with Pro at $12/mo, or $39/year founding. See the current pricing page.
Stop letting Grammarly break your code
18 AI and browser tools built for developers. Code-aware parsing.
Or upgrade to Pro for 500 checks a day · All tools · No ads