commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommit 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
提交类型
| Type | Description | Example |
|---|---|---|
| New feature or functionality | |
| Bug fix | |
| Documentation changes only | |
| Code style (formatting, semicolons, no logic change) | |
| Code change that neither fixes bug nor adds feature | |
| Performance improvement | |
| Adding or updating tests | |
| Build system or external dependencies | |
| CI/CD configuration changes | |
| Other changes (tooling, configs) | |
| Revert a previous commit | |
| 类型 | 说明 | 示例 |
|---|---|---|
| 新功能或特性 | |
| 修复Bug | |
| 仅修改文档 | |
| 代码样式调整(格式、分号等,无逻辑变更) | |
| 既不修复Bug也不添加功能的代码变更 | |
| 性能优化 | |
| 添加或更新测试 | |
| 构建系统或外部依赖变更 | |
| CI/CD配置变更 | |
| 其他变更(工具、配置等) | |
| 回滚之前的提交 | |
Scope Guidelines
范围指南
Scope should reflect the area of the codebase affected:
- Component names: ,
button,modalheader - Feature areas: ,
auth,cart,checkoutdashboard - Technical areas: ,
api,db,configdeps - File types: ,
types,hooks,utilsstyles
范围应体现受影响的代码库区域:
- 组件名称:、
button、modalheader - 功能领域:、
auth、cart、checkoutdashboard - 技术领域:、
api、db、configdeps - 文件类型:、
types、hooks、utilsstyles
Commit Workflow
提交工作流
Step 1: Check Current Status
步骤1:检查当前状态
bash
git statusReview what files have been modified, added, or deleted.
bash
git status查看已修改、添加或删除的文件。
Step 2: Review Changes
步骤2:查看变更内容
bash
git diff --stagedIf nothing is staged, check unstaged changes:
bash
git diffbash
git diff --staged如果没有暂存的变更,查看未暂存的变更:
bash
git diffStep 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 -AStep 4: Generate Commit Message
步骤4:生成提交信息
Analyze the staged changes and generate an appropriate commit message:
- Identify the primary change type - Is it a feature, fix, refactor, etc.?
- Determine the scope - What component/area is affected?
- Write a concise description - What does this change do? (imperative mood)
- Add body if needed - For complex changes, explain the "why"
分析暂存的变更并生成合适的提交信息:
- 确定主要变更类型 - 是功能、修复、重构还是其他类型?
- 确定范围 - 受影响的组件/区域是什么?
- 编写简洁描述 - 此变更实现了什么?(使用祈使语气)
- 必要时添加正文 - 对于复杂变更,说明“原因”
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:
- Analyze the diff to understand what changed
- Identify patterns:
- New files → likely or
feattest - Modified logic → could be ,
fix, orfeatrefactor - Only formatting →
style - Config files → or
chorebuild - Test files →
test - Documentation →
docs
- New files → likely
- Extract scope from file paths or component names
- Write description in imperative mood ("add" not "added")
- Keep it under 72 characters for the subject line
根据暂存变更生成提交信息时:
- 分析差异内容以了解变更点
- 识别模式:
- 新文件 → 可能是或
feat类型test - 逻辑修改 → 可能是、
fix或feat类型refactor - 仅格式调整 → 类型
style - 配置文件 → 或
chore类型build - 测试文件 → 类型
test - 文档 → 类型
docs
- 新文件 → 可能是
- 从文件路径或组件名称提取范围
- 使用祈使语气编写描述(用“add”而非“added”)
- 主题行长度控制在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 flowfeat(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 flowBad Commit Messages (Avoid)
需避免的不良提交信息示例
fix bug # Too vague
updated files # No context
WIP # Not descriptive
asdfasdf # Meaningless
feat: stuff # No scope, vague descriptionfix bug # 过于模糊
updated files # 无上下文
WIP # 描述性不足
asdfasdf # 无意义
feat: stuff # 无范围,描述模糊Breaking Changes
破坏性变更
For breaking changes, add after the type/scope and include in the footer:
!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.对于破坏性变更,在类型/范围后添加,并在页脚中包含:
!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
undefinedInstead 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"
undefinedgit 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"
undefinedExample Workflow
工作流示例
User: "commit my changes"
- Run to see changes
git status - Run (or
git diff --stagedif nothing staged)git diff - Analyze the changes
- Suggest: "Based on your changes, I recommend:"
feat(dashboard): add user activity chart component - Ask: "Should I commit with this message, or would you like to modify it?"
- Execute the commit
用户:“提交我的变更”
- 运行查看变更
git status - 运行(如果没有暂存变更则运行
git diff --staged)git diff - 分析变更内容
- 建议:“根据你的变更,我推荐使用以下提交信息:”
feat(dashboard): add user activity chart component - 询问:“是否使用此信息提交,还是需要修改?”
- 执行提交
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