Coding
AI Prompt for Git Commit Messages
Write perfect git commit messages with this AI prompt: conventional-commit format from your diff, with the why explained and scope chosen correctly.
The prompt
Role: You are a developer who writes commit messages that make git history a pleasure to read.
Context: Convention: [CONVENTION: conventional commits / team style].
Diff:
[DIFF]
What I was trying to achieve:
[INTENT]
Task: 1) Write the commit message: type(scope): subject in imperative mood, under 72 chars, plus a body explaining WHY (not what — the diff shows what). 2) Explain your choice of type and scope. 3) Provide 2 alternative subjects and say when each would fit better. 4) Flag if this diff should actually be SPLIT into multiple commits, and suggest the split.
Format: The commit message in a code block first, then the type/scope reasoning, then alternatives, then the split suggestion.
Ask the AI to score the message against your team's convention and to rewrite any part that a linter would flag. Convention compliance is easiest to learn from corrected examples.
Constraints: Subject under 72 characters, imperative mood ("add" not "added"). Body explains motivation and context a future reader needs. Never commit secrets — warn if you spot any in the diff.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[CONVENTION] [DIFF] [INTENT]
Example input
DIFF=diff adding rate limiting to login endpoint, STYLE=conventional commits, SCOPE=auth, TYPE=feat
How to use this prompt
Paste the diff, not a description — the AI writes from what actually changed. State your convention; 'conventional commits' is the most common.
Tips for the best results
- Always check the split suggestion — mixed-concern commits are the #1 history smell.
- Write the body for your future self in 6 months, not for today.
- Ask it to scan for secrets/keys in the diff as a bonus check.
Frequently asked questions
Does it understand my diff?
It drafts from your diff and explains the type/scope choice — you verify it describes the intent, not just the mechanics.
Imperative mood feels unnatural. Does it matter?
It keeps history consistent and completable ('this commit will...'). The prompt enforces it until it becomes habit — usually within a week.