【问题标题】:Update git submodules shallowly with the '--depth' option使用“--depth”选项浅层更新 git 子模块
【发布时间】:2014-05-05 19:36:52
【问题描述】:

git submodule update 已支持 --depth 选项,如此 answer 中所述。

但是我们仍然不能轻易确定深度值,这可能会导致 git 无法找到子模块的预期修订版本。

有没有真正的浅层更新子模块的解决方案?

【问题讨论】:

  • 它不应该阻止 git 获取正确的深度。但如果是,那么与stackoverflow.com/questions/24294361/… 中的评论相同:(对于 git 1.9.x+)您是否尝试过 git fetch --update-shallow (可能通过自定义命令/更新:stackoverflow.com/a/17693008/6309)。跨度>
  • 我将首先测试git submodule update --depth:它应该能够更新到正确的深度,具体取决于记录的 SHA1。
  • 从 git 2.0.0 开始,--depth 后面必须跟一个值。所以我认为确切的深度仍然是一个神话,这是唯一且必须解决的问题。感谢@VonC的帮助

标签: git git-submodules


【解决方案1】:

所以我认为确切的深度仍然是一个神话,这是该问题唯一且必须解决的问题

虽然确实没有“确切深度”,但您仍然可以使用 git 2.9.x+(2016 年第三季度)记录“深度推荐”。

commit abed000commit 37f52e9(2016 年 5 月 26 日)Stefan Beller (stefanbeller)
(由 Junio C Hamano -- gitster -- 合并于 commit 3807098,2016 年 6 月 20 日)

submodule update:学习--[no-]recommend-shallow选项

上游项目可以推荐浅层克隆 它附带的.gitmodules 文件中的一些子模块。

有时子模块的历史不被认为是重要的 上游的项目。
为了方便下游用户,请在.gitmodules 中允许一个布尔字段“submodule.<name>.shallow”,可用于推荐上游是否认为历史重要。

初始克隆时默认使用该字段,可以 通过提供--no-recommend-shallow 选项忽略。

这样,一个简单的git submodule update(无附加参数)将使用推荐的深度值(如果找到)。

另见“Git submodule without extra weight”:

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

g19fanatic提议in the comments

快速 1-liner 将 shallow=true 添加到所有子模块:

git submodule | awk '{print $2}' | \
  xargs -n 1 -I %% bash -c 'git config -f .gitmodules submodule.%%.shallow true'

或者,git submodule foreach:

git submodule foreach 'git config -f .gitmodules submodule.$sm_path.shallow true'

【讨论】:

  • 快速 1-liner 为所有子模块添加 shallow=true git submodule | awk '{print $2}' | xargs -n 1 -I %% bash -c 'git config -f .gitmodules submodule.%%.shallow true'
  • @g19fanatic 谢谢。那确实应该派上用场。我已将您的评论包含在答案中以提高知名度。
  • @g19fanatic 但我相信使用git submodule foreach更安全,不需要依赖awk等解析技巧。
  • 可能是对的。从未真正使用过 foreach,但 awk/xargs 在我的实用工具带中。为了完整性git submodule foreach 'git config -f .gitmodules submodule.$sm_path.shallow true'
  • @g19fanatic 然而,正如他们所说:“This is the way”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-10
  • 2022-01-23
  • 2019-07-20
  • 2012-04-27
  • 2012-09-14
  • 1970-01-01
相关资源
最近更新 更多