Git 提交规范(Conventional Commits)
遵循 Conventional Commits 规范,提升团队协作质量和代码可维护性。
<type>(<scope>): <subject>
<body>
<footer>
<类型>[可选作用域]: <描述>
示例:
feat(api): 添加用户认证接口
fix(database): 修复连接池泄漏问题
docs(readme): 更新安装说明
| 类型 | 说明 | 示例 |
|-----|------|------|
| feat | 新功能 | feat(user): 添加用户注册功能 |
| fix | Bug 修复 | fix(login): 修复密码验证错误 |
| docs | 文档变更 | docs(api): 更新 API 文档 |
| style | 代码格式(不影响逻辑) | style: 统一代码缩进 |
| refactor | 重构(不是新功能或修复) | refactor(auth): 优化认证逻辑 |
| perf | 性能优化 | perf(query): 优化数据库查询 |
| test | 测试相关 | test(user): 添加用户模块单元测试 |
| build | 构建系统或外部依赖 | build: 升级 Spring Boot 到 3.0 |
| ci | CI 配置文件和脚本 | ci: 添加 GitHub Actions 配置 |
| chore | 其他不修改源代码的变更 | chore: 更新 .gitignore |
| revert | 回滚之前的提交 | revert: 回滚 feat(api): xxx |
作用域表示影响的模块或组件,可选但建议添加。
常见作用域示例:
user - 用户模块auth - 认证模块api - API 接口database - 数据库config - 配置ui - 用户界面✅ 好的描述:
feat(api): 添加用户注册接口
fix(login): 修复密码加密错误
❌ 不好的描述:
feat(api): 添加了用户注册接口。
fix: 修复bug
详细说明变更的动机和与之前行为的对比。
格式要求:
示例:
fix(auth): 修复 JWT Token 验证失败问题
之前使用的签名算法与解析算法不一致,导致 Token 验证总是失败。
现在统一使用 HS256 算法,并添加了算法一致性检查。
用于记录不兼容变更和关闭的 Issue。
BREAKING CHANGE: 删除了 v1 版本的 API
请迁移到 v2 版本,详见迁移指南。
Closes #123
Closes #456, #789
feat(user): 添加用户头像上传功能
支持上传 JPG、PNG 格式的图片,最大 5MB。
自动生成缩略图并存储到 OSS。
Closes #234
fix(order): 修复订单金额计算错误
在计算优惠券折扣时未考虑最小金额限制,
导致部分订单金额为负数。现已添加金额验证。
Closes #567
feat(api): 重构用户认证 API
BREAKING CHANGE: 移除了 /api/v1/auth 端点
请使用新的 /api/v2/auth 端点,返回格式已变更。
详见 API 文档:https://example.com/api-docs
Closes #890
创建 .git/hooks/commit-msg:
#!/bin/bash
commit_msg_file=$1
commit_msg=$(cat "$commit_msg_file")
# 验证格式
if ! echo "$commit_msg" | grep -qE "^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?: .+"; then
echo "错误:提交信息不符合规范"
echo "格式:<type>(<scope>): <subject>"
echo "示例:feat(api): 添加用户注册接口"
exit 1
fi
# 安装
npm install -g commitizen cz-conventional-changelog
# 配置
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
# 使用
git cz
git pull --rebaseA: 如果变更不影响用户或功能(如更新依赖、修改配置),使用 chore。
A: 如果主要目的是提升性能,使用 perf;如果是改善代码结构,使用 refactor。
A: 建议拆分成多个提交,每个提交只修复一个 Bug。
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer