外观
Git 提交规范
Conventional Commits 格式
<type>(<scope>): <description>
[optional body]
[optional footer(s)]类型说明
| 类型 | 说明 | 示例 |
|---|---|---|
feat | 新功能(feature) | feat(auth): 添加登录功能 |
fix | 修复 bug | fix(api): 修复接口返回格式错误 |
docs | 文档更新 | docs(readme): 更新安装说明 |
style | 代码格式调整(不影响逻辑) | style: 格式化代码 |
refactor | 重构(既不是新增功能,也不是修复 bug) | refactor(user): 重构用户模块 |
perf | 性能优化 | perf: 优化列表渲染性能 |
test | 测试相关 | test(auth): 添加登录测试用例 |
build | 构建相关(依赖、工具等) | build(deps): 更新 axios 到 v1.0 |
ci | CI/CD 配置 | ci: 添加 GitHub Actions |
chore | 其他杂项 | chore: 更新 .gitignore |
revert | 撤销提交 | revert: 撤销 feat(auth): 添加登录功能 |
作用域(scope)
可选字段,用于说明修改涉及的模块或文件:
bash
feat(sidebar): 添加欢迎页置顶
fix(api/user): 修复用户列表查询
docs(cocos): 更新课程目录说明描述(description)
- 简短描述,不超过 50 字符
- 使用动词开头(添加、修复、更新等)
- 结尾不加句号
示例
简单提交
bash
git commit -m "feat(auth): 添加短信验证码登录"
git commit -m "fix(sidebar): 修复欢迎页排序问题"带正文的提交
bash
git commit -m "refactor(api): 重构响应处理逻辑" -m "- 统一错误码格式" -m "- 添加请求超时处理"修复问题并关联 Issue
bash
git commit -m "fix(ui): 修复按钮样式错位" -m "Closes #123"推荐实践
- 一个提交一个变更:每个提交应该只包含一个逻辑变更
- 提交信息用英文:便于团队协作和工具解析
- 使用
fix而不是bugfix:遵循规范的类型名称 - 重大变更加
BREAKING CHANGE:
bash
git commit -m "feat(api): 修改用户接口返回格式" -m "BREAKING CHANGE: 用户接口不再返回 password 字段"工具
- commitlint:检查提交信息格式
- cz-cli:交互式生成提交信息
- standard-version:自动生成 CHANGELOG
错误示例 vs 正确示例
| 错误 | 正确 |
|---|---|
修复了一个 bug | fix(api): 修复接口超时问题 |
添加功能 | feat(auth): 添加 OAuth 登录 |
更新代码 | refactor: 提取公共组件 |
修改了 sidebar | fix(sidebar): 调整欢迎页位置 |