git-workflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Workflow Standards
Git 工作流规范
This document defines the project's Git usage standards, including commit message format, branch management strategy, workflows, merge strategies, and more. Following these standards improves collaboration efficiency, enables traceability, supports automation, and reduces conflicts.
本文档定义了项目的Git使用标准,包含提交信息格式、分支管理策略、工作流程、合并策略等内容。遵循这些规范可以提升协作效率、实现变更可追溯、支持自动化流程并减少冲突。
Commit Message Standards
提交信息规范
The project follows the Conventional Commits specification:
<type>(<scope>): <subject>
<body>
<footer>项目遵循 Conventional Commits 规范:
<type>(<scope>): <subject>
<body>
<footer>Type Reference
类型参考
| Type | Description | Example |
|---|---|---|
| New feature | |
| Bug fix | |
| Documentation update | |
| Refactoring | |
| Performance improvement | |
| Test related | |
| Other changes | |
| 类型 | 描述 | 示例 |
|---|---|---|
| 新增功能 | |
| 修复Bug | |
| 文档更新 | |
| 代码重构 | |
| 性能优化 | |
| 测试相关 | |
| 其他变更 | |
Subject Rules
主题规则
- Start with a verb: add, fix, update, remove, optimize
- No more than 50 characters
- No period at the end
For more detailed conventions and examples, see .
references/commit-conventions.md- 以动词开头:add、fix、update、remove、optimize
- 不超过50个字符
- 末尾不加句号
更详细的约定和示例请查看 。
references/commit-conventions.mdBranch Management Strategy
分支管理策略
Branch Types
分支类型
| Branch Type | Naming Convention | Description | Lifecycle |
|---|---|---|---|
| master | | Main branch, releasable state | Permanent |
| develop | | Development branch, latest integrated code | Permanent |
| feature | | Feature branch | Delete after completion |
| bugfix | | Bug fix branch | Delete after fix |
| hotfix | | Emergency fix branch | Delete after fix |
| release | | Release branch | Delete after release |
| 分支类型 | 命名规则 | 描述 | 生命周期 |
|---|---|---|---|
| master | | 主分支,处于可发布状态 | 永久存在 |
| develop | | 开发分支,包含最新集成代码 | 永久存在 |
| feature | | 功能分支 | 开发完成后删除 |
| bugfix | | Bug修复分支 | 修复完成后删除 |
| hotfix | | 紧急修复分支 | 修复完成后删除 |
| release | | 发布分支 | 发布完成后删除 |
Branch Naming Examples
分支命名示例
feature/user-management # User management feature
feature/123-add-export # Issue-linked feature
bugfix/login-error # Login error fix
hotfix/security-vulnerability # Security vulnerability fix
release/v1.0.0 # Version releasefeature/user-management # 用户管理功能
feature/123-add-export # 关联Issue的功能开发
bugfix/login-error # 登录错误修复
hotfix/security-vulnerability # 安全漏洞修复
release/v1.0.0 # 版本发布Branch Protection Rules
分支保护规则
master branch:
- No direct pushes allowed
- Must merge via Pull Request
- Must pass CI checks
- Requires at least one Code Review approval
develop branch:
- Direct pushes restricted
- Pull Request merges recommended
- Must pass CI checks
For detailed branch strategies and workflows, see .
references/branching-strategies.mdmaster分支:
- 禁止直接推送
- 必须通过Pull Request合并
- 必须通过CI检查
- 至少需要1个Code Review审批
develop分支:
- 限制直接推送
- 推荐通过Pull Request合并
- 必须通过CI检查
详细的分支策略和工作流请查看 。
references/branching-strategies.mdWorkflows
工作流程
Daily Development Workflow
日常开发工作流
bash
undefinedbash
undefined1. Sync latest code
1. 同步最新代码
git checkout develop
git pull origin develop
git checkout develop
git pull origin develop
2. Create feature branch
2. 创建功能分支
git checkout -b feature/user-management
git checkout -b feature/user-management
3. Develop and commit
3. 开发并提交
git add .
git commit -m "feat(user): add user list page"
git add .
git commit -m "feat(user): add user list page"
4. Push to remote
4. 推送到远端
git push -u origin feature/user-management
git push -u origin feature/user-management
5. Create Pull Request and request Code Review
5. 创建Pull Request并申请Code Review
6. Merge to develop (via PR)
6. (通过PR)合并到develop分支
7. Delete feature branch
7. 删除功能分支
git branch -d feature/user-management
git push origin -d feature/user-management
undefinedgit branch -d feature/user-management
git push origin -d feature/user-management
undefinedHotfix Workflow
热修复工作流
bash
undefinedbash
undefined1. Create fix branch from master
1. 从master创建修复分支
git checkout master
git pull origin master
git checkout -b hotfix/critical-bug
git checkout master
git pull origin master
git checkout -b hotfix/critical-bug
2. Fix and commit
2. 修复问题并提交
git add .
git commit -m "fix(auth): fix authentication bypass vulnerability"
git add .
git commit -m "fix(auth): fix authentication bypass vulnerability"
3. Merge to master
3. 合并到master
git checkout master
git merge --no-ff hotfix/critical-bug
git tag -a v1.0.1 -m "hotfix: fix authentication bypass vulnerability"
git push origin master --tags
git checkout master
git merge --no-ff hotfix/critical-bug
git tag -a v1.0.1 -m "hotfix: fix authentication bypass vulnerability"
git push origin master --tags
4. Sync to develop
4. 同步到develop分支
git checkout develop
git merge --no-ff hotfix/critical-bug
git push origin develop
undefinedgit checkout develop
git merge --no-ff hotfix/critical-bug
git push origin develop
undefinedRelease Workflow
发布工作流
bash
undefinedbash
undefined1. Create release branch
1. 创建发布分支
git checkout develop
git checkout -b release/v1.0.0
git checkout develop
git checkout -b release/v1.0.0
2. Update version numbers and documentation
2. 更新版本号和相关文档
3. Commit version update
3. 提交版本更新
git add .
git commit -m "chore(release): prepare release v1.0.0"
git add .
git commit -m "chore(release): prepare release v1.0.0"
4. Merge to master
4. 合并到master
git checkout master
git merge --no-ff release/v1.0.0
git tag -a v1.0.0 -m "release: v1.0.0 official release"
git push origin master --tags
git checkout master
git merge --no-ff release/v1.0.0
git tag -a v1.0.0 -m "release: v1.0.0 official release"
git push origin master --tags
5. Sync to develop
5. 同步到develop分支
git checkout develop
git merge --no-ff release/v1.0.0
git push origin develop
undefinedgit checkout develop
git merge --no-ff release/v1.0.0
git push origin develop
undefinedMerge Strategy
合并策略
Merge vs Rebase
Merge 与 Rebase 对比
| Feature | Merge | Rebase |
|---|---|---|
| History | Preserves complete history | Linear history |
| Use case | Public branches | Private branches |
| Recommended for | Merging to main branch | Syncing upstream code |
| 特性 | Merge | Rebase |
|---|---|---|
| 提交历史 | 保留完整历史 | 线性历史 |
| 适用场景 | 公共分支 | 私有分支 |
| 推荐用途 | 合并到主分支 | 同步上游代码 |
Recommendations
使用建议
- Feature branch syncing develop: Use
rebase - Feature branch merging to develop: Use
merge --no-ff - develop merging to master: Use
merge --no-ff
bash
undefined- 功能分支同步develop代码:使用
rebase - 功能分支合并到develop:使用
merge --no-ff - develop合并到master:使用
merge --no-ff
bash
undefined✅ Recommended: Feature branch syncing develop
✅ 推荐:功能分支同步develop代码
git checkout feature/user-management
git rebase develop
git checkout feature/user-management
git rebase develop
✅ Recommended: Merge feature branch to develop
✅ 推荐:功能分支合并到develop
git checkout develop
git merge --no-ff feature/user-management
git checkout develop
git merge --no-ff feature/user-management
❌ Not recommended: Rebase on public branch
❌ 不推荐:在公共分支上执行rebase
git checkout develop
git rebase feature/xxx # Dangerous operation
**Project convention**: Use `--no-ff` when merging feature branches to preserve branch history.
For detailed merge strategies and techniques, see `references/merge-strategies.md`.git checkout develop
git rebase feature/xxx # 危险操作
**项目约定**:合并功能分支时使用`--no-ff`保留分支历史。
详细的合并策略和技巧请查看 `references/merge-strategies.md`。Conflict Resolution
冲突解决
Identifying Conflicts
识别冲突
<<<<<<< HEAD
// Current branch code
const name = 'Alice'
=======
// Branch being merged
const name = 'Bob'
>>>>>>> feature/user-management<<<<<<< HEAD
// 当前分支代码
const name = 'Alice'
=======
// 待合并分支代码
const name = 'Bob'
>>>>>>> feature/user-managementResolving Conflicts
解决冲突
bash
undefinedbash
undefined1. View conflicting files
1. 查看冲突文件
git status
git status
2. Manually edit files to resolve conflicts
2. 手动编辑文件解决冲突
3. Mark as resolved
3. 标记为已解决
git add <file>
git add <file>
4. Complete the merge
4. 完成合并
git commit # merge conflict
git commit # merge场景冲突
or
或
git rebase --continue # rebase conflict
undefinedgit rebase --continue # rebase场景冲突
undefinedConflict Resolution Strategies
冲突解决命令
bash
undefinedbash
undefinedKeep current branch version
保留当前分支版本
git checkout --ours <file>
git checkout --ours <file>
Keep incoming branch version
保留待合并分支版本
git checkout --theirs <file>
git checkout --theirs <file>
Abort merge
终止合并操作
git merge --abort
git rebase --abort
undefinedgit merge --abort
git rebase --abort
undefinedPreventing Conflicts
冲突预防
- Sync code regularly - Pull latest code before starting work each day
- Small commits - Commit small changes frequently
- Modular features - Implement different features in different files
- Communication - Avoid modifying the same file simultaneously
For detailed conflict handling and advanced techniques, see .
references/conflict-resolution.md- 定期同步代码 - 每天开始工作前拉取最新代码
- 小粒度提交 - 频繁提交小范围变更
- 功能模块化 - 不同功能在不同文件中实现
- 团队沟通 - 避免同时修改同一文件
详细的冲突处理和高级技巧请查看 。
references/conflict-resolution.md.gitignore Standards
.gitignore 规范
Basic Rules
基础规则
undefinedundefinedIgnore all .log files
忽略所有.log文件
*.log
*.log
Ignore directories
忽略目录
node_modules/
node_modules/
Ignore directory at root
忽略根目录下的指定目录
/temp/
/temp/
Ignore files in all directories
忽略所有目录下的指定文件
**/.env
**/.env
Don't ignore specific files
不忽略特定文件
!.gitkeep
undefined!.gitkeep
undefinedCommon .gitignore
常用配置
node_modules/
dist/
build/
.idea/
.vscode/
.env
.env.local
logs/
*.log
.DS_Store
Thumbs.dbFor detailed .gitignore patterns and project-specific configurations, see .
references/gitignore-guide.mdnode_modules/
dist/
build/
.idea/
.vscode/
.env
.env.local
logs/
*.log
.DS_Store
Thumbs.db详细的.gitignore模式和项目专属配置请查看 。
references/gitignore-guide.mdTag Management
标签管理
Uses Semantic Versioning:
MAJOR.MINOR.PATCH[-PRERELEASE]采用 Semantic Versioning 规范:
MAJOR.MINOR.PATCH[-PRERELEASE]Version Change Rules
版本变更规则
- MAJOR: Incompatible API changes (v1.0.0 → v2.0.0)
- MINOR: Backward-compatible new features (v1.0.0 → v1.1.0)
- PATCH: Backward-compatible bug fixes (v1.0.0 → v1.0.1)
- MAJOR:不兼容的API变更 (v1.0.0 → v2.0.0)
- MINOR:向后兼容的新增功能 (v1.0.0 → v1.1.0)
- PATCH:向后兼容的Bug修复 (v1.0.0 → v1.0.1)
Tag Operations
标签操作
bash
undefinedbash
undefinedCreate annotated tag (recommended)
创建附注标签(推荐)
git tag -a v1.0.0 -m "release: v1.0.0 official release"
git tag -a v1.0.0 -m "release: v1.0.0 official release"
Push tags
推送标签
git push origin v1.0.0
git push origin --tags
git push origin v1.0.0
git push origin --tags
View tags
查看标签
git tag
git show v1.0.0
git tag
git show v1.0.0
Delete tag
删除标签
git tag -d v1.0.0
git push origin :refs/tags/v1.0.0
undefinedgit tag -d v1.0.0
git push origin :refs/tags/v1.0.0
undefinedTeam Collaboration Standards
团队协作规范
Pull Request Standards
Pull Request 规范
PRs should include:
markdown
undefinedPR需要包含以下内容:
markdown
undefinedChange Description
变更描述
<!-- Describe the content and purpose of this change -->
<!-- 描述本次变更的内容和目的 -->
Change Type
变更类型
- New feature (feat)
- Bug fix (fix)
- Code refactoring (refactor)
- 新增功能 (feat)
- Bug修复 (fix)
- 代码重构 (refactor)
Testing Method
测试方式
<!-- Describe how to test -->
<!-- 描述如何验证变更效果 -->
Related Issue
关联Issue
Closes #xxx
Closes #xxx
Checklist
检查清单
- Code has been self-tested
- Documentation has been updated
undefined- 代码已完成自测
- 相关文档已更新
undefinedCode Review Standards
Code Review 规范
Review focus areas:
- Code quality: Clear and readable, proper naming, no duplicate code
- Logic correctness: Business logic correct, edge cases handled
- Security: No security vulnerabilities, sensitive information protected
- Performance: No obvious performance issues, resources properly released
For detailed collaboration standards and best practices, see .
references/collaboration.md评审重点:
- 代码质量:清晰可读、命名规范、无重复代码
- 逻辑正确性:业务逻辑正确、边缘场景已处理
- 安全性:无安全漏洞、敏感信息已保护
- 性能:无明显性能问题、资源已正确释放
详细的协作规范和最佳实践请查看 。
references/collaboration.mdCommon Issues
常见问题
Amending the Last Commit
修改最后一次提交
bash
undefinedbash
undefinedAmend commit content (not yet pushed)
修改提交内容(未推送到远端时)
git add forgotten-file.ts
git commit --amend --no-edit
git add forgotten-file.ts
git commit --amend --no-edit
Amend commit message
修改提交信息
git commit --amend -m "new commit message"
undefinedgit commit --amend -m "new commit message"
undefinedPush Rejected
推送被拒绝
bash
undefinedbash
undefinedPull then push
先拉取再推送
git pull origin master
git push origin master
git pull origin master
git push origin master
Use rebase for cleaner history
使用rebase获得更整洁的历史
git pull --rebase origin master
git push origin master
undefinedgit pull --rebase origin master
git push origin master
undefinedRollback to Previous Version
回滚到之前的版本
bash
undefinedbash
undefinedReset to specific commit (discards subsequent commits)
重置到指定提交(会丢弃后续提交)
git reset --hard abc123
git reset --hard abc123
Create reverse commit (recommended, preserves history)
创建反向提交(推荐,保留历史)
git revert abc123
undefinedgit revert abc123
undefinedStash Current Work
暂存当前工作
bash
git stash save "work in progress"
git stash list
git stash popbash
git stash save "work in progress"
git stash list
git stash popView File Modification History
查看文件修改历史
bash
git log -- <file> # Commit history
git log -p -- <file> # Detailed content
git blame <file> # Per-line authorbash
git log -- <file> # 提交历史
git log -p -- <file> # 详细变更内容
git blame <file> # 逐行修改人信息Best Practices Summary
最佳实践总结
Commit Standards
提交规范
✅ Recommended:
- Follow Conventional Commits specification
- Write clear commit messages describing changes
- One commit for one logical change
- Run code checks before committing
❌ Prohibited:
- Vague commit messages
- Multiple unrelated changes in one commit
- Committing sensitive information (passwords, keys)
- Developing directly on main branch
✅ 推荐:
- 遵循Conventional Commits规范
- 编写清晰描述变更的提交信息
- 一个提交对应一个逻辑变更
- 提交前执行代码检查
❌ 禁止:
- 提交信息模糊不清
- 一个提交包含多个不相关的变更
- 提交敏感信息(密码、密钥等)
- 直接在主分支上开发
Branch Management
分支管理
✅ Recommended:
- Use feature branches for development
- Regularly sync main branch code
- Delete branches promptly after feature completion
- Use merge to preserve history
--no-ff
❌ Prohibited:
- Developing directly on main branch
- Long-lived unmerged feature branches
- Non-standard branch naming
- Rebasing on public branches
✅ 推荐:
- 使用功能分支进行开发
- 定期同步主分支代码
- 功能完成后及时删除分支
- 使用合并保留历史
--no-ff
❌ 禁止:
- 直接在主分支上开发
- 长期存在未合并的功能分支
- 分支命名不规范
- 在公共分支上执行rebase
Code Review
代码评审
✅ Recommended:
- All code goes through Pull Requests
- At least one reviewer approval before merging
- Provide constructive feedback
❌ Prohibited:
- Merging without review
- Reviewing your own code
✅ 推荐:
- 所有代码都通过Pull Request提交
- 合并前至少获得1个评审人审批
- 提供有建设性的反馈意见
❌ 禁止:
- 未经评审直接合并
- 评审自己提交的代码
Additional Resources
额外资源
Reference Files
参考文件
For detailed guidance on specific topics:
- - Commit message detailed conventions and examples
references/commit-conventions.md - - Comprehensive branch management strategies
references/branching-strategies.md - - Merge, rebase, and conflict resolution strategies
references/merge-strategies.md - - Detailed conflict handling and prevention
references/conflict-resolution.md - - Git performance optimization, security, submodules, and advanced techniques
references/advanced-usage.md - - Pull request and code review guidelines
references/collaboration.md - - .gitignore patterns and project-specific configurations
references/gitignore-guide.md
特定主题的详细指南:
- - 提交信息详细约定和示例
references/commit-conventions.md - - 完整的分支管理策略
references/branching-strategies.md - - 合并、rebase和冲突解决策略
references/merge-strategies.md - - 详细的冲突处理和预防方法
references/conflict-resolution.md - - Git性能优化、安全、子模块等高级技巧
references/advanced-usage.md - - Pull Request和代码评审指南
references/collaboration.md - - .gitignore模式和项目专属配置
references/gitignore-guide.md
Example Files
示例文件
Working examples in :
examples/- - Good commit message examples
examples/commit-messages.txt - - Common workflow command snippets
examples/workflow-commands.sh
examples/- - 优秀提交信息示例
examples/commit-messages.txt - - 常用工作流命令片段
examples/workflow-commands.sh
Summary
总结
This document defines the project's Git standards:
- Commit Messages - Follow Conventional Commits specification
- Branch Management - master/develop/feature/bugfix/hotfix/release branch strategy
- Workflows - Standard processes for daily development, hotfixes, and releases
- Merge Strategy - Use rebase to sync feature branches, merge --no-ff to merge
- Tag Management - Semantic versioning, annotated tags
- Conflict Resolution - Regular syncing, small commits, team communication
Following these standards improves collaboration efficiency, ensures code quality, and simplifies version management.
本文档定义了项目的Git标准:
- 提交信息 - 遵循Conventional Commits规范
- 分支管理 - master/develop/feature/bugfix/hotfix/release分支策略
- 工作流程 - 日常开发、热修复、发布的标准流程
- 合并策略 - 功能分支同步用rebase,合并用merge --no-ff
- 标签管理 - 语义化版本,使用附注标签
- 冲突解决 - 定期同步、小粒度提交、团队沟通
遵循这些规范可以提升协作效率、保障代码质量、简化版本管理。