gpt4 book ai didi

git - 完整克隆是子模块添加分支的唯一方法吗?

转载 作者:太空狗 更新时间:2023-10-29 13:25:17 26 4
gpt4 key购买 nike

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

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

因为 submodule add 不支持 --single-branch,这是否意味着我唯一的选择是克隆整个 repo?

最佳答案

来自documentation of git-clone :

--depth depth

Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches.

--[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.

因此,如果 git submodule add 使用 git clone 执行克隆,则在您的用例中隐含了 --single-branch。但是,只有当 git submodule add-b 选项转发给 git clone 时,它才会正常工作。

实现预期结果的保证方法(不对 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 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.

关于git - 完整克隆是子模块添加分支的唯一方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38089816/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com