AgentSkillsCN

commit-messages

在撰写 Git 提交信息或遵循 Conventional Commits 规范时——切勿用于 PR 文本;提交信息应简洁明了,以“为什么”为先,清晰阐述变更的动机与范围。

SKILL.md
--- frontmatter
name: commit-messages
description: WHEN writing git/conventional commits; NOT for PR text; returns concise, why-first commit lines with proper type/scope.

Commit Messages

Use this skill to generate clear, conventional commit messages that explain the "why" not just the "what". Follow this guide when writing commit messages or helping users structure their commits.

When to Use

  • User asks for help writing a commit message
  • User wants to understand conventional commit format
  • User needs to split a large commit into smaller ones
  • User asks about commit best practices

Philosophy

  • Why > What - The diff shows what changed; the message explains why
  • Atomic commits - One logical change per commit
  • Future readers - Write for someone debugging at 2am in 6 months
  • Searchable - Make it easy to find with git log --grep

Format

Follow Conventional Commits:

code
type(scope): subject

body (optional)

footer (optional)

Types

TypeWhen to UseExample
featNew feature for the userfeat(auth): add password reset flow
fixBug fix for the userfix(cart): correct quantity calc
docsDocumentation only changesdocs: update API examples
styleFormatting, white-space (not CSS)style: format with biome
refactorCode change that neither fixes nor addsrefactor: extract validation utils
perfPerformance improvementperf: memoize expensive calculation
testAdding or updating teststest: add auth integration tests
buildBuild system or dependenciesbuild: upgrade to node 22
ciCI configurationci: add playwright to pipeline
choreOther changes that don't modify src/test fileschore: update .gitignore

Rules

Subject Line

RuleGoodBad
Imperative moodadd user profileadded user profile
No capitalizationfix login bugFix login bug
No periodupdate readmeupdate readme.
Be specificfix redirect loop on session expiryfix bug
Max 50 chars (72 hard limit)Keep it conciseDon't write essays

Scope (optional)

  • Component or area: feat(auth):, fix(api):, test(cart):
  • Keep consistent within project
  • Omit if change spans multiple areas

Body (when needed)

  • Wrap at 72 characters
  • Explain why this change was necessary
  • Include context that isn't obvious from the diff
  • Reference issues: Fixes #123 or Relates to #456

Breaking Changes

code
feat(api)!: change authentication endpoint

BREAKING CHANGE: /auth/login now requires email instead of username.
Migration: Update all clients to send email field.

Commit Scope Assessment

Before writing the message, assess whether the staged changes should be one commit or multiple.

Signs to Split

SignalAction
Changes to unrelated filesSplit by feature/area
Multiple types (feat + fix)Separate commits
"and" in your subject lineProbably two commits
> 10 files changedConsider splitting
Mix of refactor + featureRefactor first, then feature

Good Split Example

Instead of:

code
feat: add user profile and fix login redirect and update tests

Split into:

code
fix(auth): prevent redirect loop on session expiry
feat(profile): add user profile page
test(auth): add session expiry tests

Examples

Good

code
feat(cart): add quantity selector to cart items

Allow users to update item quantities directly from the cart
instead of navigating back to the product page.

Closes #234
code
fix(auth): prevent redirect loop on expired session

Session expiry was triggering a redirect to login, which then
redirected back to the protected route, causing an infinite loop.

Now we clear the redirect URL when session expires.
code
refactor: extract validation logic to shared utilities

Consolidates duplicate Zod schemas from three API routes into
a single source of truth in lib/validation.

No behavior changes.
code
perf(search): debounce search input to reduce API calls

Search was firing on every keystroke, causing 10+ requests
for a typical query. Now waits 300ms after typing stops.

Reduces search API calls by ~80% based on local testing.

Bad

MessageProblem
fixed stuffToo vague - what stuff?
Updated the codeObvious - adds no value
WIPNot ready to commit
fix: Fix the bugRedundant, no detail
misc changesMeaningless
feat: add new featureWhat feature?
refactor codeWhat code? Why?

Output Format

When generating commit messages, provide the complete message ready to use:

code
type(scope): clear subject line

Optional body explaining the motivation for this change.
Include context that helps future readers understand why
this was done, not just what was done.

Fixes #123

If the commit should be split, recommend splitting with specific guidance:

markdown
**Recommendation: Split this commit**

The staged changes include multiple unrelated changes:

1. [Change type 1] - [files affected]
2. [Change type 2] - [files affected]

**Suggested commits:**

1. First commit:

type(scope): first change

code

2. Second commit:

type(scope): second change

code

**To split:** Use `git reset HEAD` then stage files for each commit separately.