AgentSkillsCN

generate-commit-message

通过分析 Git 差异与暂存变更,按照 Conventional Commits 规范生成提交信息。适用于当用户需要提交信息、希望提交更改,或需要帮助撰写提交信息时使用。

SKILL.md
--- frontmatter
name: generate-commit-message
description: Generate commit messages following Conventional Commits specification by analyzing git diffs and staged changes. Use when the user asks for a commit message, wants to commit changes, or needs help writing commit messages.

Generate Commit Message

Generate commit messages that follow the Conventional Commits specification by analyzing git changes.

Process

  1. Analyze changes: Run git diff --cached for staged changes or git diff for unstaged changes
  2. Determine type: Identify the primary change type from the diff
  3. Identify scope: Extract the affected module/component (optional but recommended)
  4. Write description: Create a concise, imperative-mood description
  5. Add body (if needed): Include context for complex changes
  6. Check for breaking changes: Look for API changes, removed features, or schema changes

Commit Message Format

code
<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Types

TypeWhen to UseExample
featNew featurefeat(auth): add JWT token refresh
fixBug fixfix(reports): correct date formatting
docsDocumentation onlydocs: update API documentation
styleFormatting, missing semicolonsstyle: format code with prettier
refactorCode restructuringrefactor(users): extract validation logic
perfPerformance improvementperf(db): optimize query with index
testAdding/updating teststest(auth): add login tests
choreBuild tasks, dependencieschore: update dependencies
buildBuild system changesbuild: update webpack config
ciCI/CD changesci: add GitHub Actions workflow

Scope Guidelines

  • Use module/component name: feat(auth), fix(articles), refactor(database)
  • Use library name for libs: feat(s3), fix(email)
  • Omit scope for broad changes: chore: update dependencies
  • Use lowercase, no spaces

Description Guidelines

  • Use imperative mood: "add feature" not "added feature" or "adds feature"
  • Lowercase (except proper nouns)
  • No period at the end
  • Keep under 72 characters when possible
  • Be specific: "fix date parsing bug" not "fix bug"

Breaking Changes

Indicate breaking changes with ! after type/scope or BREAKING CHANGE: footer:

code
feat(api)!: change response format

BREAKING CHANGE: API now returns objects instead of arrays

Or:

code
feat!: remove deprecated endpoint

Examples

Simple feature

code
feat(auth): add password reset functionality

Bug fix with scope

code
fix(reports): correct timezone handling in date filters

Refactor with body

code
refactor(database): extract query builder logic

Move complex SQL generation to dedicated QueryBuilder class
to improve testability and maintainability.

Breaking change

code
feat(api)!: change pagination response structure

BREAKING CHANGE: Pagination now uses `page` and `per_page` instead of `offset` and `limit`

Multiple changes

If changes span multiple types, focus on the primary change or split into multiple commits:

code
feat(articles): add article categorization

- Add category field to article entity
- Update article service with category filtering
- Add category filter to article controller

Analysis Tips

  1. File patterns:

    • New files → usually feat
    • Test files → test
    • Config files → chore or build
    • Documentation → docs
  2. Change patterns:

    • Adding exports/endpoints → feat
    • Fixing logic errors → fix
    • Reorganizing code → refactor
    • Performance optimizations → perf
  3. Scope detection:

    • Look at directory structure: src/articles/articles
    • Check module names: ArticlesModulearticles
    • Library modules: libs/s3/s3
  4. Breaking changes:

    • Removed exports/functions
    • Changed function signatures
    • Changed response formats
    • Database schema changes (migrations)

Output Format

ALWAYS provide the full git commit command with the message:

bash
git commit -m "feat(scope): description"

For multi-line messages, format as:

bash
git commit -m "feat(scope): description" -m "Additional context line 1" -m "Additional context line 2"

Or use a commit message file if body is long.