Git submodule.$name.url 覆盖不起作用

标签 git

我有一个包含一些子模块的 git 存储库。对于其中一些子模块,我想在我的本地机器上使用不同的远程 URL。根据to the Git Documentation我可以通过覆盖 .git/config 中的 submodule.$name.url 属性来做到这一点。

不幸的是,这个设置似乎根本没有被使用。

重现步骤

git clone http://example.com/parentrepo

.gitmodules 内容现在是:

[submodule "mysubmodule"]
 path = mysubmodule
 url = https://example.com/mysubmodule

git config submodule.mysubmodule.url http://doesnotexist.com

.git/config 内容现在是:

[submodule "mysubmodule"]
    url = http://doesnotexist.com
    active = true

之后 git submodule update --remote 成功,而如果它使用覆盖值应该会失败,因为 URL 不存在。

我正在运行 git 版本 2.22.0。

那么为什么不考虑覆盖的 url?

最佳答案

看来@alexei 上面描述的行为是正确的,并且符合 Git 文档; gitsubmodules guide提到.git/modules/<name>/config优先级高于 .git/config .

在这种情况下,remote.origin.url.git/modules/<name>/config优先于 submodule.<name>.url.git/config .

然而,阿列克谢写道:

Upon init the URL gets saved in .git/modules/<name>/config.

事实并非如此;它在初始 git submodule update 上, 或 git submodule update --init , 或 git clone --recursive URL 保存在 .git/modules/<name>/config 中(如果子模块克隆成功)。

此外,事后更改 URL 的更简单方法是运行 git config。在子模块中(不需要像 alexei 写的那样 deinit 和删除子模块 repo):

cd path/to/submodule
git config remote.origin.url http://doesnotexist.com
# or
git -C path/to/submodule config remote.origin.url http://doesnotexist.com

另外,请注意 git submodule sync将更新两者 .git/config.git/modules/<name>/config使用 .gitmodules 中记录的值.

关于Git submodule.$name.url 覆盖不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57376342/

相关文章:

Git Fetch 与 Git Fetch Origin

git - git 标签适用于所有分支吗?

git - 如何在 cocoa 中下载 github 项目的所有子模块?

git - 从失败的 rebase 中恢复

git - 为什么 'git submodule update' 会跳过子模块?

git - 在一台计算机上的一个 Git 中切换用户身份

git - 当它说一个 git step 是 "1 ahead"是什么意思

git - 使用 GitHub Pages 时了解 Jekyll 和 gh-pages 分支

git - 这个断开连接的箭头在 gitk 上意味着什么?

git - 如何撤销在 Git 提交消息中添加的换行符?