提交准备技能
自动准备遵循传统提交标准的提交消息。
激活
此技能在以下关键词激活:
- “提交”, “准备提交”, “提交这个”
- “提交消息”, “写提交”
- “阶段和提交”, “提交更改”
- “我应该提交什么”, “准备提交”
工作流程
当激活时,请按照以下步骤操作:
1. 收集上下文
运行这些命令以了解正在提交的内容:
# 查看所有更改
git status
# 已暂存的更改(将被提交的内容)
git diff --cached --stat
git diff --cached
# 未暂存的更改(尚未提交)
git diff --stat
2. 分析更改
确定:
- 类型:feat, fix, docs, refactor, test, chore, perf, ci
- 范围:哪个组件/模块受影响(可选)
- 破坏性:是否有破坏性更改?
- 什么:更改了什么
- 为什么:为什么更改(如果不显而易见)
3. 生成提交消息
遵循传统提交格式:
<type>(<scope>): <subject>
<body>
<footer>
类型参考
| 类型 | 何时使用 | 示例 |
|---|---|---|
feat |
新功能 | feat: add user authentication |
fix |
修复bug | fix: resolve null pointer in parser |
docs |
仅文档 | docs: update API reference |
refactor |
代码重构 | refactor: extract validation logic |
test |
添加/修复测试 | test: add unit tests for auth |
perf |
性能改进 | perf: optimize database queries |
chore |
维护,依赖 | chore: update dependencies |
ci |
CI/CD更改 | ci: add caching to workflow |
style |
仅格式化 | style: fix indentation |
规则
- 主题:祈使语气(“add” 不是 “added”),无句号,最多50个字符
- 正文:72个字符换行,解释什么和为什么(不是怎么做)
- 页脚:破坏性更改,问题参考
4. 处理暂存
如果有未暂存的更改,询问:
- “暂存所有更改?”(
git add .) - “暂存特定文件?”(列出它们)
- “首先审查更改?”(显示差异)
5. 执行提交
用户确认消息后:
git add <files>
git commit -m "<message>"
重要:始终对多行提交使用HEREDOC:
git commit -m "$(cat <<'EOF'
feat: add user authentication
Implement OAuth2 flow with Google and GitHub providers.
Includes session management with secure cookies.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
### 6. 提交后
提交成功后:
- 显示`git log -1`以确认
- 如果准备好,建议`git push`
- 提及如果还有更多未暂存的更改
## 示例交互
### 简单提交
**用户**:"提交这些更改"
**Claude**:
```bash
git status
git diff --cached
查看您的暂存更改:
- 修改
src/auth/oauth.py- 添加令牌刷新逻辑 - 修改
tests/test_auth.py- 添加刷新测试
建议提交:
feat(auth): add OAuth token refresh
Implement automatic token refresh when access token expires.
Includes retry logic with exponential backoff.
我可以用这个消息提交吗?
破坏性更改
用户:“准备提交”
Claude:我看到您更改了API响应格式。这是一个破坏性更改。
建议提交:
feat(api)!: change response envelope format
BREAKING CHANGE: API responses now use { data, meta, errors }
envelope instead of flat response. Clients must update parsing.
Migration: Update response handlers to access .data property.
这将其标记为带有!的破坏性更改。继续吗?
多个逻辑更改
用户:“提交这个”
Claude:我看到多个不相关的区域发生了更改:
- 在
parser.py中修复bug - 在
export.py中新增功能 - 更新文档
建议分成单独的提交:
fix(parser): handle empty input gracefullyfeat(export): add CSV export optiondocs: update export documentation
想要我帮助暂存并分别提交每个吗?
归属
始终包括Claude归属以AI辅助提交:
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
安全规则
- 永不在推送的提交上使用
git commit --amend - 永不跳过钩子使用
--no-verify除非明确要求 - 始终在执行前显示提交消息
- 检查暂存文件中的机密/凭据
- 警告大的二进制文件