将 Git 子模块设置为浅克隆 &稀疏结帐? [英] Set Git submodule to shallow clone & sparse checkout?

查看:37
本文介绍了将 Git 子模块设置为浅克隆 &稀疏结帐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多供应商 Objective-C 库(例如,facebook-ios-sdk)指示您将其存储库文件/目录的某个子集复制到您的 Xcode 项目中.这样做的一个问题是您不知道您拥有的供应商代码的修订版.另一个原因是,如果您对供应商代码进行更改,则通过 Git 贡献您的更改并不容易.

作为一种解决方案,我想将每个供应商库添加为我项目存储库的 Git 子模块,并带有一些额外设置(例如,在 .gitmodules 文件中).这样,如果另一个人克隆我的项目并执行 git submodule update --init,他们的 repo &子模块将具有与我相同的状态,因为它们将使用我设置的相同默认设置:

  1. 稀疏检出:仅检出子模块的某些文件.
  2. 浅克隆:只克隆子模块的某个 SHA1.

如何为 Git 子模块设置上述设置?

解决方案

With git1.8.4(2013 年 7 月),在 为子模块添加 git 浅更新(git submodule update --depth 1),您现在可以进行自定义更新:

<块引用>

除了可以选择rebase、merge或checkout-detach"之外,submodule update"还可以允许使用自定义命令通过submodule.*.更新"配置变量.

请参阅提交 6cb5728c43f34a7348e1801a704b1804b1b1b404<块引用>

用户可以将 submodule.$name.update 设置为 '!command' 这将导致运行 'command' 而不是 checkout/merge/rebase.
这允许用户更精细地控制更新的完成方式.

签字人:Chris Packham

这意味着您可以对command"进行版本控制,然后您可以将其用于任何子模块更新(通过 submodule.$name.update 设置).
如果您愿意,该脚本可以进行稀疏结帐.

<小时>

2016 年 8 月更新(3 年后)

使用 Git 2.10(2016 年第三季度),您将能够做到

 git config -f .gitmodules submodule..shallow bool

请参阅没有额外重量的 Git 子模块"了解更多信息.

Many vendor Objective-C libraries (e.g., facebook-ios-sdk) instruct you to copy a certain subset of its repo's files/dirs into your Xcode project. One problem with this is then you do not know what revision of the vendor code you have. Another is that if you make changes to the vendor code, it's not easy to contribute your changes via Git.

As a solution, I want to add each vendor library as a Git submodule of my project's repo with some extra settings (say, in the .gitmodules file). This way, if another person clones my project and does git submodule update --init, their repo & submodules will have the same state as mine because they'll be using the same default settings I set:

  1. Sparse checkout: Only check out certain files of the submodule.
  2. Shallow clone: Only clone a certain SHA1 of the submodule.

How do I set the above settings for a Git submodule?

解决方案

With git1.8.4 (July 2013), in addition git shallow update for submodule (git submodule update --depth 1), you now can have a custom update:

In addition to the choice from "rebase, merge, or checkout-detach", "submodule update" can allow a custom command to be used in to update the working tree of submodules via the "submodule.*.update" configuration variable.

See commit 6cb5728c43f34a7348e128b44b80d00b9417cb19:

Users can set submodule.$name.update to '!command' which will cause 'command' to be run instead of checkout/merge/rebase.
This allows the user finer-grained control over how the update is done.

Signed-off-by: Chris Packham <judge.packham@gmail.com>

That means you can version a 'command' that you can then use for any submodule update (through the submodule.$name.update setting).
That script can do a sparse checkout if you want.


Update August 2016 (3 years later)

With Git 2.10 (Q3 2016), you will be able to do

 git config -f .gitmodules submodule.<name>.shallow bool

See "Git submodule without extra weight" for more.

这篇关于将 Git 子模块设置为浅克隆 &amp;稀疏结帐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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