git add submodule with depth和branch options

时间:2015-12-24 18:17:17

标签: git

使用git 2.4.3(Fedora 22),我可以使用--depth-b选项克隆回购:

$ 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分支上作为二进制对象分发。只有最新的二进制文件是相关的。

对我来说,如何完成这项工作并不明显,请指教。

1 个答案:

答案 0 :(得分: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

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