在不同的机器上使用不同的git子模块URL [英] Use different git submodule URL's on different machines

查看:100
本文介绍了在不同的机器上使用不同的git子模块URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一台机器上是否可以使用一个子模块URL,而在另一台机器上可以使用不同的子模块URL?

Is there any way to use one submodule URL when on one machine, but use a different submodule URL when on the other?

让我们假设我有一台机器已对中央服务器上的git存储库进行SSH访问的身份验证,而另一台计算机无权访问该服务器.在经过身份验证的计算机上,我已经使用git-daemon将存储库共享到未经身份验证的计算机上.

Let's assume I have one machine which has authenticated SSH access to a git repository on a central server and another machine which does not have access to that server. On the authenticated machine I have used git-daemon to share the repositories to my non-authenticated machine.

这里的问题是,我克隆的存储库具有几个子模块依赖项,所有这些依赖项都是服务器上需要经过身份验证的SSH访问的存储库.在这种情况下,我还将所有子模块存储在经过身份验证的机器上,因此我可以从以下位置简单地更新.gitmodules文件:

The problem here is that the repository I've cloned has several submodule dependencies, all of which are repositories on the server that requires authenticated SSH access. In this case, I also have all of the submodules stored on my authenticated machine, so I can simply update the .gitmodules file from:

[submodule "@sub-a"]
    url = ssh://<authenticated-url>/<repo>
    branch = master

到...

[submodule "@sub-a"]
    url = git://<ip-of-authenticated-machine>/<repo>
    branch = master

然后运行git submodule syncgit submodule update --init -r将直接从经过身份验证的计算机而不是从服务器获取子模块.

Then running git submodule sync and git submodule update --init -r will fetch the submodules directly from my authenticated machine instead of from the server.

然后我的问题是,是否有任何便携式方法来执行此操作,以便我可以在机器之间自由移动并期望正确的git-submodule行为?

My question then is this, is there any portable way to do this so that I can freely move between the machines and expect correct git-submodule behavior?

推荐答案

您可以在.git/config中更改子模块属性.根据您的情况,您可以从[submodule "<name>"]部分更改url.请记住,这些属性将无法生存git submodule deinitgit submodule sync
详细

You can change submodule properties in .git/config. In your case you can change url from [submodule "<name>"] section. Keep in mind that those properties won't survive git submodule deinit, git submodule sync
Detailed

git submodule deinit     # deinitialize submodule, relevant section in .git/config will be removed
rm -fdr .git/modules/    # clear submodules' local repos
git submodule init       # relevant section will be copied (partially) from .gitmodules to .git/config
...                      #Edit .git/config with new url for submodule
git submodule update     # submodule will be updated from new url.

这篇关于在不同的机器上使用不同的git子模块URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆