Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
git submodule && git subtree
Search
Zhe Yu
April 01, 2014
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
git submodule && git subtree
Zhe Yu
April 01, 2014
More Decks by Zhe Yu
See All by Zhe Yu
git submodule && subtree
lazynight
0
110
Featured
See All Featured
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Product Roadmaps are Hard
iamctodd
55
13k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
330
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
Mind Mapping
helmedeiros
1
370
ラッコキーワード サービス紹介資料
rakko
1
5M
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
850
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
The Spectacular Lies of Maps
axbom
PRO
1
1k
Color Theory Basics | Prateek | Gurzu
gurzu
1
470
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
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 才合并进来) cd git/contrib/subtree && make && sudo install -m 755 git-subtree /usr/lib/git-core • 仓库 clone下来不需要 init 和 update • 不会产⽣生像.gitmodule类似的⽂文件 • 可以以分⽀支形式切换依赖库
如何使⽤用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到远程仓库
git subtree原理 libs master new master
git subtree原理 • git read-tree 更新暂存区 • git write-tree 保存暂存区⺫⽬目录树
• git commit-tree porcelain瓷器 • git branch • git commit • git push • etc plumbing⽔水管
git subtree原理 • git read-tree —prefix=libs/lib1 lib1 • git write-tree
• echo "subtree merge" | git commit-tree id -p id1 -p id2 • git reset id
参考 • http://aoxuis.me/posts/2013/08/07/git-subtree/ • http://blogs.atlassian.com/2013/05/alternatives-to-git- submodule-git-subtree/ • http://www.worldhello.net/2010/10/31/2041.html
THANK YOU @jackyu