git 子模块添加仅选择最新的提交

标签 git git-submodules

我有一个项目依赖于其他项目,所以我使用 git 子模块。
但我的项目只对最新的提交感兴趣,我不希望所有的提交都回到开头。

例如openssl zip是 6.6MB,但克隆仓库是 71.76MB。
我只想要 6.6MB,但可以利用 git 子模块。

还有出路吗?

最佳答案

是的,你可以做到。

有一个--深度标志可以传递给子模块。
--深度标志的使用方式与克隆存储库时使用它的方式相同,并且您希望仅克隆最新的提交。

Add the --depth option to the add and update commands of git submodule, which is then passed on to the clone command.
This is useful when the submodule(s) are huge and you're not really interested in anything but the latest commit.

git submodule add --depth 1 -- <url>
git submodule update --depth -- <url>

可以找到完整文档 here .

关于git 子模块添加仅选择最新的提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34283199/

相关文章:

Git:在所有子模块上递归切换分支( checkout )

git - 虚拟环境文件夹似乎由 git 跟踪

git - 如何恢复几周前丢失的 git 提交?

git - git rebase/squash-为什么我需要再次解决冲突?

git - 如何在 Git 中设置默认推送存储库?

每个分支的 git 子模块更新

git - 使用 Git 和 Nuget 管理内部共享库

git - 将 git 的 submodule.recurse 配置选项设置为 true 有什么缺点?

git - 何时将大型 Git 存储库拆分为较小的存储库?

Git blame 没有显示历史记录