| name | Git 工作流 |
| description | 分支命名、merge 与 rebase、冲突解决、stash 用法、仓库清理(gc、prune) |
| version | 1.0 |
Git 工作流
日常 Git 操作的最佳实践和常见命令。
分支命名约定
| 类型 | 示例 |
|---|
| 功能 | feature/user-login、feat/api-v2 |
| 修复 | fix/payment-bug、hotfix/security-patch |
| 发布 | release/1.2.0 |
| 个人开发 | dev/username、yushen/xxx |
Merge 与 Rebase
git checkout main
git merge feature-branch
git checkout feature-branch
git rebase main
原则:已推送的公共分支用 merge;个人分支可 rebase 后 force push。
冲突解决步骤
git pull origin main
git status
git add <resolved-files>
git commit
Stash 用法
git stash push -m "WIP: 描述"
git stash push -u -m "含未跟踪"
git stash pop
git stash apply
git stash list
git stash drop stash@{0}
仓库清理
git gc --aggressive
git fetch --prune
git remote prune origin
git reflog expire --expire=now --all
git gc --prune=now