本文介绍了相当于url.insteadof的Git子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个Git存储库,它们都引用了一个或多个子模块,并且都是公司局域网/内部https URL(因此只能从公司局域网访问).

I have a couple Git repositories that all have one or more submodule referenced and both are corporate lan / internal https URLs (and thereby only accessible from the corp lan).

但是,可以从外部/公共网络通过ssh访问存储库,并且我可以减轻通过全局.gitconfig url.insteadOf重定向来回切换主要存储库URL的麻烦,但是,代替Of规则似乎并不应用于子模块(也为https网址).

From the outside / public network, ssh access to the repositories IS however possible and I can mitigate switching the main repositories' URLs back and forth via a global .gitconfig url.insteadOf redirection, but that insteadOf rule doesn't seem to apply to the submodules (which also are https urls).

除了适应每个存储库的.git/config文件之外,还有其他方法吗……也就是说,我也可以在全局.gitconfig中设置某些内容?

Is there any other way than to adapt each repository's .git/config file ... i.e something I can set in the global .gitconfig as well?

推荐答案

如果您对更改全局配置不满意,则可能需要分别配置每个子模块,因为每个子模块都是其自己的存储库.

If you're not happy with changing your global configuration, then you probably need to configure each submodule separately, since each submodule is its own repository.

幸运的是git提供了 giteach的foreach 命令,其中

Fortunately git supplies git submodule foreach command, which

重要的是,它确实发生在每个检出的子模块中.意味着在运行 git子模块更新之前,某些子模块将被忽略.

What's important is that it really happens in each checked out submodule. Meaning that before you run git submodule update some submodules will get ignored.

所以

$ git config --local url."[email protected]:".insteadOf "https://github.com/"
$ git submodule foreach --recursive \
    'git config --local url."[email protected]:".insteadOf "https://github.com/"'

应该为主要存储库,其子模块及其子模块的子模块解决问题.

should do the trick for the main repository, its submodules and submodules of their submodules.

这篇关于相当于url.insteadof的Git子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:29