semantic-commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSemantic Commit
语义化Git提交
Create git commits following the Conventional Commits specification.
创建符合Conventional Commits规范的Git提交。
Commit Format
提交格式
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]<type>[可选 scope]: <描述>
[可选 正文]
[可选 页脚]Guidelines
规范指南
- Start with a short prefix followed by colon and space (feat:, fix:, docs:, refactor:, test:, chore:, etc.)
- Isolate your changes and commit only what you did (no unrelated files)
- feat: for user-visible features, fix: for bug fixes
- A scope MAY be added in parentheses, e.g. - only when it meaningfully improves clarity
fix(parser): - Short description in imperative mood explaining what changed, not how
- Body MAY be included after one blank line for context, rationale, or non-obvious behavior
- Footers MAY be included (Token: value format, use instead of spaces in tokens)
- - Breaking changes should be explained clearly in description or body, no special marking required
- Clarity and usefulness matter more than strict conformance
- 以简短前缀开头,后跟冒号和空格(feat:, fix:, docs:, refactor:, test:, chore:等)
- 隔离变更内容,仅提交你本次修改的内容(不要包含无关文件)
- feat: 用于用户可见的新功能,fix: 用于修复bug
- 可在括号中添加scope,例如 - 仅当它能显著提升清晰度时才添加
fix(parser): - 简短描述使用祈使语气,说明变更内容而非实现方式
- 若需要补充上下文、理由或非直观行为说明,可在空一行后添加正文
- 可添加页脚(采用Token: 值的格式,Token中用代替空格)
- - 破坏性变更需在描述或正文中清晰说明,无需特殊标记
- 清晰度和实用性比严格遵循规范更重要
Commit Types
提交类型
| Type | Description |
|---|---|
| A new feature (user-visible) |
| A bug fix (user-visible) |
| Documentation only changes |
| Changes that do not affect the meaning of the code (formatting, semicolons, etc.) |
| A code change that neither fixes a bug nor adds a feature |
| A code change that improves performance |
| Adding missing tests or correcting existing tests |
| Changes that affect the build system or external dependencies |
| Changes to CI configuration files and scripts |
| Other changes that don't modify src or test files |
| Reverts a previous commit |
| 类型 | 描述 |
|---|---|
| 用户可见的新功能 |
| 用户可见的bug修复 |
| 仅修改文档 |
| 不影响代码含义的变更(如格式化、分号调整等) |
| 既不修复bug也不添加功能的代码变更 |
| 提升性能的代码变更 |
| 添加缺失测试或修正现有测试 |
| 影响构建系统或外部依赖的变更 |
| 修改CI配置文件和脚本 |
| 其他不修改源码或测试文件的变更 |
| 回滚之前的提交 |
Workflow
工作流程
dot
digraph commit_workflow {
rankdir=TB;
node [shape=box];
check [label="Check git status"];
stage [label="Stage changes\n(if needed)"];
review [label="Review staged diff"];
analyze [label="Analyze changes\nDetermine type & scope"];
write [label="Write commit message"];
commit [label="Execute git commit"];
check -> stage;
stage -> review;
review -> analyze;
analyze -> write;
write -> commit;
}dot
digraph commit_workflow {
rankdir=TB;
node [shape=box];
check [label="Check git status"];
stage [label="Stage changes\n(if needed)"];
review [label="Review staged diff"];
analyze [label="Analyze changes\nDetermine type & scope"];
write [label="Write commit message"];
commit [label="Execute git commit"];
check -> stage;
stage -> review;
review -> analyze;
analyze -> write;
write -> commit;
}1. Check Repository State
1. 检查仓库状态
bash
git status --short
git diff --cached --stat # staged changes
git diff --stat # unstaged changesbash
git status --short
git diff --cached --stat # 已暂存的变更
git diff --stat # 未暂存的变更2. Stage Changes
2. 暂存变更
If no changes are staged:
- Ask which files to stage
- Stage only files you changed for this task (avoid unrelated changes)
如果没有已暂存的变更:
- 询问需要暂存哪些文件
- 仅暂存本次任务修改的文件(避免无关变更)
3. Review Staged Changes
3. 审核已暂存的变更
bash
git diff --cachedUnderstand what was modified to write an accurate message.
bash
git diff --cached了解修改内容,以便撰写准确的提交消息。
4. Determine Type and Scope
4. 确定类型和Scope
Based on the changes:
- Type: What category of change? (feat, fix, refactor, etc.)
- Scope: What area of the codebase? Only add when it meaningfully improves clarity
- Breaking: Does this break backward compatibility? Explain clearly in description or body
根据变更内容:
- 类型:变更属于哪一类别?(feat、fix、refactor等)
- Scope:代码库的哪个区域?仅当能显著提升清晰度时才添加
- 破坏性:是否破坏向后兼容性?需在描述或正文中清晰说明
Writing Good Commit Messages
撰写优质提交消息
Subject Line
主题行
- Use imperative mood: "add feature" not "added feature"
- Keep under 50 characters when possible
- Don't end with a period
- Explain what changed, not how
- 使用祈使语气:"add feature" 而非 "added feature"
- 尽可能控制在50字符以内
- 结尾不要加句号
- 说明变更内容而非实现方式
<正确示例>
feat(auth): add OAuth2 login support
fix: prevent crash on empty input
refactor(api): extract validation logic</正确示例>
<错误示例>
updated some stuff
fix bug
WIP
changes</错误示例>
Body (Optional)
正文(可选)
Include after one blank line when context, rationale, or non-obvious behavior needs explanation:
- Explain motivation for the change
- Contrast with previous behavior
- Note any side effects
fix(parser): handle unicode characters in filenames
Previously, filenames with non-ASCII characters would cause
a decode error. Now using UTF-8 decoding with fallback to
latin-1 for legacy files.
Closes #123当需要说明上下文、理由或非直观行为时,可在空一行后添加正文:
- 说明变更的动机
- 对比之前的行为
- 注明任何副作用
fix(parser): handle unicode characters in filenames
Previously, filenames with non-ASCII characters would cause
a decode error. Now using UTF-8 decoding with fallback to
latin-1 for legacy files.
Closes #123Footer (Optional)
页脚(可选)
Use Token: value format (use instead of spaces in token names):
-- or
Closes #123for issue referencesFixes #456 - for pair programming
Co-authored-by: Name <email> - for review attribution
Reviewed-by: Name <email>
采用Token: 值的格式(Token名称中用代替空格):
-- 或
Closes #123用于关联议题Fixes #456 - 用于结对编程署名
Co-authored-by: Name <email> - 用于审核署名
Reviewed-by: Name <email>
Examples
示例
| Changes | Commit |
|---|---|
| New endpoint added | |
| Bug causing crash | |
| Updated README | |
| Reformatted code | |
| Renamed internal function | |
| Optimized query | |
| Added unit tests | |
| Updated dependencies | |
| Changed CI config | |
| Cleaned up files | |
| Breaking API change | |
| 变更内容 | 提交消息 |
|---|---|
| 添加新接口 | |
| 修复导致崩溃的bug | |
| 更新README | |
| 格式化代码 | |
| 重命名内部函数 | |
| 优化查询 | |
| 添加单元测试 | |
| 更新依赖 | |
| 修改CI配置 | |
| 清理文件 | |
| 破坏性API变更 | |
Common Mistakes
常见错误
| Mistake | Fix |
|---|---|
| Past tense ("added") | Use imperative ("add") |
| Too vague ("fix bug") | Be specific ("fix null check in parser") |
| Too long subject | Keep concise, move details to body |
| Wrong type | |
| Combining unrelated changes | Split into multiple commits |
| Overusing scope | Only add scope when it meaningfully improves clarity |
| 错误 | 修正方式 |
|---|---|
| 使用过去式("added") | 使用祈使语气("add") |
| 描述过于模糊("fix bug") | 具体化描述("fix null check in parser") |
| 主题行过长 | 保持简洁,将细节移至正文 |
| 类型选择错误 | |
| 合并无关变更 | 拆分为多个提交 |
| 过度使用scope | 仅当能显著提升清晰度时才添加scope |
Quick Reference
快速参考
feat: New feature for users
fix: Bug fix for users
docs: Documentation only
style: Formatting, no logic change
refactor: Code change, no behavior change
perf: Performance improvement
test: Adding/fixing tests
build: Build system, dependencies
ci: CI configuration
chore: Maintenance, tooling
revert: Reverting commitsfeat: 用户可见新功能
fix: 用户可见bug修复
docs: 仅修改文档
style: 格式化调整,无逻辑变更
refactor: 代码调整,无行为变更
perf: 性能优化
test: 添加/修复测试
build: 构建系统、依赖变更
ci: CI配置变更
chore: 维护工作、工具调整
revert: 回滚提交