AgentSkillsCN

commit

自动分析代码变更,并生成结构清晰的常规提交信息。在被要求提交代码更改、创建提交记录,或执行 /commit 命令时,运用此技能。

SKILL.md
--- frontmatter
name: commit
description: Automatically analyze changes and create organized conventional commits. Use this skill when asked to commit code changes, create commits, or when running /commit.

Auto Commit with Convention

Automatically analyze git changes and create organized, conventional commits.

Commit Message Format

code
type(scope): description

or without scope:

code
type: description

Valid Types

TypeDescriptionExample
featNew featureNew component, new API endpoint
fixBug fixResolve hover state issue
docsDocumentationUpdate README, add comments
styleFormattingPrettier, fix indentation
refactorCode restructuringExtract utility, simplify logic
perfPerformanceOptimize render, lazy load
testTestsAdd unit tests, E2E tests
choreMaintenanceUpdate dependencies, config
revertRevert commitRevert previous changes

Types must be lowercase.

Scope

  • Use scope when changes are specific to a module/feature
  • Omit scope for project-wide changes
  • Derive scope from folder structure (e.g., src/hooks/hooks)

Workflow

1. Analyze Changes

bash
git status --short
git diff --staged
git diff

Decision:

  • Both staged and unstaged → Ask user which to commit
  • Only staged → Proceed with staged
  • Only unstaged → Ask if should stage all
  • No changes → Inform and exit

2. Group Changes

Group by logical scope based on file paths:

code
src/components/**    → scope: components
src/hooks/**         → scope: hooks
src/server/**        → scope: server
src/db/**            → scope: db
src/lib/**           → scope: lib
Root/multiple        → no scope

Special cases:

  • Multiple scopes → Split into separate commits
  • Root config files → No scope, use chore:

3. Determine Type

ChangesType
New files, new featuresfeat
Bug fixesfix
*.md, docs/docs
Formatting onlystyle
Code restructuringrefactor
Performanceperf
.test. filestest
package.json, configschore

4. Generate Messages

Rules:

  • Imperative mood: "add" not "added"
  • Lowercase descriptions
  • Concise but specific
  • Max ~72 characters

Examples:

code
feat(components): add user profile card
fix(hooks): resolve infinite loop in useQuery
docs: update README with setup instructions
chore: upgrade dependencies
refactor(server): extract validation logic
test(db): add unit tests for user queries

5. Present Plan

code
📋 Planned commits:

1. feat(components): add user profile card
   Files:
   - src/components/user-profile.tsx

2. fix(hooks): resolve infinite loop
   Files:
   - src/hooks/use-user.ts

───────────────────────────────────────
Total: 2 commits

Proceed? (yes/no)

Always get user confirmation before creating commits.

6. Create Commits

bash
git add <files>
git commit -m "$(cat <<'EOF'
type(scope): description
EOF
)"
git log -1 --oneline

7. Edge Cases

ScenarioAction
No changesInform user
Mixed types same scopeSplit commits
Description too longUse commit body
User wants to editAllow override

Best Practices

✅ DO:

  • Group logically related changes
  • Atomic commits (complete, working change)
  • Single responsibility per commit
  • Clear descriptions

❌ DON'T:

  • Mix feat + fix in one commit
  • Vague descriptions ("fix bug")
  • Past tense ("added" → "add")
  • Trailing periods
  • Add Co-Authored-By lines

Reference

See docs/commit-message.md for detailed commit convention rules.