Git 子模块和 ssh 访问 [英] Git submodules and ssh access

查看:15
本文介绍了Git 子模块和 ssh 访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用包含多个子模块的 git 存储库时遇到了一些问题.

I have some trouble with a git repository that contains several submodules.

超级git仓库是用命令构建的

The super git repository was constructed with the commands

mkdir projectname
cd projectname
git init
git submodule add ssh://myusername@server/pathtorepos

当另一个用户(otheruser")克隆超级存储库时,一切似乎都解决了.但是什么时候可以访问子模块

When a different user ("otheruser") then clones the super repository everything seems to work out. But when it is time to get access to the submodule

git submodule init
git submodule update

git 尝试使用myusername"而不是otheruser"来克隆子模块.

git tries to clone the submodule using "myusername" instead of "otheruser".

如何解决这个问题?

推荐答案

如果可能,最好确保 .gitmodules 文件包含任何人都可以克隆的存储库的 URL,通常是 git://http:// URL.然后自己有SSH访问权限的用户可以在克隆后切换到子模块中,将remote.origin.url中的URL改为指向一个带有用户名的SSH URL,例如:

If possible, it's best to make sure that the .gitmodules file contains a URL for the repository that can be cloned by anyone, typically either a git:// or http:// URL. Then users that have SSH access themselves can change into the submodule after cloning and change the URL in remote.origin.url to point to an SSH URL with their username, e.g.:

 cd my-submodule
 git remote set-url origin otheruser@server:/pathtorepos

即使在当前情况下,其他用户也应该能够做到这一点.更新: Chris Johnsen 在下面指出,在 .gitmodules 中使用 SSH URL 也是合理的,如果您省略用户名并且存储库的所有用户都将具有 SSH 访问权限 -如果本地和远程用户名不同,他们需要添加与上述类似的用户名.

The other user should be able to do that even in the current situation. Update: Chris Johnsen points out below that it's also reasonable to use an SSH URL in .gitmodules if you omit the username and all the users of the repository will have SSH access - they'll need to add their username similarly to the above if it differs locally and remotely.

请注意,.gitmodules 中的 URL 仅在初始化子模块时使用.初始化子模块会将主项目中的配置值 submodule..url 设置为 .gitmodules 中提交的任何内容 - 这是将使用的值在第一个子模块更新上.在初始化和更新子模块之间,您还可以使用如下命令更改将用于第一次更新的 URL:

Note that the URLs in .gitmodules are only used when initializing the submodule. Initializing the submodule sets the config value submodule.<SUBMODULE-NAME>.url in the main project to whatever's committed in .gitmodules - this is the value that will be used on the first submodule update. Between initializing and updating the submodule, you can also change this URL that will be used for that first update with a command like:

git config submodule.my-submodule.url otheruser@server:/pathtorepos

确实,如果第一次更新失败,您可能需要这样做.第一次更新子模块后,您需要更改的 URL 是在子模块中为 origin 定义的 URL - 此时仅设置 submodule.my-submodule 有用.url 主项目中的配置值,如果您可能要删除和重新更新子模块.

Indeed, you may need to do this if the first update fails. Once the submodule has been updated for the first time, the URL you need to change is that defined for origin within the submodule - at that point it's only useful to set the submodule.my-submodule.url config value in the main project if you're likely to be deleting and re-updating the submodule.

这篇关于Git 子模块和 ssh 访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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