juechafun/03-资源/操作说明-工具技巧-git提交规范.md

168 lines
5.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
#领域/工具技巧
#复盘/0 #临时/备忘 #状态/待处理
## 一句话描述
[__git提交规范______]
---
## 核心规范
>空想不如行动,积累胜于苛求。
>实践 > 沉淀 > 完美主义
实践不是盲目行动,而是带着“小目标、可验证“的方向试错,实践后必须沉淀(比如记录问题、总结规律),否则就是低水平重复。
实践大于沉淀,沉淀大于完美;完美是沉淀的终局方向,沉淀是实践的复盘产物;分域施策,避坑落地,始于行动,终于迭代。
---
## 三省沉淀法
- 达成了[__置顶了git的提交的消息规范______]目标
- 遇到了[__旧版本不兼容______]问题
- 下次改进[__不修改旧版本仅忽略______]
## 个人理解
[___结构化编写提交消息方便人工阅读和脚本自动化_____]
## 实践计划
#状态/待实践
1. [_使用工具落地规范成果_______]
- **commitlint**:校验提交信息是否符合约定式提交规范,避免违规提交
- **husky**Git 钩子工具,配合 commitlint 在提交前自动校验
- **语义化版本SemVer**:约定式提交是 SemVer 的 “落地载体”type 直接对应版本升级规则feat→MINOR、fix→PATCH、BREAKING CHANGE→MAJOR
- **standard-version**:基于约定式提交自动生成 CHANGELOG、升级版本、打 Tag
2. [________]
3. [________]
---
## 核心定义
git 需遵循**Conventional Commits约定式提交** 规范
feat 和 fix 是核心提交类型,语义化版本
feat 对应小版本升级, fix 对应补丁版本升级
## 提交格式
类型:必须是规定的几大类中
作用域:必须现在式动词开头 add/modify/fix重点在于现在做了什么
详细描述:解释为什么改、改了什么
脚注:
1. 破坏性变更:必须写 `BREAKING CHANGE:` 变更描述
2. 关联Issue: 必须用 Closes/Fixes/Resolves + `#数字`,如 Close `#123`
3. 回滚提交: 必须注明: Reverts `<commit-hash>`
```plaintext
<类型>[可选作用域]: <简短描述>
[可选的详细描述]
[可选的关闭Issue链接]
```
```
# 新功能(带作用域)
feat(shop): 新增商品收藏功能
# 修复Bug带详细描述
fix(cart): 修复购物车数量为0时仍显示小红点
用户删除所有商品后购物车小红点未清空原因是判断条件遗漏了数量为0的场景现已补充。
# 文档变更
docs: 更新API文档中用户信息接口的参数说明
# 重构
refactor: 提取表单验证的公共方法到utils目录
```
## 常见前缀
| 前缀 | 全称 / 含义 | 适用场景举例 |
| ---------- | ----------------- | ------------------------------------ |
| `feat` | Feature新功能 | 新增用户注册功能、添加商品筛选接口 |
| `fix` | Fix修复 Bug | 修复登录密码错误提示不显示、修复数据统计偏差 |
| `docs` | Documentation文档 | 更新 README、补充接口注释、修改使用说明 |
| `style` | Style格式 | 调整代码缩进、补充分号、修改空格(不影响逻辑) |
| `refactor` | Refactor重构 | 提取公共函数、优化代码结构(无功能 / 修复变更) |
| `perf` | Performance性能 | 优化列表渲染速度、减少接口请求耗时 |
| `test` | Test测试 | 添加单元测试、补充集成测试、修复测试用例 |
| `build` | Build构建 | 升级 webpack 版本、修改打包配置、调整依赖版本 |
| `ci` | CI/CD持续集成 | 修改 GitHub Actions 配置、调整 Jenkins 流水线 |
| `chore` | Chore杂项 | 删除无用文件、清理日志、修改.gitignore |
| `revert` | Revert回滚 | 回滚之前的错误提交(格式:`revert: feat: 新增xx功能` |
### 示例
#### ✅ 示例:新功能提交
```bash
feat(pay): add wechat pay signature verification
Implement wechat pay V3 signature check to prevent fake payment requests
Closes #45
```
#### ✅ 示例Bug 修复提交
```bash
fix(cart): fix empty cart quantity display error
Quantity showed 1 instead of 0 when cart is empty, fix the boundary condition check
Fixes #67
```
#### ✅ 示例性能优化Angular 特有)
```bash
perf(list): optimize large list rendering speed
Reduce rendering time by 60% for lists with more than 200 items
Closes #89
```
#### ✅ 示例CI 配置修改Angular 特有)
```bash
ci: update woodpecker ci test step
Add node_modules cache to reduce CI execution time from 5min to 1min
```
#### ✅ 示例回滚提交Angular 特有)
```bash
revert: feat(pay): add wechat pay signature verification
This reverts commit abc1234567890.
Reverts #45
```
#### ✅ 示例:破坏性变更提交
```bash
feat(auth): refactor token validation logic
Unify token validation to use JWT only, remove old token format support BREAKING CHANGE: Old token format is no longer supported, clients need to upgrade to JWT
Closes #99
```
#### ✅ 示例:`BREAKING CHANGE:`脚注
涉及接口删除、参数移除等 breaking 变更,必须加`BREAKING CHANGE:`脚注,避免线上风险
```
BREAKING CHANGE: 移除旧版token校验方式统一使用JWT
```
### 避坑点
⚠️ 避坑点1
解决方案:✅
⚠️ 避坑点1
核心问题:
解决方案:✅