Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
git submodule && subtree
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Zhe Yu
April 01, 2014
Technology
100
0
Share
git submodule && subtree
Zhe Yu
April 01, 2014
More Decks by Zhe Yu
See All by Zhe Yu
git submodule && git subtree
lazynight
0
290
Other Decks in Technology
See All in Technology
No Types Needed, Just Callable Method Check
dak2
1
2.6k
Keeping Ruby Running on Cygwin
fd0
0
190
コードや知識を組み込む / Incorporate Code and Knowledge
ks91
PRO
0
190
Percolatorを廃止し、マルチ検索サービスへ刷新した話 / Search Engineering Tech Talk 2026 Spring
visional_engineering_and_design
0
220
20260428_Product Management Summit_tadokoroyoshiro
tadokoro_yoshiro
15
17k
需要創出(Chatwork)×供給(BPaaS) フライホイールとMoat 実行能力の最適配置とAI戦略
kubell_hr
0
1.6k
AIが盛んな時代に 技術記事を書き始めて起きた私の中での小さな変化
peintangos
0
340
アクセシビリティはすべての人のもの
tomokusaba
0
190
運用システムにおけるデータ活用とPlatform
sansantech
PRO
0
150
データ定義の混乱と戦う 〜 管理会計と財務会計 〜
wonohe
0
170
GitHub Copilot CLI と VS Code Agent Mode の使い分け
tomokusaba
0
120
Modernizing Your HCL Connections Experience: Visual Report to chain, Profile Enhancements, and AI Integration
wannesrams
0
240
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
110
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Facilitating Awesome Meetings
lara
57
6.8k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
230
Balancing Empowerment & Direction
lara
6
1.1k
Un-Boring Meetings
codingconduct
0
280
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Git: the NoSQL Database
bkeepers
PRO
432
67k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
Scaling GitHub
holman
464
140k
Transcript
Git Subtree解说 by于哲 2014.3.31
场景 对于⼀一些⽐比较⼤大的⼯工程,为了便于复⽤用,常常需要抽取⼦子 项⺫⽬目 A B C
⽅方案1:git submodule ! ⽅方案2:git subtree
git submodule submodule项⺫⽬目和它的⽗父项⺫⽬目本质上是2个独⽴立的git仓库, 只是⽗父项⺫⽬目存储了它依赖的submodule项⺫⽬目的版本号信息⽽而已。 坑: • git pull之后,需要 git submodule
update • detached HEAD state,需要 git checkout master • git clone 之后,需要 git submodule init & update • messy,etc
git subtree 简介: 替代git submodule 命令,合并⼦子仓库到项⺫⽬目中并放在⼦子 ⺫⽬目录,管理、更新都更加⽅方便。 要求: git version
> 1.8.0.0 if git version < 1.8.0.0: go https://github.com/apenwarr/git-subtree
why git subtree? • 管理和更新流程⽐比较⽅方便 • git v1.5.2以后建议使⽤用git subtree (git
v1.8.0.0 才合并进来) • 仓库 clone下来不需要 init 和 update • 不会产⽣生像.gitmodule类似的⽂文件 • git submodule 删除起来⽐比较费劲 • 另外还有⼀一些团队协作时的尴尬问题
如何使⽤用git subtree? 前期准备: ! 创建本地项⺫⽬目(两个项⺫⽬目,⼀一个库): git --git-dir=proj1.git init --bare git
--git-dir=proj2.git init —bare git --git-dir=lib1.git init —bare ! ! 填充数据,提交,etc
如何使⽤用git subtree? ! ! 1. git remote add -f <⼦子仓库名>
<⼦子仓库地址> ! 其中-f意思是在添加远程仓库之后,⽴立即执⾏行fetch ! 2. git subtree add --prefix=<⼦子⺫⽬目录名> <⼦子仓库名> <分⽀支> —squash ! —squash意思是把subtree的改动合并成⼀一次commit,这样就不⽤用拉取⼦子 项⺫⽬目完整的历史记录。 ! --prefix之后的=等号也可以⽤用空格。 ! ! 添加⼦子⺫⽬目录,建⽴立与git项⺫⽬目的关联
如何使⽤用git subtree? ! ! 1. git fetch <远程仓库名> <分⽀支> !
2. git subtree pull --prefix=<⼦子⺫⽬目录名> <远程分⽀支> <分 ⽀支> --squash ! ! ! 从远程仓库更新⼦子⺫⽬目录
如何使⽤用git subtree? ! ! 1. git subtree push --prefix=<⼦子⺫⽬目录名> <远程分⽀支名>
分⽀支 ! ! ! ! ! 从⼦子⺫⽬目录push到远程仓库
参考 • http://aoxuis.me/posts/2013/08/07/git-subtree/ • http://blogs.atlassian.com/2013/05/alternatives-to-git- submodule-git-subtree/
THANK YOU @jackyu