managing-git
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseManaging Git
Git管理
When to Load
适用场景
- Trigger: Branching strategies, commit workflows, pull requests, merge conflicts, version control questions
- Skip: Tasks that do not involve git operations
- 触发条件:分支策略、提交流程、pull request、合并冲突、版本控制相关问题
- 不适用:不涉及Git操作的任务
Feature Development Workflow
功能开发工作流
Copy this checklist and track progress:
Feature Development Progress:
- [ ] Step 1: Create feature branch from main
- [ ] Step 2: Make changes with atomic commits
- [ ] Step 3: Rebase on latest main
- [ ] Step 4: Push and create PR
- [ ] Step 5: Address review feedback
- [ ] Step 6: Merge after approval复制以下清单跟踪进度:
Feature Development Progress:
- [ ] Step 1: Create feature branch from main
- [ ] Step 2: Make changes with atomic commits
- [ ] Step 3: Rebase on latest main
- [ ] Step 4: Push and create PR
- [ ] Step 5: Address review feedback
- [ ] Step 6: Merge after approvalBranching Strategies
分支策略
GitHub Flow (Recommended for most projects)
GitHub Flow(多数项目推荐)
main ──●────●────●────●────●── (always deployable)
\ /
feature └──●──●──┘- is always deployable
main - Feature branches from main
- PR + review + merge
- Deploy after merge
main ──●────●────●────●────●── (always deployable)
\ /
feature └──●──●──┘- 分支始终处于可部署状态
main - 功能分支从main分支拉出
- 提交PR + 代码评审 + 合并
- 合并后完成部署
Git Flow (For release-based projects)
Git Flow(适用于基于版本发布的项目)
main ──●─────────────●────── (releases only)
\ /
release └────●────┘
/
develop ──●──●────●──●──●──
\ /
feature └──●┘main ──●─────────────●────── (releases only)
\ /
release └────●────┘
/
develop ──●──●────●──●──●──
\ /
feature └──●┘Commit Conventions
提交规范
Conventional Commits Format
Conventional Commits 格式
<type>(<scope>): <description>
[optional body]
[optional footer(s)]<type>(<scope>): <description>
[optional body]
[optional footer(s)]Types
提交类型
| Type | Description |
|---|---|
| New feature |
| Bug fix |
| Documentation only |
| Formatting, no logic change |
| Code change that neither fixes bug nor adds feature |
| Performance improvement |
| Adding/updating tests |
| Build process, dependencies |
| CI configuration |
| 类型 | 说明 |
|---|---|
| 新增功能 |
| 修复Bug |
| 仅文档变更 |
| 代码格式调整,无逻辑变更 |
| 既不修复Bug也不新增功能的代码变更 |
| 性能优化 |
| 新增/更新测试用例 |
| 构建流程、依赖项相关变更 |
| CI配置相关变更 |
Examples
示例
bash
feat(auth): add OAuth2 login support
Implements Google and GitHub OAuth providers.
Closes #123
BREAKING CHANGE: Session tokens now expire after 24hbash
fix(api): handle null response from payment gateway
Previously caused 500 error when gateway returned null.
Now returns appropriate error message to user.bash
feat(auth): add OAuth2 login support
Implements Google and GitHub OAuth providers.
Closes #123
BREAKING CHANGE: Session tokens now expire after 24hbash
fix(api): handle null response from payment gateway
Previously caused 500 error when gateway returned null.
Now returns appropriate error message to user.Branch Naming
分支命名
<type>/<ticket-id>-<short-description><type>/<ticket-id>-<short-description>Examples
Examples
feature/AUTH-123-oauth-login
fix/BUG-456-null-pointer
chore/TECH-789-upgrade-deps
undefinedfeature/AUTH-123-oauth-login
fix/BUG-456-null-pointer
chore/TECH-789-upgrade-deps
undefinedPull Request Workflow
Pull Request 工作流
Copy this checklist when creating PRs:
PR Checklist:
- [ ] Code follows project conventions
- [ ] Tests added/updated for changes
- [ ] All tests pass locally
- [ ] No merge conflicts with main
- [ ] Documentation updated if needed
- [ ] No security vulnerabilities introduced
- [ ] PR description explains the "why"创建PR时可复制以下清单:
PR Checklist:
- [ ] Code follows project conventions
- [ ] Tests added/updated for changes
- [ ] All tests pass locally
- [ ] No merge conflicts with main
- [ ] Documentation updated if needed
- [ ] No security vulnerabilities introduced
- [ ] PR description explains the "why"PR Template
PR模板
markdown
undefinedmarkdown
undefinedSummary
摘要
[Brief description of changes]
[变更内容简要说明]
Changes
变更内容
- [Change 1]
- [Change 2]
- [变更1]
- [变更2]
Testing
测试说明
- Unit tests added/updated
- Manual testing performed
- E2E tests pass
- 已新增/更新单元测试
- 已完成手动测试
- E2E测试全部通过
Screenshots (if UI changes)
截图(如有UI变更)
[Before/After screenshots]
undefined[变更前/变更后截图]
undefinedPR Size Guidelines
PR大小规范
| Size | Lines Changed | Review Guidance |
|---|---|---|
| XS | < 50 | Quick review |
| S | 50-200 | Standard review |
| M | 200-500 | Thorough review |
| L | 500+ | Split if possible |
| 大小 | 改动行数 | 评审建议 |
|---|---|---|
| XS | < 50 | 快速评审 |
| S | 50-200 | 标准评审 |
| M | 200-500 | 全面评审 |
| L | 500+ | 尽量拆分提交 |
Common Git Commands
常用Git命令
Daily Workflow
日常工作流
bash
undefinedbash
undefinedStart new feature
Start new feature
git checkout main
git pull
git checkout -b feature/TICKET-123-description
git checkout main
git pull
git checkout -b feature/TICKET-123-description
Commit changes
Commit changes
git add -p # Stage interactively
git commit -m "feat: description"
git add -p # Stage interactively
git commit -m "feat: description"
Keep up with main
Keep up with main
git fetch origin main
git rebase origin/main
git fetch origin main
git rebase origin/main
Push and create PR
Push and create PR
git push -u origin HEAD
undefinedgit push -u origin HEAD
undefinedFixing Mistakes
错误修正
bash
undefinedbash
undefinedAmend last commit (before push)
Amend last commit (before push)
git commit --amend
git commit --amend
Undo last commit (keep changes)
Undo last commit (keep changes)
git reset --soft HEAD~1
git reset --soft HEAD~1
Undo last commit (discard changes)
Undo last commit (discard changes)
git reset --hard HEAD~1
git reset --hard HEAD~1
Revert a pushed commit
Revert a pushed commit
git revert <commit-hash>
git revert <commit-hash>
Interactive rebase to clean up
Interactive rebase to clean up
git rebase -i HEAD~3
undefinedgit rebase -i HEAD~3
undefinedAdvanced Operations
高级操作
bash
undefinedbash
undefinedCherry-pick specific commit
Cherry-pick specific commit
git cherry-pick <commit-hash>
git cherry-pick <commit-hash>
Find which commit broke something
Find which commit broke something
git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>
git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>
Stash with message
Stash with message
git stash push -m "WIP: feature description"
git stash list
git stash pop
undefinedgit stash push -m "WIP: feature description"
git stash list
git stash pop
undefinedCommit Validation
提交校验
Before pushing, validate commits:
Commit Validation:
- [ ] Each commit has a clear, descriptive message
- [ ] Commit type matches the change (feat, fix, etc.)
- [ ] No WIP or temporary commits
- [ ] No secrets or credentials committed
- [ ] Changes are atomic (one logical change per commit)If validation fails, use to clean up commit history before pushing.
git rebase -i推送前请校验提交内容:
Commit Validation:
- [ ] Each commit has a clear, descriptive message
- [ ] Commit type matches the change (feat, fix, etc.)
- [ ] No WIP or temporary commits
- [ ] No secrets or credentials committed
- [ ] Changes are atomic (one logical change per commit)如果校验不通过,可在推送前使用清理提交历史。
git rebase -i