Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 知乎专栏 | 视频教程 | About

180.4. Submodule 子模块

180.4.1. 添加模块

		
neo@MacBook-Pro ~ % cd workspace/Linux
		
neo@MacBook-Pro ~/workspace/Linux % git submodule add https://github.com/netkiller/common.git common 
Cloning into '/Users/neo/workspace/Linux/common'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 185 (delta 2), reused 6 (delta 1), pack-reused 176
Receiving objects: 100% (185/185), 56.49 KiB | 163.00 KiB/s, done.
Resolving deltas: 100% (105/105), done.		
		
		

模块信息存储在 .gitmodules 文件中

		
neo@MacBook-Pro ~/workspace/Linux % cat .gitmodules  
[submodule "common"]
	path = common
	url = https://github.com/netkiller/common.git		
		
		

同时也添加到 .git/config 文件中

		
neo@MacBook-Pro ~/workspace/Linux % cat .git/config | tail -n 3
[submodule "common"]
	url = https://github.com/netkiller/common.git
	active = true		
		
		

180.4.2. checkout 子模块

clone 项目,然后进入目录

		
neo@MacBook-Pro /tmp/test % git clone https://github.com/netkiller/Linux.git
neo@MacBook-Pro /tmp/test % cd Linux
		
		

初始化子模块

		
neo@MacBook-Pro /tmp/test/Linux % git submodule init
Submodule 'common' (https://github.com/netkiller/common.git) registered for path 'common'
		
		

更新模块

		
neo@MacBook-Pro /tmp/test/Linux % git submodule update
Cloning into '/private/tmp/test/Linux/common'...
Submodule path 'common': checked out 'cdf61a1de34590bcc80b895fdf0e90b62cfd729f'			
		
		

180.4.3. 删除子模块

		
git rm --cached <module>