Coding & Automation prompt
AI Prompt to Write Clear Git Commit Messages From a Diff
CursorClaude CodeChatGPTGitHub Copilot
The short answer
Paste your diff, get a Conventional Commits message that explains why, not just what. Retire "fix stuff" forever. Copy the prompt below, replace the 5 [BRACKETED] variables with your own, and paste it into Cursor, Claude Code, ChatGPT or GitHub Copilot.
You are a senior engineer who writes commit messages that future maintainers thank you for. A good message explains why the change was made, not just what changed.
CONTEXT
- Commit convention: [CONVENTION] (for example Conventional Commits, team format, or "none")
- Ticket or issue reference, if any: [TICKET_ID]
- Why I made this change (the problem, in one or two sentences): [REASON_FOR_CHANGE]
- The diff (output of git diff --staged):
[STAGED_DIFF]
TASK
1. Read the diff and identify the logical changes it contains.
2. If the diff mixes unrelated changes (for example a bug fix plus a refactor plus formatting), say so and propose how to split it into separate commits, with a message for each.
3. Otherwise, write one commit message.
RULES
- Subject line: imperative mood ("Add", "Fix", not "Added" or "Fixes"), aim for 50 characters and never exceed 72, no trailing period.
- If using Conventional Commits, pick the correct type (feat, fix, refactor, perf, docs, test, build, ci, chore) and an optional scope. Mark breaking changes with ! and a BREAKING CHANGE footer.
- Body: wrap at 72 characters. Explain why the change was needed and any important consequences or trade-offs.
- Do not narrate the diff line by line. Do not describe things the diff does not show.
- If REASON_FOR_CHANGE is empty and the reason is not obvious from the diff, write [REASON_NEEDED] in the body rather than inventing a reason.
- Add the ticket reference as a footer if provided.
OUTPUT FORMAT
The commit message in a code block, ready to paste. If you proposed a split, list each commit's files and message in order. Then one line flagging anything in the diff that looks accidental (debug logs, commented-out code, secrets, unrelated files).What to fill in
Everything in [GOLD CAPS] is yours to replace. Leave one blank and the machine will guess — and the machine guesses like a meatbag on a Monday.
[CONVENTION][TICKET_ID][REASON_FOR_CHANGE][STAGED_DIFF][REASON_NEEDED]
How to use it
- Always fill in the reason. The diff tells the model what changed; only you know why, and why is the entire point of a commit message.
- Pay attention to the "looks accidental" line. Catching a stray console.log or an API key before it hits main is worth more than any message.
- In Claude Code or Cursor you can skip the paste: tell it to run git diff --staged itself and apply these rules.
Example
CONVENTION: Conventional Commits
TICKET_ID: PAY-412
REASON_FOR_CHANGE: refunds on old charges were failing silently; we now show a clear error instead
Sample subject: fix(refunds): show clear error when refund window has passedWorks with
Tested for Cursor, Claude Code, ChatGPT, GitHub Copilot. Any modern chat model that follows long instructions will cope; the weaker ones will need you to restate the output format if they drift.
Weapons from the Arsenal that pair well with this prompt:
- Claude Code — Anthropic's agentic coding tool that reads your codebase, edits files and runs commands from terminal, IDE, desktop or web.
- Cursor — AI-first code editor (a VS Code fork) with agents, codebase-aware chat and fast autocomplete.
- GitHub Copilot — GitHub's AI pair programmer: completions, chat and coding agents across editors and GitHub itself.