WarmGrayMatteInkMistClaySage
RELIEF · GIT

Four pictures of a repository仓库的四张图

A branch is a groove — a channel a history travels along. A commit is a raised dot on it. A fork point is a hollow one, because it is not a commit of that branch at all. Three shapes, and the four questions below answer themselves.一条分支是一道凹槽 —— 历史从里面走过的通道。一次提交是槽上的一个凸点。分叉点是空心的,因为它根本不是这条分支的提交。三种形状,下面四个问题就自己有了答案。

1 · Branches and merges1 · 分支与合并

A branch is a groove running left to right and a commit is a raised dot sitting on it. The merge commit takes the accent, because the question a reader brings to a commit graph is almost always where did these two come back together — and a hollow dot is a point a branch was cut from, not a commit of its own.一条分支是一道从左往右的凹槽,一次提交是压在槽上的凸点。合并提交给强调色,因为读提交图的人问的几乎永远是这两支在哪汇回去的 —— 而空心的点是分支从那里切出来的位置,不是它自己的提交。

ONE SDK UPGRADE一次 SDK 升级the hollow dot on product/main is r8.1 — the point it was cut from, which is what a rebase would moveproduct/main 上那个空心点是 r8.1 —— 它切出来的位置,rebase 挪的就是这个点
upstream/mainvendor SDK厂商 SDK
r8.0
r8.1
r8.2
product/mainour fork我们的分叉
 
A
B
M
C
feature/tpone task一个任务
 
D
E
M

2 · Which clone may push2 · 哪个仓能推

Three clones of one repository, and the shape is the permission: the one that can push is raised, the fetch-only ones are grooves. This is not a convention to remember — the push remote is physically removed from the sunken ones. A capability you can only break by editing config is worth more than one you keep by being careful.同一个仓库的三份克隆,而且形状就是权限:能推的凸起,只能 fetch 的是凹槽。这不是记在心里的约定 —— 凹的那两个 push 远端是物理删掉的。一个只能靠改配置才能破坏的限制,比一个靠小心保持的限制值钱。

GATEWAY / SATELLITE / CLEAN-VERIFYgateway / satellite / clean-verifyclean-verify exists to answer one question: does what I pushed build, or only what is on my diskclean-verify 只回答一个问题:我推上去的东西编得过吗,还是只有我盘上那份编得过

gateway

The only clone that can push. Kept small and never built in, so a stray object file can never ride along with a commit.唯一能推的克隆。保持干净、从不在里面编译,所以一个漏下的目标文件永远搭不上提交的车。

push ✓build ✗HDD

satellite

Where the build runs. Fetch-only on purpose — the push remote is removed, not just discouraged.编译在这里跑。故意设成只能 fetch —— push 的远端是删掉的,不是靠自觉不推。

push ✗build ✓SSD

clean-verify

A fresh clone of what was actually pushed. If it builds here, the commit is complete; if it does not, something only existed on your disk.把真正推上去的东西重新克隆一份。在这里编得过,提交才是完整的;编不过,说明有东西只存在于你自己的盘上。

push ✗build ✓throwaway用完即弃

3 · Where a fix travelled3 · 一个修复流到了哪

The same change carried onto three product branches. The commit ids differ because cherry-pick rewrites them — which is exactly why you cannot ask git whether product C already has it by comparing hashes. The hollow dot is the branch that has not taken it, and that is the only thing this figure is for.同一个改动搬到三条产品分支上。提交 id 各不相同,因为 cherry-pick 会重写它们 —— 这正是你没法靠比对 hash 去问 git「产品 C 拿到没有」的原因。空心的那个点是还没拿的分支,这张图就为说这一件事而存在。

ONE FIX, THREE PRODUCTS一个修复,三个产品cherry-pick -x writes the original id into the message; without it this figure cannot be reconstructed latercherry-pick -x 会把原始 id 写进提交信息;不加它,这张图事后就重建不出来了
fix commitwhere it was written原始提交
F
product Acherry-pickcherry-pick
F'
product Bcherry-pickcherry-pick
F''
product Cnot taken yet还没拿
?

4 · Ahead, behind, or both4 · 领先、落后,还是两头都有

Three refs on one axis. Hollow dots are the commits a ref already shares with the others, raised ones are what only it has. Ahead and behind are not opposites — this layout shows a branch that is three ahead of its own remote and two behind upstream at the same time, which is the state that makes people run the wrong command.一根轴上三个 ref。空心点是这个 ref 和别人共有的提交,凸起的是只有它自己有的。领先和落后不是对立的两件事 —— 这张图画的分支同时领先自己的远端 3 个、落后上游 2 个,而这正是让人敲错命令的那种状态。

git status -sb SAYS [ahead 3]git status -sb 显示 [ahead 3]it says ahead of ORIGIN. It says nothing at all about upstream, and that is the sentence people finish in their head它说的是领先 origin。它对上游只字未提 —— 而人们会在脑子里自己把这句话补完
origin/mainwhat is pushed已经推上去的
·
·
·
local mainahead 3领先 3
·
·
·
1
2
3
upstream/mainbehind 2落后 2
·
·
·
x
y