git submodule update
已支持此answer中描述的
--depth
选项。
但我们仍然无法轻易确定深度值,这可能会使 git 无法找到子模块的预期修订版。
是否有浅更新子模块的真正解决方案?
所以我认为确切的深度仍然是一个神话,这是唯一必须解决的问题
虽然确实没有“确切深度”,但你仍然可以用 git 2.9.x+ (Q3 2016) 记录一个“深度推荐”。
参见 commit abed000、commit 37f52e9(2016 年 5 月 26 日),作者 Stefan Beller (
stefanbeller
)。gitster
-- 在 commit 3807098,2016 年 6 月 20 日)
:学习submodule update
选项--[no-]recommend-shallow
上游项目可以建议浅克隆它发布的
文件中的一些子模块。.gitmodules
有时上游项目认为子模块的历史并不重要。
为了让下游用户更容易,在中允许一个布尔字段'submodule.<name>.shallow
',它可以用来推荐上游是否认为历史重要。.gitmodules
默认情况下,该字段在初始克隆中受到尊重,可以通过提供
选项来忽略它。--no-recommend-shallow
这样,一个简单的
git submodule update
(没有附加参数)将使用推荐的深度值,如果找到的话。
另见“Git submodule without extra weight”:
git config -f .gitmodules submodule.<name>.shallow true
g19fanatic 在评论中提出:
quick 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'
命令是从子模块执行的,因此不会像这里描述的那样工作(例如尝试foreach
)。git submodule foreach 'echo $PWD'
但是
工作得很好。xargs
工作配方:
git submodule | awk '{print $2}' | \ xargs -n 1 -I %% bash -c 'git config -f .gitmodules submodule.%%.shallow true' git submodule update --depth=1