架构图
+============================================================+
| git branch vs worktree |
| one repo, multiple branch checkouts |
+============================================================+
+------------------------------------------------------------+
| BRANCHES (refs, no files) |
| feature-mesh |
| demo-ipynb |
| node |
| names are conventions, not types |
+------------------------------------------------------------+
| checkout
v
+------------------------------------------------------------+
| WORKTREES (directories) |
| main dir -> feature-mesh |
| .worktrees/demo-ipynb -> demo-ipynb |
| .worktrees/node -> node |
| shared .git object database |
+------------------------------------------------------------+
| commit
v
+------------------------------------------------------------+
| MERGE FLOW |
| work on worktree branch |
| commit on that branch |
| merge branch into target |
| target dir gets the changes |
+------------------------------------------------------------+
关系说明
- Branch 是提交指针,不含文件副本;worktree 是同一个仓库的额外检出目录。
- 主目录和各 worktree 共享
.git 对象库,但各自有独立工作区与 index。
- worktree 不改变分支模型,也不复制仓库;它只把指定本地分支检出到另一目录。
- worktree 的起点可以是本地分支、远端跟踪分支、tag 或 commit。
- 改动先在 worktree 对应分支提交,再把该分支合并到目标分支,主目录代码才会更新。
- “二次 feature”只是从某条 feature 分支继续开新分支;Git 不记录父分支,只记录 commit 历史。
- 任务信息空间不是 worktree;无代码版本管理需求的临时产物应放 scratch 或 task workspace。