Git Commit with Conventional Commits
Overview
Create standardized, semantic git commits using the Conventional Commits specification. Analyze the actual diff to determine appropriate type, scope, and message.
Conventional Commit Format
CODEBLOCK0
Commit Types
| Type | Purpose |
|---|
| INLINECODE0 | New feature |
| INLINECODE1 |
Bug fix |
|
docs | Documentation only |
|
style | Formatting/style (no logic) |
|
refactor | Code refactor (no feature/fix) |
|
perf | Performance improvement |
|
test | Add/update tests |
|
build | Build system/dependencies |
|
ci | CI/config changes |
|
chore | Maintenance/misc |
|
revert | Revert commit |
Breaking Changes
CODEBLOCK1
Workflow
1. Analyze Diff
CODEBLOCK2
2. Stage Files (if needed)
If nothing is staged or you want to group changes differently:
CODEBLOCK3
Never commit secrets (.env, credentials.json, private keys).
3. Generate Commit Message
Analyze the diff to determine:
- - Type: What kind of change is this?
- Scope: What area/module is affected?
- Description: One-line summary of what changed (present tense, imperative mood, <72 chars)
Language: Use Chinese (简体中文) for commit messages.
AI-GEN Footer: Add a footer line to indicate AI-generated code percentage:
CODEBLOCK4
- -
<percentage>: Percentage of AI-generated code in this commit - INLINECODE12 : Number of lines changed by AI
- INLINECODE13 : The AI model used (e.g., glm-5, Claude Opus 4.6)
Example:
CODEBLOCK5
4. Execute Commit
CODEBLOCK6
Best Practices
- - One logical change per commit
- Present tense: "add" not "added"
- Imperative mood: "fix bug" not "fixes bug"
- Reference issues:
Closes #123, INLINECODE15 - Keep description under 72 characters
- Use Chinese (简体中文) for commit messages
- Include AI-GEN footer to indicate AI-generated code percentage
Git Safety Protocol
- - NEVER update git config
- NEVER run destructive commands (--force, hard reset) without explicit request
- NEVER skip hooks (--no-verify) unless user asks
- NEVER force push to main/master
- If commit fails due to hooks, fix and create NEW commit (don't amend)
技能名称: git-commit
详细描述:
遵循约定式提交规范的 Git 提交
概述
使用约定式提交规范创建标准化、语义化的 Git 提交。分析实际差异以确定合适的类型、范围和消息。
约定式提交格式
<类型>[可选范围]: <描述>
[可选正文]
[可选脚注]
提交类型
错误修复 |
| docs | 仅文档变更 |
| style | 格式/样式(无逻辑变更) |
| refactor | 代码重构(非功能/修复) |
| perf | 性能改进 |
| test | 添加/更新测试 |
| build | 构建系统/依赖项 |
| ci | CI/配置变更 |
| chore | 维护/杂项 |
| revert | 回退提交 |
破坏性变更
类型/范围后加感叹号
feat!: 移除已弃用的端点
BREAKING CHANGE 脚注
feat: 允许配置扩展其他配置
BREAKING CHANGE: extends 键行为已更改
工作流程
1. 分析差异
bash
如果文件已暂存,使用暂存区差异
git diff --staged
如果未暂存任何内容,使用工作区差异
git diff
同时检查状态
git status --porcelain
2. 暂存文件(如需要)
如果未暂存任何内容或希望以不同方式分组更改:
bash
暂存特定文件
git add path/to/file1 path/to/file2
按模式暂存
git add
.test.
git add src/components/*
交互式暂存
git add -p
切勿提交机密信息(.env、credentials.json、私钥)。
3. 生成提交消息
分析差异以确定:
- - 类型:这是什么类型的更改?
- 范围:影响哪个区域/模块?
- 描述:更改内容的一行摘要(现在时,祈使语气,<72 个字符)
语言:提交消息使用中文(简体中文)。
AI-GEN 脚注:添加脚注行以指示 AI 生成代码的百分比:
AI-GEN: <百分比>%/<行数>行 <模型名>
- - <百分比>:此提交中 AI 生成代码的百分比
- <行数>:AI 更改的行数
- <模型名>:使用的 AI 模型(例如 glm-5、Claude Opus 4.6)
示例:
AI-GEN: 100%/3行 glm-5
4. 执行提交
bash
单行
git commit -m <类型>[范围]: <描述>
带正文/脚注的多行(中文,含 AI-GEN)
git commit -m $(cat <
[范围]: <中文描述>
<可选的详细说明>
AI-GEN: <占比>%/<行数>行 <模型名>
EOF
)
最佳实践
- - 每次提交只包含一个逻辑变更
- 使用现在时:add 而非 added
- 使用祈使语气:fix bug 而非 fixes bug
- 引用问题:Closes #123、Refs #456
- 描述保持在 72 个字符以内
- 提交消息使用中文(简体中文)
- 包含 AI-GEN 脚注以指示 AI 生成代码的百分比
Git 安全协议
- - 绝不更新 git 配置
- 未经明确请求,绝不运行破坏性命令(--force、hard reset)
- 除非用户要求,绝不跳过钩子(--no-verify)
- 绝不强制推送到 main/master 分支
- 如果提交因钩子失败,修复后创建新提交(不修改原提交)