commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit with Quality Gates
带有质量门禁的Git提交
Enforce code quality before every commit.
在每次提交前强制执行代码质量检查。
Workflow (MANDATORY ORDER)
工作流(必须按顺序执行)
-
Quality Gates (BLOCKING - must pass)bash
./scripts/quality-gates.sh- Validates >90% test coverage
- Runs all tests with strict warnings
- Checks security vulnerabilities
- Verifies code quality standards
If quality gates FAIL: STOP. Fix issues before proceeding. -
Check Statusbash
git status git diff --stat -
Stage Changesbash
git add -p # Interactive staging for atomic commits # OR git add <specific-files> -
Create Commit (use message format below)bash
git commit -
Sync with Remotebash
git pull --rebase -
Handle Conflicts (if any)
- STOP - DO NOT AUTO-FIX
- Notify user for manual resolution
- Only proceed after user confirms resolution
-
Pushbash
git push
-
质量门禁(阻塞性检查 - 必须通过)bash
./scripts/quality-gates.sh- 验证测试覆盖率>90%
- 运行所有测试并开启严格警告
- 检查安全漏洞
- 验证代码质量标准
如果质量门禁未通过:停止操作。在继续之前修复问题。 -
检查状态bash
git status git diff --stat -
暂存变更bash
git add -p # 交互式暂存,实现原子提交 # 或者 git add <specific-files> -
创建提交(使用下方的信息格式)bash
git commit -
与远程仓库同步bash
git pull --rebase -
处理冲突(如果有)
- 停止 - 不要自动修复
- 通知用户进行手动解决
- 仅在用户确认解决后再继续
-
推送bash
git push
Commit Message Format
提交信息格式
type(scope): Brief description (50 chars max)
- Why this change was necessary from user perspective
- What problem it solves or capability it enables
- Reference issue/ticket numbers if applicabletype(scope): 简短描述(最多50字符)
- 从用户角度说明此变更的必要性
- 说明解决的问题或实现的功能
- 如有需要,引用问题/工单编号Commit Types
提交类型
| Type | Purpose |
|---|---|
| New user-facing feature |
| Bug fix resolving user issue |
| Documentation changes |
| Code restructure (no user-facing changes) |
| Performance improvement |
| Test additions/changes |
| Build/dependency updates |
| 类型 | 用途 |
|---|---|
| 新增面向用户的功能 |
| 修复用户相关的问题 |
| 文档变更 |
| 代码重构(无面向用户的变更) |
| 性能优化 |
| 测试用例新增/修改 |
| 构建/依赖更新 |
Message Rules
信息规则
- Subject: 50 chars max, capitalized, no period
- Body: Wrap at 72 chars
- Use imperative mood: "Add feature" not "Added feature"
- Explain WHY from user perspective, not WHAT code changed
- 主题:最多50字符,首字母大写,末尾无句号
- 正文:每行不超过72字符
- 使用祈使语气:例如“Add feature”而非“Added feature”
- 从用户角度解释原因,而非说明代码做了哪些修改
Examples
示例
Good:
feat(search): Add filters to help users find documents faster
Users were spending too much time scrolling through results.
New filters reduce search time by 60% in user testing.
Fixes #123Bad:
improved stuff规范示例:
feat(search): 添加筛选器帮助用户更快找到文档
用户此前需要花费大量时间滚动查看结果。
新筛选器在用户测试中将搜索时间缩短了60%。
修复 #123不规范示例:
改进了一些内容Atomic Commit Principle
原子提交原则
- Each commit = ONE logical change
- Commit must compile and pass tests
- Use for partial staging
git add -p
- 每个提交对应一个逻辑变更
- 提交的代码必须能编译通过并通过测试
- 使用进行部分暂存
git add -p
Optional Pre-Push Checks
可选的推送前检查
For larger changes:
bash
./scripts/check-doctests.sh
./scripts/check_performance_regression.sh对于较大的变更:
bash
./scripts/check-doctests.sh
./scripts/check_performance_regression.shReferences
参考资料
- AGENTS.md - Required Checks Before Commit
- commit command
- AGENTS.md - 提交前的必要检查
- commit 命令