| name | git-workflow |
| description | Git工作流规范,分支策略和提交规范 |
| trigger | 代码修改完成后 |
Git Workflow Skill
版本控制是工程的基石
清晰的提交历史 = 可追溯的项目演进
🌿 分支策略
标准分支
| 分支 | 用途 | 保护 |
|---|
main | 生产代码 | ✅ 保护 |
develop | 开发主线 | ✅ 保护 |
feature/* | 功能开发 | ❌ |
bugfix/* | Bug修复 | ❌ |
hotfix/* | 紧急修复 | ❌ |
release/* | 发布准备 | ❌ |
分支命名
feature/user-authentication
feature/payment-integration
bugfix/login-redirect-issue
bugfix/memory-leak
hotfix/critical-security-patch
分支流程
main ──────────────────────────────────────────────▶
│ ↑
└──▶ develop ────────────────────────┼───────────▶
│ ↑ ↑ │
└──▶ feature/xxx ──┘ │
│
└──▶ bugfix/xxx ─────────────┘
📝 提交规范
Conventional Commits
<type>(<scope>): <subject>
<body>
<footer>
Type 类型
| Type | 用途 |
|---|
feat | 新功能 |
fix | Bug修复 |
docs | 文档更新 |
style | 格式调整(不影响代码) |
refactor | 重构 |
perf | 性能优化 |
test | 测试相关 |
chore | 构建/工具相关 |
示例
feat(auth): add login validation
fix(api): handle null response from server
The API sometimes returns null instead of empty array.
Added null check to prevent crash.
feat(db)!: change user schema
BREAKING CHANGE: user.name is now split into firstName and lastName
提交检查清单
🔄 工作流程
1. 开始新功能
git checkout develop
git pull origin develop
git checkout -b feature/user-profile
git add .
git commit -m "feat(profile): add user avatar upload"
git push origin feature/user-profile
2. 修复 Bug
git checkout -b bugfix/login-issue develop
git commit -m "fix(auth): handle expired token correctly"
git checkout develop
git merge bugfix/login-issue
3. 紧急修复
git checkout -b hotfix/security-patch main
git checkout main
git merge hotfix/security-patch
git checkout develop
git merge hotfix/security-patch
🔙 回滚策略
回滚单个提交
git revert <commit-hash>
回滚到特定版本
git reset --soft <commit-hash>
git reset --hard <commit-hash>
回滚合并
git revert -m 1 <merge-commit-hash>
📋 PR/MR 检查清单
创建 Pull Request 前:
PR 描述模板:
## 变更说明
[描述做了什么]
## 变更类型
- [ ] 新功能
- [ ] Bug修复
- [ ] 重构
- [ ] 文档
## 测试
- [ ] 单元测试通过
- [ ] 手动测试通过
## 截图(如有UI变更)
[截图]
## 相关 Issue
Closes #123
🛡️ 保护规则
main 分支
- ❌ 禁止直接推送
- ✅ 需要 PR 审查
- ✅ 需要 CI 通过
- ✅ 需要 1+ 审批
develop 分支
- ❌ 禁止 force push
- ✅ 需要 CI 通过
⚠️ 禁止操作
git checkout main
git commit ...
git push -f origin main
git add .env
🔗 与开发流程集成
| 阶段 | Git 操作 |
|---|
| P (Plan) | 创建 feature 分支 |
| E (Execute) | 多次小提交 |
| R2 (Review) | 创建 PR,请求审查 |
| 通过 | 合并到 develop |
核心: 小步提交、清晰历史、保护主干 | 规范: Conventional Commits