是一个完整的克隆子模块的唯一方法添加分支? [英] Is a full clone the only way to submodule add a branch?

查看:327
本文介绍了是一个完整的克隆子模块的唯一方法添加分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个引用特定(非主)分支的子模块。由于 - depth = 1 ,以下将只抓取主分支,所以命令将不可避免地失败;

  git submodule add -b myBranch --depth = 1 git@host.com:some / large / repo 

因为子模块add 不支持 - 单分支,这是否意味着我唯一的选择是克隆整个repo?

解决方案

git-克隆


- 深度 深度



创建一个历史截断为指定的克隆的浅克隆

- [no-] single -branch



只克隆通过--branch选项或主分支指定的单个分支尖端的历史

remote的HEAD指向。 使用
--depth选项创建浅度克隆时,这是默认的
,除非--no-single-branch
被用于获取提示附近的历史记录所有分支。
进一步提取到生成的存储库只会更新分支的
远程跟踪分支此选项用于
初始克隆。如果在创建单分支克隆时,远程的HEAD未指向任何
分支,则不会创建远程跟踪
分支。


因此,如果 git submodule add git clone 执行克隆,那么在你的用例中隐含 - 单分支。但是,只有当 git submodule add 转发 -b 选项到 git时,它才能正常工作克隆



实现所需结果的一种有保证的方式(不需要对 git submodule add )使用您所选择的选项自行完成 git clone 子模块存储库,然后将现有目录添加为子模块:

  git clone -b myBranch --single-branch --depth = 1 git@host.com:some / large / repo large_repo 
git submodule add -b myBranch git@host.com:some / large / repo large_repo




git子模块添加 选项 存储库 [路径]


...

...
$ b

path 是克隆子模块存在于
超级项目中的相对位置。如果路径不存在,则通过
克隆命名的URL创建子模块。 如果 path 确实存在并且已经是有效的
Git存储库,那么将其添加到变更集而不克隆

>


I want to add a submodule that references a specific (non-master) branch. The following will only grab the master branch due to --depth=1, so the command will inevitably fail;

git submodule add -b myBranch --depth=1 git@host.com:some/large/repo

Because submodule add doesn't support --single-branch, does this mean my only option is to clone the entire repo?

解决方案

From the documentation of git-clone:

--depth depth

Create a shallow clone with a history truncated to the specified

--[no-]single-branch

Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. When creating a shallow clone with the --depth option, this is the default, unless --no-single-branch is given to fetch the histories near the tips of all branches. Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is created.

Thus, if git submodule add performs the cloning with git clone, then in your use case --single-branch is implied. However, it will work correctly only if git submodule add forwards the -b option to git clone.

A guaranteed way of achieving the desired result (without making any assumptions about inner workings of git submodule add) is to git clone the submodule repository on your own using the options of your choice and then add the existing directory as a submodule:

git clone -b myBranch --single-branch --depth=1 git@host.com:some/large/repo large_repo
git submodule add -b myBranch git@host.com:some/large/repo large_repo

git submodule add options repository [path]

...

path is the relative location for the cloned submodule to exist in the superproject. If path does not exist, then the submodule is created by cloning from the named URL. If path does exist and is already a valid Git repository, then this is added to the changeset without cloning.

这篇关于是一个完整的克隆子模块的唯一方法添加分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆