git 添加具有深度和分支选项的子模块

标签 git

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

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

我不太清楚如何使这项工作有效,请指教。

最佳答案

首先添加你的子模块,不要提及分支。

然后 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

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

关于git 添加具有深度和分支选项的子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34456530/

相关文章:

git - 基于主干开发的代码审查

git - 如何使用 git-replace 替换提交树

git - 使用 SSH 用户名和密码将 Git 项目导入 Aptana

git - 删除我文件夹中的所有 .gitignore 文件

git - 将两个或多个 git 分支拆分为一个 repo 的单独子目录?

git - 真的,一个在 Git 中 merge 比 SVN 更容易的具体例子?

git - 将我所有的提交压缩为 GitHub pull 请求

git - 使用 rebase 反向移植 git 分支

Git checkout 不会改变任何东西

git - 将 ssh key 添加到 gitlab