记录一下mermaid的gitGraph
fill:#333;important;important;fill:none;fill:none;fill:#333;git initgit commit -m 'feat: 登录页面'git commit -m 'feat: JWT验证'git commit -m 'test: 登录测试'v1.0mermaid。
·
Git 常用场景示例合集
示例 1:基础功能开发流程(Feature Branch)
mermaid
gitGraph
commit id: "git init"
commit id: "git commit -m 'init'"
branch feature/login
checkout feature/login
commit id: "1. git checkout -b feature/login"
commit id: "git commit -m 'feat: 登录页面'"
commit id: "git commit -m 'feat: JWT验证'"
commit id: "git commit -m 'test: 登录测试'"
checkout main
commit id: "2. git checkout main"
merge feature/login id: "3. git merge feature/login"
commit id: "git tag v1.0" tag: "v1.0"
示例 2:紧急热修复流程(Hotfix)
mermaid
gitGraph
commit id: "main: 线上稳定版" tag: "v1.0"
commit id: "main: 正常迭代中"
branch hotfix/crash
checkout hotfix/crash
commit id: "1. git checkout -b hotfix/crash" type: REVERSE
commit id: "fix: 修复空指针崩溃" type: REVERSE
commit id: "test: 验证修复" type: REVERSE
checkout main
merge hotfix/crash id: "2. git merge hotfix/crash"
commit id: "3. git tag v1.0.1" tag: "v1.0.1" type: HIGHLIGHT
branch dev
checkout dev
commit id: "4. git cherry-pick hotfix (同步修复)" type: HIGHLIGHT
示例 3:多人协作 rebase 同步(Rebase)
mermaid
gitGraph
commit id: "main: 初始提交"
branch dev
checkout dev
commit id: "dev: 公共基础代码"
branch feature/user-A
checkout feature/user-A
commit id: "A: git checkout -b feature/user-A"
commit id: "A: feat: 用户列表"
commit id: "A: feat: 用户详情"
checkout dev
commit id: "dev: 其他同事提交了新代码"
commit id: "dev: 又有新提交"
checkout feature/user-A
commit id: "1. git fetch origin dev" type: HIGHLIGHT
commit id: "2. git rebase dev (变基到最新)" type: HIGHLIGHT
commit id: "A: feat: 用户编辑(基于最新代码)"
checkout dev
merge feature/user-A id: "3. git merge feature/user-A (干净的线性历史)"
示例 4:版本发布流程(Release Branch)
mermaid
gitGraph
commit id: "main: v1.0" tag: "v1.0"
branch dev
checkout dev
commit id: "feat: 订单模块"
commit id: "feat: 支付模块"
commit id: "feat: 通知模块"
branch release/2.0
checkout release/2.0
commit id: "1. git checkout -b release/2.0"
commit id: "chore: bump version → 2.0.0"
commit id: "fix: 发布前修复问题A"
commit id: "fix: 发布前修复问题B"
commit id: "docs: 更新CHANGELOG"
checkout main
merge release/2.0 id: "2. git merge release/2.0"
commit id: "3. git tag -a v2.0 -m 'release'" tag: "v2.0" type: HIGHLIGHT
checkout dev
merge release/2.0 id: "4. git merge release/2.0 (修复同步回dev)"
示例 5:撤销与回退操作(Revert / Reset)
mermaid
gitGraph
commit id: "feat: 功能A(正常)"
commit id: "feat: 功能B(正常)"
commit id: "feat: 功能C(有问题!)" type: REVERSE
branch revert-demo
checkout revert-demo
commit id: "1. git revert HEAD (生成反向提交)" type: HIGHLIGHT
commit id: "功能C已被安全撤销(历史保留)"
checkout main
commit id: "2. git reset --soft HEAD~1 (保留改动退回暂存)" type: HIGHLIGHT
commit id: "3. 重新修改后 git commit"
branch amend-demo
checkout amend-demo
commit id: "git commit -m '手误写错的注释'" type: REVERSE
commit id: "4. git commit --amend -m '正确注释'" type: HIGHLIGHT
示例 6:stash 暂存现场切换分支(Stash)
mermaid
gitGraph
commit id: "main: 稳定代码"
branch feature/big-task
checkout feature/big-task
commit id: "feat: 大需求开发到一半..."
commit id: "1. git stash (临时保存现场)" type: HIGHLIGHT
checkout main
branch hotfix/urgent
checkout hotfix/urgent
commit id: "2. 切去修紧急bug" type: REVERSE
commit id: "fix: 紧急修复完成" type: REVERSE
checkout main
merge hotfix/urgent id: "git merge hotfix/urgent"
checkout feature/big-task
commit id: "3. git stash pop (恢复现场继续开发)" type: HIGHLIGHT
commit id: "feat: 继续完成大需求"
commit id: "feat: 大需求完工"
checkout main
merge feature/big-task id: "git merge feature/big-task"
示例 7:Squash 合并压缩提交(整洁历史)
mermaid
gitGraph
commit id: "main: 干净的主线"
branch feature/messy
checkout feature/messy
commit id: "wip: 先提交一下"
commit id: "fix: 刚才搞错了"
commit id: "fix: 又改了一下"
commit id: "wip: 临时保存"
commit id: "feat: 终于写完了"
commit id: "fix: review修改"
checkout main
commit id: "1. git merge --squash feature/messy" type: HIGHLIGHT
commit id: "2. git commit -m 'feat: 新功能(压缩为1个提交)'" type: HIGHLIGHT
commit id: "git tag v1.1" tag: "v1.1"
示例 8:多版本并行维护(Backport)
mermaid
gitGraph
commit id: "main: 长期维护中"
commit id: "feat: v2新特性A"
commit id: "feat: v2新特性B"
commit id: "git tag v2.0" tag: "v2.0" type: HIGHLIGHT
branch support/v1.x
checkout support/v1.x
commit id: "1. 维护旧版本 v1.x 分支"
commit id: "git tag v1.5" tag: "v1.5"
branch hotfix/security
checkout hotfix/security
commit id: "2. git checkout -b hotfix/security" type: REVERSE
commit id: "fix: 高危安全漏洞修复" type: REVERSE
checkout main
merge hotfix/security id: "3. git merge → main"
commit id: "git tag v2.0.1" tag: "v2.0.1" type: HIGHLIGHT
checkout support/v1.x
merge hotfix/security id: "4. git cherry-pick (backport到v1)" type: HIGHLIGHT
commit id: "git tag v1.5.1" tag: "v1.5.1" type: HIGHLIGHT
更多推荐


所有评论(0)