惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security @ Cisco Blogs
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
C
CERT Recently Published Vulnerability Notes
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cisco Blogs
博客园 - 司徒正美
L
LINUX DO - 热门话题
D
Docker
M
MIT News - Artificial intelligence
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
Jina AI
Jina AI
Last Week in AI
Last Week in AI
Security Latest
Security Latest
The Hacker News
The Hacker News
L
Lohrmann on Cybersecurity
Y
Y Combinator Blog
A
Arctic Wolf
小众软件
小众软件
T
Threat Research - Cisco Blogs
Know Your Adversary
Know Your Adversary
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
I
InfoQ
腾讯CDC
Google DeepMind News
Google DeepMind News
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 叶小钗
I
Intezer
NISL@THU
NISL@THU
A
About on SuperTechFans
爱范儿
爱范儿
C
Cybersecurity and Infrastructure Security Agency CISA
D
Darknet – Hacking Tools, Hacker News & Cyber Security
G
Google Developers Blog
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Cyberwarzone
Cyberwarzone
AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
Latest news
Latest news

博客园 - ddrsql

从“黑盒”到“全景”:在.NET中拥抱OpenTelemetry与SigNoz的可观测工具 记录团队使用git合并代码丢失 记一次对老服务改造 国产麒麟(Kylin-Server-10)系统无外网环境安装docker vue3学习之axios、mockjs、nswag vue3学习之tabler组件Layout布局 vue3学习之BootstrapVueNext Framework升级到Core以及Dapper支持达梦数据库 Avalonia集成Prism与Abp Avalonia中使用EF增删改查DM数据库 Linux中使用原生Wpf之Avalonia WPF通过wine适配统信uos系统 单体仓库下通过helm优雅的将微服务部署到k8s DevOps 前端项目(angular、vue、react)打包静态资源生成一份Docker镜像支持部署不同环境 VS使用IIS调试(非附加进程).net core、.net framework程序 k8s集群通过nginx-ingress做tcp、udp 4层网络转发 DevOps .net core Jenkins持续集成Linux、Docker、K8S swaggerui集成oauth implicit redis cluster集群web管理工具 relumin
关于git分支堆叠
ddrsql · 2025-08-18 · via 博客园 - ddrsql

git stack 是一种 堆叠式分支管理(Stacked Branch Management)工作流工具,它的核心思想是: 把多个有依赖关系的功能分支像“积木”一样堆叠起来,按顺序开发、审查和合并,而不是一次性在一个大分支里完成所有改动。
https://www.stacking.dev/
https://graphite.dev/blog/stacked-prs
https://graphite.dev/blog/the-ideal-pr-is-50-lines-long
https://graphite.dev/blog/how-large-prs-slow-down-development
https://andrewlock.net/working-with-stacked-branches-in-git-part-1/
https://andrewlock.net/working-with-stacked-branches-in-git-part-2/

堆叠

gitGraph commit id: "M0" branch feature/base commit id: "base1" commit id: "base2" branch feature/middle commit id: "middle1" branch feature/top commit id: "top1" commit id: "top2" checkout main commit id: "M1"

image

$ git checkout feature/top
Already on 'feature/top'
$ git rebase main --update-refs
Successfully rebased and updated refs/heads/feature/top.
Updated the following refs with --update-refs:
        refs/heads/feature/base
        refs/heads/feature/middle

image

长分支

核心目标

  • 多人并行开发:每个人负责一个子功能,但都挂在同一个功能栈(stack)上
  • 保持主干稳定:功能没完成前,主干(main/master)不被污染
  • 可控合并顺序:按依赖关系逐层合并,避免一次性大冲击

协作小技巧

  • 命名规范:feature/xxx-partN,方便识别顺序
  • 频繁同步:每天 git fetch + git rebase,避免冲突堆积
  • 并行开发:不同成员可在同一 stack 的不同分支上工作,但要明确依赖关系
  • 自动化检查:CI/CD 针对每个子分支运行测试,提前发现问题

初始化

点击查看代码
# M0
chcp 65001
mkdir Test
cd Test
git init -b main
echo 初始化内容 > init.txt
git add .
git commit -m "初始化提交"

# base1
chcp 65001
cd Test
git checkout main
git checkout -b feature/base
echo base内容-1 > base.txt
git add .
git commit -m "base提交-1"

# middle1
chcp 65001
cd Test
git checkout feature/base
git checkout -b feature/middle
echo middle内容-1 > middle.txt
git add .
git commit -m "middle提交-1"

# top1
chcp 65001
cd Test
git checkout feature/middle
git checkout -b feature/top
echo top内容-1 > top.txt
git add .
git commit -m "top提交-1"

# top2
chcp 65001
cd Test
git checkout feature/top
echo top内容-2 >> top.txt
git add .
git commit -m "top提交-2"

# base2
chcp 65001
cd Test
git checkout feature/base
echo base内容-2 >> base.txt
git add .
git commit -m "base提交-2"

# M1
chcp 65001
cd Test
git checkout main
echo main-1 >> init.txt
git add .
git commit -m "main-1提交"

gitGraph commit id: "M0" branch feature/base commit id: "base1" branch feature/middle commit id: "middle1" branch feature/top commit id: "top1" commit id: "top2" checkout feature/base commit id: "base2" checkout main commit id: "M1"

image

切换到feature/top进行rebase main

$ git checkout feature/top
Already on 'feature/top'
$ git rebase main --update-refs
Successfully rebased and updated refs/heads/feature/top.
Updated the following refs with --update-refs:
        refs/heads/feature/middle

image

切换到feature/base进行rebase main

$ git checkout feature/base
Switched to branch 'feature/base'
$ git rebase main --update-refs
Successfully rebased and updated refs/heads/feature/base.

image

切换到feature/top进行rebase base

$ git checkout feature/top
Already on 'feature/top'
$ git rebase feature/base --update-refs
warning: skipped previously applied commit 935fa8b
hint: use --reapply-cherry-picks to include skipped commits
hint: Disable this message with "git config advice.skippedCherryPicks false"
Successfully rebased and updated refs/heads/feature/top.
Updated the following refs with --update-refs:
        refs/heads/feature/middle

image

#解决冲突继续rebase
git rebase --continue
#终止rebase
git rebase --abort

#设置默认启用--update-refs
git config --global --add --bool rebase.updateRefs true

普通rebase

image

gitlab上操作

base、middle、top合并完成效果
image

git命令扩展

--update-refs 是 Git 在 2.38 版本中引入的新选项
git default-branch 默认分支
git merge-base-origin 获取当前分支与默认分支最近共同祖先
git stack 查看当前分支堆叠
git push-stack 推送所在分支及堆叠上游分支
在 C:\Users\UserName\.gitconfig 文件中添加

[alias]
	default-branch = "!git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'"
	merge-base-origin ="!f() { git merge-base ${1-HEAD} origin/$(git default-branch); };f "
	stack = "!f() { \
		BRANCH=${1-HEAD}; \
		MERGE_BASE=$(git merge-base-origin $BRANCH); \
		git log --decorate-refs=refs/heads --simplify-by-decoration --pretty=format:\"%(decorate:prefix=,suffix=,tag=,separator=%n)\" $MERGE_BASE..$BRANCH; \
	};f "
	push-stack = "!f() { \
		BRANCH=${1-HEAD}; \
		git stack $BRANCH | xargs -I {} git push --force-with-lease origin {}; \
	};f "

git-spice

https://github.com/abhinav/git-spice

安装

下载gs命令解压后把gs.exe拷贝到 C:\Program Files\Git\cmd 目录

配置

https://abhinav.github.io/git-spice/setup/auth/#gitlab-self-hosted

# 自托管设置
git config spice.forge.gitlab.url https://gitlab.example.com

# gitlab 用户设置 -> 访问令牌 -> 添加新token 后auth
gs auth login

使用

Your first stack

https://abhinav.github.io/git-spice/start/stack/

Your first stacked Change Requests

https://abhinav.github.io/git-spice/start/submit/

gs branch submit 到远端效果
image