Use this skill when the user explicitly asks to generate a commit message, organize commit descriptions, or mentions commit-msg.
Do not use for:
- Automatically executing
git addorgit commit - replacing formal code review
- generating release notes or changelog
Core approach
- By default, look at staged changes first; when the user explicitly says
all, all changes, or including unstaged changes, then look at the entire workspace diff. - First determine whether this batch of changes is suitable for one commit; if it is too mixed, first remind the user to split it.
- Classify according to the intent of the changes as
feat、fix、refactor、style、docs、testorchore。 - First provide one ready-to-use subject, then provide 2-5 body bullet points.
- Also list the main changed files, to help the user judge whether the message is too broad.
Output requirements
- Use Conventional Commit style:
<type>: <subject> subjectconcise and focused, do not pile up file names- Output language:
typekeep keywords in English (feat/fix/refactor/style/docs/test/chore),subjectandbodymust use Simplified Chinese bodyuse flat bullets, explaining the core changes- Do not add emoji, AI statements, or
Co-Authored-By - Do not execute the commit command on behalf of the user
Write-to-disk command (mandatory heredoc)
After outputting the message, you must additionally provide a directly copyable and executable heredoc command, so that git correctly preserves the structure of single-line subject + blank line + multi-line body bullets:
git add <文件列表> && git commit -m "$(cat <<'EOF'
<type>: <subject>
- 变更点1
- 变更点2
- 变更点3
EOF
)"
<<'EOF' Use single-quote fencing to avoid $, backticks being expanded by the shell.
Forbidden counterexamples
- ❌
git commit -m "feat: x\n- a\n- b"——\nis a literal string, the shell will not parse it as a newline, and the whole thing will be stuffed into the subject line. - ❌
git commit -m "feat: x - a - b"— the body is compressed into a single line, losing the markdown list structure, and GitHub Release /git logcannot render correctly. - ❌ Concatenating multiple bullets into the subject with spaces — the subject should remain a single topic, with a maximum length of no more than 80 characters.
Self-verification
After writing to disk, use git log -1 --pretty=format:'%s%n---%n%b' to check: the subject must be a single line, and the body must preserve each line's independent - bullet。
Expand as needed
- Type selection:
references/commit-types.md - Format constraints:
references/message-format.md