2015-12-24 40 views
3

使用Git 2.4.3(Fedora的22),我可以使用--depth-b選項克隆回購:git的子模塊添加深度和分支選項

$ git clone --depth 1 -b release https://github.com/adobe-fonts/source-code-pro.git fonts/source-code-pro 
Cloning into 'fonts/source-code-pro'...          
remote: Counting objects: 114, done. 
remote: Compressing objects: 100% (113/113), done. 
remote: Total 114 (delta 1), reused 105 (delta 1), pack-reused 0 
Receiving objects: 100% (114/114), 7.27 MiB | 2.85 MiB/s, done. 
Resolving deltas: 100% (1/1), done. 
Checking connectivity... done. 

理論上git submodule add應該支持相同的選項。不幸的是它似乎不工作:

$ mkdir foo 
$ cd foo 
$ git init 
Initialized empty Git repository in /spare/local/arankine/foo/.git/ 
$ git submodule add --depth 1 -b release https://github.com/adobe-fonts/source-code-pro.git fonts/source-code-pro       
Cloning into 'fonts/source-code-pro'... 
remote: Counting objects: 35853, done. 
remote: Compressing objects: 100% (5932/5932), done. 
remote: Total 35853 (delta 35196), reused 30018 (delta 29921), pack-reused 0 
Receiving objects: 100% (35853/35853), 12.95 MiB | 3.06 MiB/s, done. 
Resolving deltas: 100% (35196/35196), done. 
Checking connectivity... done. 
fatal: Cannot update paths and switch to branch 'release' at the same time. 
Did you intend to checkout 'origin/release' which can not be resolved as commit? 
Unable to checkout submodule 'fonts/source-code-pro' 

這樣做的目的是儘量減少這些字體,其分佈情況對回購的release分支二進制對象所需的磁盤空間。只有最新的二進制文件是相關的。

這並不明顯如何使這項工作,請告知。

回答

0

首先添加您的子模塊,而不提及分支。

然後make your submodule track the right branch

cd /path/to/your/parent/repo 
git config -f .gitmodules submodule.<path>.branch <branch> 

cd path/to/your/submodule 
git checkout -b branch --track origin/branch 
# if the master branch already exist: 
git branch -u origin/master master 

您可能需要提高深度以包含想要分支的一部分提交,而不是默認的主分支的一部分提交。

+0

這是如何達到預期效果的?我認爲這與刪除'submodule add'中的'--depth'參數基本相同,還是我錯過了一些東西?爲了清楚起見,我編輯了這個問題來描述所需的結果。 – Alastair

+0

@AlastairRankine的想法是使用子模塊添加--depth,*然後*嘗試和切換分支。 – VonC