根据目标仓库选择git子模块

问题描述 投票:0回答:1

我有一个项目,我在.git/config文件中使用以下内容推送到2个不同的存储库:

    [remote "origin"]
        url = the_main_repo
        fetch = +refs/heads/*:refs/remotes/origin/*
    [remote "other_repo"]
        url = the_other_repo

该项目本身也有一个子模块。我的.gitmodules文件看起来像:

    [submodule "the_submodule"]
        path = the_submodule
        url = the_submodule_repo_url

我想the_submodule_repo_url是不同的,这取决于我从哪个repo拉出来,以便我从同一个源获取子模块repo(这些是我网络中的不同服务器)。

怎么做到这一点?

git git-submodules
1个回答
0
投票

Git认为子模块应该有一个URL,所以没有简单的方法可以做你想要的。 Git可以substitute URLs on the fly但在你的情况下它应该动态使用(在命令行中,而不是在配置中)。

将子模块的一个URL设置为与其中一个远程模块相同的主机。对于其他远程运行

git -c url.$the_other_submodule_repo.insteadOf the_submodule_repo_url fetch/push/pull other_repo

创建shell脚本,函数或git别名以简化调用它。

© www.soinside.com 2019 - 2024. All rights reserved.