generate-commit-message
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGenerate Commit Message
生成提交信息
Generate commit messages following cbea.ms guidelines.
遵循cbea.ms指南生成提交信息。
Output Format
输出格式
Default output: Plain text commit message in a code block with NO language tag.
The user should be able to copy the entire content directly. Do NOT include:
- wrapper
git commit -m - or HEREDOC syntax
EOF - language tag on the code block
bash - Extra commentary outside the code block
- trailers or any git trailers
Co-authored-by
默认输出:无语言标签的代码块形式纯文本提交信息。
用户应能直接复制全部内容。请勿包含:
- 包裹语句
git commit -m - 或HEREDOC语法
EOF - 代码块上的语言标签
bash - 代码块外的额外注释
- 或任何Git尾部信息
Co-authored-by
Short Example
简短示例
Add input validation to form componentsAdd input validation to form componentsDetailed Example
详细示例
Implement input validation for form components
- Create validation utility with reusable validators
- Add validators for email, phone, and text inputs
- Update Button and Input to use validationImplement input validation for form components
- Create validation utility with reusable validators
- Add validators for email, phone, and text inputs
- Update Button and Input to use validationFormat Options
格式选项
- Short (default): Subject line only (~50 chars)
- Detailed: Subject + bullet list body (3–6 bullets recommended)
When to use detailed:
- User explicitly requests: "detail", "detailed", "comprehensive", "full"
- Many changes: Ask preference before generating
Large change thresholds (trigger preference question):
- Files changed: 5+
- OR Insertions + deletions: 200+
- 简短模式(默认):仅主题行(约50字符)
- 详细模式:主题行 + 项目符号列表正文(建议3-6个项目符号)
何时使用详细模式:
- 用户明确要求:“detail”、“detailed”、“comprehensive”、“full”
- 变更内容较多:生成前询问用户偏好
大规模变更阈值(触发偏好询问):
- 变更文件数:5个及以上
- 或 插入+删除行数:200行及以上
Workflow
工作流程
- Run to see staged changes
git diff --staged --stat - If nothing is staged, ask the user to stage files
- Analyze
git diff --staged - Generate the commit message based only on staged changes
- Decide Short vs Detailed (rules above)
- Output the plain commit message in a code block (no language tag)
- 运行 查看已暂存的变更
git diff --staged --stat - 若无暂存内容,提示用户暂存文件
- 分析 的输出
git diff --staged - 仅基于已暂存的变更生成提交信息
- 决定使用简短模式还是详细模式(遵循上述规则)
- 以无语言标签的代码块形式输出纯文本提交信息
Commit Message Rules
提交信息规则
- Subject line ≤50 chars (warn at 50-72, error >72)
- Capitalize subject
- No period at end
- Imperative mood: "Add feature" not "Added feature"
- Blank line between subject and body
- Body lines ≤72 chars
- 主题行≤50字符(50-72字符时警告,超过72字符报错)
- 主题行首字母大写
- 主题行末尾无句号
- 使用祈使语气:例如用“Add feature”而非“Added feature”
- 主题与正文之间空一行
- 正文行≤72字符
Imperative Test
祈使语气测试
Subject should complete: "If applied, this commit will [subject]"
主题行应能完成句子:“If applied, this commit will [subject]”(若应用此提交,将[主题内容])
Imperative Verbs by Change Type
按变更类型分类的祈使动词
| Type | Verbs |
|---|---|
| Feature | Add, Implement, Introduce, Create |
| Fix | Fix, Resolve, Correct |
| Refactor | Refactor, Simplify, Restructure |
| Docs | Document, Update docs |
| Style | Format, Polish, Clean up |
| Test | Add tests, Update tests |
| Chore | Update deps, Configure |
| 变更类型 | 动词 |
|---|---|
| 功能新增 | Add, Implement, Introduce, Create |
| 问题修复 | Fix, Resolve, Correct |
| 代码重构 | Refactor, Simplify, Restructure |
| 文档更新 | Document, Update docs |
| 代码格式 | Format, Polish, Clean up |
| 测试相关 | Add tests, Update tests |
| 日常维护 | Update deps, Configure |
Context Detection
上下文识别
Infer context from file paths in the staged diff:
- Monorepo app directories (e.g., ) → mention the app name
apps/<name>/* - Shared packages (e.g., ) → mention the package name
packages/<name>/* - Test files (,
*.test.*) → "Add tests" / "Update tests"*.spec.* - Documentation () → "Document" / "Update docs"
*.md - Config files (,
.eslintrc, etc.) → "Configure" / "Update config"tsconfig.json
从已暂存差异中的文件路径推断上下文:
- 单体仓库应用目录(如 )→ 提及应用名称
apps/<name>/* - 共享包目录(如 )→ 提及包名称
packages/<name>/* - 测试文件(、
*.test.*)→ 使用“Add tests” / “Update tests”*.spec.* - 文档文件()→ 使用“Document” / “Update docs”
*.md - 配置文件(、
.eslintrc等)→ 使用“Configure” / “Update config”tsconfig.json
Large Changes Handling
大规模变更处理
When a large change threshold is hit and the user didn't specify format, ask:
I see 8 files staged. Would you like:
1. Short commit message (subject only)
2. Detailed commit message (with bullet points)当达到大规模变更阈值且用户未指定格式时,询问:
I see 8 files staged. Would you like:
1. Short commit message (subject only)
2. Detailed commit message (with bullet points)Tips
提示
- If changes are too large, suggest splitting into multiple commits
- Keep bullet points action-oriented and concise (3-6 recommended)
- Focus on WHAT and WHY, not HOW
- Never add or other git trailers to commit messages
Co-authored-by
- 若变更内容过大,建议拆分为多个提交
- 项目符号点需以动作导向且简洁(建议3-6个)
- 聚焦于做了什么和为什么做,而非怎么做
- 切勿在提交信息中添加或其他Git尾部信息
Co-authored-by