gpt4 book ai didi

git clone 浅子模块

转载 作者:行者123 更新时间:2023-12-04 02:00:12 26 4
gpt4 key购买 nike

我添加了几个 git 子模块,它们在 .gitmodules 中配置。我对子模块的特定提交感兴趣。因此,我提交了这些提交,并且可以在 git submodule status 中看到。说为

[submodule "pcl"]
path = libs/pcl
url = https://github.com/PointCloudLibrary/pcl.git

子模块状态显示 757e28a75a0c6c0413085a2af070670828a48527 libs/pcl。这意味着上面的 SHA1 将在运行 git submodule update --init

后被 check out

但是,我的问题是我不想完全克隆子模块 pcl,因为我只对从 757e28a75a0c6c0413085a2af070670828a48527 开始的提交感兴趣。有没有办法通过在 .gitmodules 文件中写入深度参数等来实现这一点?

我看过几篇文章,但大多数都建议做一个 git add submodule。因为,我已经这样做了,有没有办法为每个子模块编辑带有深度参数的 .gitmodule 文件。

git clone --depth 10 --shallow-submodules <repo>

在我看来会 pull 主分支的 10 次提交,然后 pull 所有子模块的主分支的尖端。我的理解正确吗?

最佳答案

找到了解决该问题的方法,这可能会对其他人有所帮助。

目标是浅克隆子模块。通过执行以下步骤,项目(包括子模块)的大小从 30 GB 减少到 2 GB。该项目由许多不断开发的子模块组成,例如 opencv、ffmpeg、pcl、mrpt 等。

.gitmodule 只包含子模块名称、路径和 url(因此没有花哨的配置选项),就像这样

[submodule "pcl"]
path = libs/pcl
url = https://github.com/PointCloudLibrary/pcl.git

因此,从克隆开始,然后初始化子模块,最后更新子模块。

git clone --depth 10 <repo>
git submodule init
git submodule update --depth 10

如果出现错误 - 错误:服务器不允许请求未通告对象 SHA,请增加此特定模块的深度,例如 100。

git submodule update --depth 100 <submodule> # for those modules, whose depth doesnt match. try with different depths.

成功后,默认继续

git submodule update --depth 10

希望它对某人有帮助,欢迎进一步的解决方案。

关于git clone 浅子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47798888/

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