将 Git 子模块设置为浅克隆和稀疏结帐?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6238590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:32:59  来源:igfitidea点击:

Set Git submodule to shallow clone & sparse checkout?

gitgithubclonegit-submodulessparse-checkout

提问by ma11hew28

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.

许多供应商的Objective-C 库(例如,facebook-ios-sdk)指示您将其repo 文件/目录的某个子集复制到您的Xcode 项目中。这样做的一个问题是您不知道您拥有的供应商代码的修订版。另一个原因是,如果您对供应商代码进行更改,则通过 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 .gitmodulesfile). 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:

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

  1. Sparse checkout: Only check out certain files of the submodule.
  2. Shallow clone: Only clone a certain SHA1 of the submodule.
  1. 稀疏检出:只检出子模块的某些文件。
  2. 浅克隆:只克隆子模块的某个 SHA1。

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

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

回答by gwohpq9

You can do sparse checkouts of submodules the same way as normal sparse checkout. Just remember the sparse-checkoutfile for each module goes in .git/modules/<mymodule>/info/. But, as discussed in git 1.7 sparse checkout feature, sparse checkouts are exactly that: checkouts. You can't move files or share the settings.

您可以像普通稀疏检出一样对子模块进行稀疏检出。只要记住sparse-checkout每个模块的文件进入.git/modules/<mymodule>/info/。但是,正如git 1.7 稀疏结帐功能中所讨论的那样,稀疏结帐就是这样:结帐。您无法移动文件或共享设置。

回答by VonC

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:

使用git1.8.4(2013 年 7 月)除了子模块( git submodule update --depth 1) 的git 浅更新之外,您现在可以进行自定义更新

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.

除了从“rebase、merge 或 checkout-detach”中选择之外,“submodule update”还可以允许使用自定义命令通过“ submodule.*.update”配置变量更新子模块的工作树。

See commit 6cb5728c43f34a7348e128b44b80d00b9417cb19:

提交 6cb5728c43f34a7348e128b44b80d00b9417cb19

Users can set submodule.$name.updateto '!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 <[email protected]>

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

签字人:克里斯·帕克汉姆 <[email protected]>

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

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



Update August 2016 (3 years later)

2016 年 8 月更新(3 年后)

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

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

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

See "Git submodule without extra weight" for more.

有关更多信息,请参阅“没有额外重量的 Git 子模块”。

回答by Tekkub

Submodules can't do partof a repo. You should check out subtree mergeinstead.

子模块不能作为 repo 的一部分。您应该检查子树合并