Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

对于存在 submodule 的 git 仓库怎么 clone 最少的代码?对比 git clone --depth=1

单纯从 github 下载使用软件时,可以通过 depth 参数来下载最先的代码,但是对于有 submodule 的项目,执行 git submodule update --init --recursive --depth=1 ,因为 submodule 是 shallow clone, 所以无法 checkout 到目标 commit。

这种情况有什么办法解决?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我只找到一个fetch/clone各一次的,颇麻烦的方法:

  1. git submodule update --init --depth=1 这时clone到的commit一般都不是submodule注册的那个,所以会报错

  2. git ls-tree HEAD:(submodule的路径) 找到想要的那个commit,如

    `160000 commit abb03163aeafb8b7fc1efd2413d9f077bcdbeed9  tidy-html5` 的 `abb031`就是
  3. cd到submodule 的clone repo (如.git/modules/tidy-html5), fetch那个commit git fetch abb031

  4. git submodule update --no-fetch


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...