generate-commit-message

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Generate 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:
  • git commit -m
    wrapper
  • EOF
    or HEREDOC syntax
  • bash
    language tag on the code block
  • Extra commentary outside the code block
  • Co-authored-by
    trailers or any git trailers
默认输出:无语言标签的代码块形式纯文本提交信息。
用户应能直接复制全部内容。请勿包含:
  • git commit -m
    包裹语句
  • EOF
    或HEREDOC语法
  • 代码块上的
    bash
    语言标签
  • 代码块外的额外注释
  • Co-authored-by
    或任何Git尾部信息

Short Example

简短示例

Add input validation to form components
Add input validation to form components

Detailed 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 validation
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 validation

Format 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

工作流程

  1. Run
    git diff --staged --stat
    to see staged changes
  2. If nothing is staged, ask the user to stage files
  3. Analyze
    git diff --staged
  4. Generate the commit message based only on staged changes
  5. Decide Short vs Detailed (rules above)
  6. Output the plain commit message in a code block (no language tag)
  1. 运行
    git diff --staged --stat
    查看已暂存的变更
  2. 若无暂存内容,提示用户暂存文件
  3. 分析
    git diff --staged
    的输出
  4. 仅基于已暂存的变更生成提交信息
  5. 决定使用简短模式还是详细模式(遵循上述规则)
  6. 以无语言标签的代码块形式输出纯文本提交信息

Commit Message Rules

提交信息规则

  1. Subject line ≤50 chars (warn at 50-72, error >72)
  2. Capitalize subject
  3. No period at end
  4. Imperative mood: "Add feature" not "Added feature"
  5. Blank line between subject and body
  6. Body lines ≤72 chars
  1. 主题行≤50字符(50-72字符时警告,超过72字符报错)
  2. 主题行首字母大写
  3. 主题行末尾无句号
  4. 使用祈使语气:例如用“Add feature”而非“Added feature”
  5. 主题与正文之间空一行
  6. 正文行≤72字符

Imperative Test

祈使语气测试

Subject should complete: "If applied, this commit will [subject]"
主题行应能完成句子:“If applied, this commit will [subject]”(若应用此提交,将[主题内容])

Imperative Verbs by Change Type

按变更类型分类的祈使动词

TypeVerbs
FeatureAdd, Implement, Introduce, Create
FixFix, Resolve, Correct
RefactorRefactor, Simplify, Restructure
DocsDocument, Update docs
StyleFormat, Polish, Clean up
TestAdd tests, Update tests
ChoreUpdate 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.,
    apps/<name>/*
    ) → mention the app name
  • Shared packages (e.g.,
    packages/<name>/*
    ) → mention the package name
  • Test files (
    *.test.*
    ,
    *.spec.*
    ) → "Add tests" / "Update tests"
  • Documentation (
    *.md
    ) → "Document" / "Update docs"
  • Config files (
    .eslintrc
    ,
    tsconfig.json
    , etc.) → "Configure" / "Update config"
从已暂存差异中的文件路径推断上下文:
  • 单体仓库应用目录(如
    apps/<name>/*
    )→ 提及应用名称
  • 共享包目录(如
    packages/<name>/*
    )→ 提及包名称
  • 测试文件(
    *.test.*
    *.spec.*
    )→ 使用“Add tests” / “Update tests”
  • 文档文件(
    *.md
    )→ 使用“Document” / “Update docs”
  • 配置文件(
    .eslintrc
    tsconfig.json
    等)→ 使用“Configure” / “Update config”

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
    Co-authored-by
    or other git trailers to commit messages
  • 若变更内容过大,建议拆分为多个提交
  • 项目符号点需以动作导向且简洁(建议3-6个)
  • 聚焦于做了什么为什么做,而非怎么做
  • 切勿在提交信息中添加
    Co-authored-by
    或其他Git尾部信息