排除子模块的子模块 [英] Exclude submodule of a submodule
问题描述
我有git repo,我可以在extern/
目录中使用git子模块链接我的一些依赖项.假设我有一个依赖项A
作为子模块,位于extern/A
.现在A
本身具有一些依赖项,如git子模块.在A
的仓库中,例如A/test/data/X
.
I have git repo where I link some of my dependencies using git submodules inside extern/
dir. Say I have a dependency A
as a submodule, located at extern/A
. Now A
itself has some dependencies as git submodules. In A
's repo, that is, eg. A/test/data/X
.
现在,当我克隆我的仓库并运行git submodule update --init --recursive
以便在CI服务器上构建它时,或者无论如何,我希望上面的命令忽略exter/A/test/data/X
,因为它就像1G的数据一样我不想的.
Now when I clone my repo, and run git submodule update --init --recursive
, in order to build it on a CI server, or w'ever, I'd like the above command to ignore exter/A/test/data/X
, because it's like 1G of data that I don't want.
但是,我的其他依赖项具有一些有用的子模块,因此我不能只跳过--recursive
.有办法吗?
My other dependencies however, have some useful submodules, so I can't just skip --recursive
. Is there a way to do this?
推荐答案
您可以使用submodule.<name>.update
config变量来设置应该更新哪个子模块,如此处所述
如何从更新中排除特定的git子模块?.
You can use submodule.<name>.update
config variable to set which submodule should be updated as mentioned here
How to exclude a specific git submodule from update?.
如果要排除A中的子模块X,则可以使用以下命令:
If you want to exclude the submodule X in A, then you can use the following command:
git -c submodule."X".update=none submodule update --init --recursive
注意:这假设仓库A中的子模块X(是extern的子模块)在整个仓库extern(包括其所有子模块,及其子模块,等等... ).如果X不是唯一的,则在回购extern中将跳过所有名为X的子模块.
Note: This assumes that the submodule X in repo A (which is a submodule of extern) is unique across the whole repo extern (including all its submodules, and their submodules and so on...) If X is not unique, then all submodules named X will be skipped in repo extern.
您可以在克隆过程中使用以下命令跳过子模块:
You can skip the submodules during the cloning process, using the following command:
$ git -c submodule."X".update=none clone --recurse-submodules <repository>
如果子模块位于存储库下的目录中,则相对于其存储库的相对路径应包含在子模块名称中.为避免混淆,可以从存储库中的.gitmodules
文件获取子模块名称.
If the submodule is located in a directory under the repository, then the relative path with respect to its repository should be included in the submodule name. To avoid any confusion, you can get the submodule name from the .gitmodules
file in the repository.
考虑以下示例.gitmodules
文件,
[submodule "path/to/submodule_X"]
path = path/to/submodule_X
url = https://github.com/<user>/<repo>
[submodule "Y"]
path = Y
url = https://github.com/<user>/<repo>
如果要跳过子模块X,则用此"path/to/submodule_X"
替换submodule.<name>.update
中的<name>
.嵌套子模块也是如此.
If you want to skip submodule X, then replace <name>
in submodule.<name>.update
with this "path/to/submodule_X"
. The same applies to nested submodules.
这篇关于排除子模块的子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!