11.24 GIT与GFW https://scz.617.cn/unix/202211231303.txt Q: 有时可能需要 git clone --recursive git@... 但.gitmodules中是这样的 [submodule "subm1"] path = subm1 url = https://... [submodule "subm2"] path = subm2 url = https://... 于是递归中出现 git clone https://... 众所周知,寡妇王对https并不友好,挂线路自然是可以的,但我想问的是,假设可 以手工修改拖回本地的.gitmodules,有无正经办法让递归时不用https。现在只能 clone完主模块后,手工clone每个子模块,将https换成git;倒也可行,只是太low。 A: 2022-11-23 网友「李同学virusdefender」(3560808645)指出,可以用insteadOf配置。实测如下 用法满足原始需求 cd /tmp git config --global url.git@github.com:.insteadOf https://github.com/ git config -l git clone --recursive https://github.com/libbpf/libbpf-bootstrap.git libbpf-bootstrap git config --global --unset url.git@github.com:.insteadOf git config -l "git config -l"无必要,只是为了观察配置。"--unset"无必要,只是出于洁癖,我 不喜欢改.gitconfig文件。配置生效期间,所有"https://"被自动替换成"git@..."。 A: zz@nsfocus 2022-11-24 insteadOf算是最优解,但最初我想问的是,假设可以手工修改拖回本地的 .gitmodules,有无正经办法让递归时不用https,zz回答了这个问题。 cd /tmp git clone git@github.com:libbpf/libbpf-bootstrap.git libbpf-bootstrap cd libbpf-bootstrap 修改".gitmodules" -------------------------------------------------------------------------- [submodule "libbpf"] path = libbpf url = git@github.com:libbpf/libbpf.git [submodule "bpftool"] path = bpftool url = git@github.com:libbpf/bpftool.git [submodule "blazesym"] path = blazesym url = git@github.com:libbpf/blazesym.git -------------------------------------------------------------------------- git submodule update --init --recursive bpftool子模块下还有另一个libbpf子模块,若上述命令未能完成所有递归,就继续 修改"bpftool/.gitmodules" -------------------------------------------------------------------------- [submodule "libbpf"] path = libbpf url = git@github.com:libbpf/libbpf.git -------------------------------------------------------------------------- cd bpftool git submodule update --init --recursive 其实最初我想问的是这个答案,我不知道上述"git submodule"用法。