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

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

问题描述



超级git存储库是用命令构建的

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

当一个不同的用户(其他用户)克隆超级仓库时,一切似乎都会奏效。但是,当是时候访问子模块的时候了

  git子模块init 
git子模块更新

git尝试使用myusername而不是otheruser克隆子模块。

如何解决这个问题?

解决方案

如果可能的话,最好确保 .gitmodules 文件包含可由任何人克隆的存储库URL,通常为 git:// http:// URL。然后,拥有SSH访问权限的用户可以在克隆后更改为子模块,并将 remote.origin.url 中的URL更改为使用其用户名指向SSH URL,例如:

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

即使在当前情况下,其他用户也应该可以这样做。 更新: Chris Johnsen指出,如果您省略用户名和所有用户,则在 .gitmodules 中使用SSH URL也是合理的。存储库将具有SSH访问权限 - 如果它们在本地和远程存在差异,它们需要与上述类似地添加他们的用户名。



请注意, .gitmodules 仅在初始化子模块时使用。初始化子模块会将主项目中的配置值子模块< SUBMODULE-NAME> .url 设置为 .gitmodules - 这是将在第一个子模块更新中使用的值。在初始化和更新子模块之间,您还可以使用以下命令更改此第一次更新的URL:

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

确实,您可能需要如果首次更新失败,请执行此操作。第一次更新子模块后,需要更改的URL是在子模块中为 origin 定义的URL - 此时它仅用于设置 submodule.my-submodule.url 在主项目中配置值,如果您可能要删除并重新更新子模块。


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

The super git repository was constructed with the commands

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

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 tries to clone the submodule using "myusername" instead of "otheruser".

How to solve this problem?

解决方案

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

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.

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

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天全站免登陆