Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 知乎專欄 | 視頻教程 | About

11.4. Submodule 子模組

11.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		
		
		
11.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'			
		
		
11.4.3. 刪除子模組
		
git rm --cached <module>