commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Commit Skill

Git提交技能

Generate meaningful, well-structured git commits following Conventional Commits specification.
生成符合Conventional Commits规范、有意义且结构清晰的Git提交信息。

When to Use This Skill

何时使用此技能

Use this skill when the user:
  • Asks to "commit" or "make a commit"
  • Says "commit my changes" or "save my work"
  • Wants help writing a commit message
  • Asks "what should I commit?"
  • Needs to commit after completing a task
当用户有以下需求时使用此技能:
  • 要求“提交”或“创建提交”
  • 说“提交我的变更”或“保存我的工作”
  • 需要帮助编写提交信息
  • 询问“我应该提交什么?”
  • 完成任务后需要提交

Conventional Commits Format

Conventional Commits格式

All commits must follow this format:
<type>(<scope>): <description>

[optional body]

[optional footer(s)]
所有提交必须遵循以下格式:
<type>(<scope>): <description>

[可选正文]

[可选页脚]

Commit Types

提交类型

TypeDescriptionExample
feat
New feature or functionality
feat(auth): add login with Google
fix
Bug fix
fix(cart): resolve quantity update issue
docs
Documentation changes only
docs(readme): update installation steps
style
Code style (formatting, semicolons, no logic change)
style(button): fix indentation
refactor
Code change that neither fixes bug nor adds feature
refactor(api): simplify error handling
perf
Performance improvement
perf(query): optimize database lookup
test
Adding or updating tests
test(auth): add login unit tests
build
Build system or external dependencies
build(deps): upgrade react to v19
ci
CI/CD configuration changes
ci(github): add deploy workflow
chore
Other changes (tooling, configs)
chore(eslint): update lint rules
revert
Revert a previous commit
revert: undo login changes
类型说明示例
feat
新功能或特性
feat(auth): add login with Google
fix
修复Bug
fix(cart): resolve quantity update issue
docs
仅修改文档
docs(readme): update installation steps
style
代码样式调整(格式、分号等,无逻辑变更)
style(button): fix indentation
refactor
既不修复Bug也不添加功能的代码变更
refactor(api): simplify error handling
perf
性能优化
perf(query): optimize database lookup
test
添加或更新测试
test(auth): add login unit tests
build
构建系统或外部依赖变更
build(deps): upgrade react to v19
ci
CI/CD配置变更
ci(github): add deploy workflow
chore
其他变更(工具、配置等)
chore(eslint): update lint rules
revert
回滚之前的提交
revert: undo login changes

Scope Guidelines

范围指南

Scope should reflect the area of the codebase affected:
  • Component names:
    button
    ,
    modal
    ,
    header
  • Feature areas:
    auth
    ,
    cart
    ,
    checkout
    ,
    dashboard
  • Technical areas:
    api
    ,
    db
    ,
    config
    ,
    deps
  • File types:
    types
    ,
    hooks
    ,
    utils
    ,
    styles
范围应体现受影响的代码库区域:
  • 组件名称
    button
    modal
    header
  • 功能领域
    auth
    cart
    checkout
    dashboard
  • 技术领域
    api
    db
    config
    deps
  • 文件类型
    types
    hooks
    utils
    styles

Commit Workflow

提交工作流

Step 1: Check Current Status

步骤1:检查当前状态

bash
git status
Review what files have been modified, added, or deleted.
bash
git status
查看已修改、添加或删除的文件。

Step 2: Review Changes

步骤2:查看变更内容

bash
git diff --staged
If nothing is staged, check unstaged changes:
bash
git diff
bash
git diff --staged
如果没有暂存的变更,查看未暂存的变更:
bash
git diff

Step 3: Stage Changes

步骤3:暂存变更

Stage specific files:
bash
git add <file1> <file2>
Or stage all changes:
bash
git add -A
暂存指定文件:
bash
git add <file1> <file2>
或暂存所有变更:
bash
git add -A

Step 4: Generate Commit Message

步骤4:生成提交信息

Analyze the staged changes and generate an appropriate commit message:
  1. Identify the primary change type - Is it a feature, fix, refactor, etc.?
  2. Determine the scope - What component/area is affected?
  3. Write a concise description - What does this change do? (imperative mood)
  4. Add body if needed - For complex changes, explain the "why"
分析暂存的变更并生成合适的提交信息:
  1. 确定主要变更类型 - 是功能、修复、重构还是其他类型?
  2. 确定范围 - 受影响的组件/区域是什么?
  3. 编写简洁描述 - 此变更实现了什么?(使用祈使语气)
  4. 必要时添加正文 - 对于复杂变更,说明“原因”

Step 5: Execute Commit

步骤5:执行提交

bash
git commit -m "<type>(<scope>): <description>"
For multi-line commits:
bash
git commit -m "<type>(<scope>): <description>" -m "<body>"
bash
git commit -m "<type>(<scope>): <description>"
对于多行提交信息:
bash
git commit -m "<type>(<scope>): <description>" -m "<body>"

AI Message Generation Rules

AI生成提交信息规则

When generating commit messages from staged changes:
  1. Analyze the diff to understand what changed
  2. Identify patterns:
    • New files → likely
      feat
      or
      test
    • Modified logic → could be
      fix
      ,
      feat
      , or
      refactor
    • Only formatting →
      style
    • Config files →
      chore
      or
      build
    • Test files →
      test
    • Documentation →
      docs
  3. Extract scope from file paths or component names
  4. Write description in imperative mood ("add" not "added")
  5. Keep it under 72 characters for the subject line
根据暂存变更生成提交信息时:
  1. 分析差异内容以了解变更点
  2. 识别模式
    • 新文件 → 可能是
      feat
      test
      类型
    • 逻辑修改 → 可能是
      fix
      feat
      refactor
      类型
    • 仅格式调整 →
      style
      类型
    • 配置文件 →
      chore
      build
      类型
    • 测试文件 →
      test
      类型
    • 文档 →
      docs
      类型
  3. 从文件路径或组件名称提取范围
  4. 使用祈使语气编写描述(用“add”而非“added”)
  5. 主题行长度控制在72字符以内

Message Quality Guidelines

提交信息质量指南

Good Commit Messages

优质提交信息示例

feat(auth): add password reset functionality
fix(cart): prevent negative quantity values
refactor(api): extract common error handling logic
docs(contributing): add PR template guidelines
test(checkout): add integration tests for payment flow
feat(auth): add password reset functionality
fix(cart): prevent negative quantity values
refactor(api): extract common error handling logic
docs(contributing): add PR template guidelines
test(checkout): add integration tests for payment flow

Bad Commit Messages (Avoid)

需避免的不良提交信息示例

fix bug                    # Too vague
updated files              # No context
WIP                        # Not descriptive
asdfasdf                   # Meaningless
feat: stuff                # No scope, vague description
fix bug                    # 过于模糊
updated files              # 无上下文
WIP                        # 描述性不足
asdfasdf                   # 无意义
feat: stuff                # 无范围,描述模糊

Breaking Changes

破坏性变更

For breaking changes, add
!
after the type/scope and include
BREAKING CHANGE:
in the footer:
feat(api)!: change authentication endpoint response format

BREAKING CHANGE: The /auth/login endpoint now returns { token, user } 
instead of just the token string.
对于破坏性变更,在类型/范围后添加
!
,并在页脚中包含
BREAKING CHANGE:
feat(api)!: change authentication endpoint response format

BREAKING CHANGE: The /auth/login endpoint now returns { token, user } 
instead of just the token string.

Multiple Changes

多类变更

If changes span multiple concerns, prefer atomic commits:
bash
undefined
如果变更涉及多个方面,建议拆分为原子提交:
bash
undefined

Instead of one big commit, split into logical units:

不要一次性提交所有内容,拆分为逻辑独立的单元:

git add src/components/Button.tsx git commit -m "refactor(button): extract common styles"
git add src/components/Button.test.tsx git commit -m "test(button): add accessibility tests"
undefined
git add src/components/Button.tsx git commit -m "refactor(button): extract common styles"
git add src/components/Button.test.tsx git commit -m "test(button): add accessibility tests"
undefined

Example Workflow

工作流示例

User: "commit my changes"
  1. Run
    git status
    to see changes
  2. Run
    git diff --staged
    (or
    git diff
    if nothing staged)
  3. Analyze the changes
  4. Suggest: "Based on your changes, I recommend:"
    feat(dashboard): add user activity chart component
  5. Ask: "Should I commit with this message, or would you like to modify it?"
  6. Execute the commit
用户:“提交我的变更”
  1. 运行
    git status
    查看变更
  2. 运行
    git diff --staged
    (如果没有暂存变更则运行
    git diff
  3. 分析变更内容
  4. 建议:“根据你的变更,我推荐使用以下提交信息:”
    feat(dashboard): add user activity chart component
  5. 询问:“是否使用此信息提交,还是需要修改?”
  6. 执行提交

Tips

小贴士

  • One logical change per commit - Makes history easier to navigate
  • Present tense, imperative mood - "add" not "adds" or "added"
  • No period at the end of the subject line
  • Capitalize the first letter of the description
  • Reference issues in the footer when applicable:
    Closes #123
  • 每次提交一个逻辑变更 - 让提交历史更易于浏览
  • 使用现在时、祈使语气 - 用“add”而非“adds”或“added”
  • 主题行末尾不要加句号
  • 描述的首字母大写
  • 适用时在页脚引用议题
    Closes #123