Files
photography/.cursor/rules/common/git-workflow.mdc
xujiang 604b9e59ba fix
2025-07-10 18:09:11 +08:00

249 lines
4.4 KiB
Plaintext
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.

# Git 工作流规则
## 🌿 分支管理
### 分支命名规范
```bash
# 功能分支
feature/photo-upload-api
feature/admin-dashboard
feature/responsive-design
# 修复分支
fix/photo-delete-bug
fix/login-redirect-issue
# 优化分支
refactor/api-structure
refactor/component-organization
# 文档分支
docs/api-documentation
docs/deployment-guide
```
### 分支工作流
```bash
# 1. 从主分支创建功能分支
git checkout main
git pull origin main
git checkout -b feature/photo-update-api
# 2. 开发和提交
git add .
git commit -m "feat: 实现照片更新API"
# 3. 推送分支
git push origin feature/photo-update-api
# 4. 创建Pull Request
# 在GitHub/GitLab上创建PR
# 5. 代码审查后合并
git checkout main
git pull origin main
git branch -d feature/photo-update-api
```
## 📝 提交信息规范
### 提交类型
```bash
feat: 新功能
fix: 修复bug
docs: 文档更新
style: 代码格式化(不影响代码逻辑)
refactor: 重构既不是新增功能也不是修复bug
perf: 性能优化
test: 添加测试
chore: 构建过程或辅助工具的变动
ci: CI/CD配置文件和脚本的变动
```
### 提交信息格式
```bash
<type>(<scope>): <subject>
<body>
<footer>
```
### 提交示例
```bash
# 简单提交
git commit -m "feat: 添加照片上传功能"
git commit -m "fix: 修复登录页面重定向问题"
# 详细提交
git commit -m "feat(api): 实现照片批量删除功能
- 添加批量删除API接口
- 支持选择多张照片删除
- 添加删除确认对话框
- 更新照片列表组件
Closes #123"
```
## 🔄 工作流最佳实践
### 代码同步
```bash
# 每日开始工作前
git checkout main
git pull origin main
# 功能开发中定期同步
git checkout main
git pull origin main
git checkout feature/your-branch
git rebase main # 或者 git merge main
```
### 提交频率
- **小而频繁的提交**:每个逻辑单元完成后提交
- **有意义的提交**:每次提交都应该是可运行的状态
- **原子性提交**:一次提交只做一件事
### 代码审查
```bash
# PR 标题规范
feat: 实现照片分类管理功能
fix: 修复图片上传失败问题
docs: 更新API文档
# PR 描述模板
## 变更说明
- 实现了什么功能
- 修复了什么问题
## 测试说明
- 如何测试这个变更
- 相关的测试用例
## 影响范围
- 影响的模块
- 是否有破坏性变更
```
## 🏷️ 版本管理
### 语义化版本
```bash
# 版本格式MAJOR.MINOR.PATCH
v1.0.0 # 初始版本
v1.0.1 # 补丁版本修复bug
v1.1.0 # 次要版本(新功能,向后兼容)
v2.0.0 # 主要版本(破坏性变更)
```
### 标签管理
```bash
# 创建标签
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
# 查看标签
git tag -l
git show v1.0.0
```
## 🚀 发布流程
### 发布分支
```bash
# 创建发布分支
git checkout -b release/v1.1.0 main
# 在发布分支上修复最后的问题
git commit -m "fix: 修复发布前的小问题"
# 合并回主分支和开发分支
git checkout main
git merge release/v1.1.0
git tag -a v1.1.0 -m "Release v1.1.0"
# 删除发布分支
git branch -d release/v1.1.0
```
## 🔧 Git 配置
### 全局配置
```bash
# 用户信息
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
# 编辑器
git config --global core.editor "code --wait"
# 别名
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.visual '!gitk'
```
### 项目配置
```bash
# .gitignore 示例
# 依赖
node_modules/
vendor/
# 构建产物
dist/
build/
*.exe
# 环境文件
.env
.env.local
.env.production
# IDE
.vscode/
.idea/
*.swp
*.swo
# 日志
logs/
*.log
# 临时文件
.DS_Store
Thumbs.db
```
## 📊 常用命令
### 日常操作
```bash
# 查看状态
git status
git log --oneline -10
# 暂存操作
git stash
git stash pop
git stash list
# 撤销操作
git reset HEAD~1 # 撤销最后一次提交(保留更改)
git reset --hard HEAD~1 # 撤销最后一次提交(丢弃更改)
git revert HEAD # 创建一个撤销提交
# 查看差异
git diff
git diff --staged
git diff main..feature/branch
```
参考 [TASK_PROGRESS.md](mdc:TASK_PROGRESS.md) 进行版本控制和任务跟踪。