将git子模块协议从git替换为http [英] replace git submodule protocol from git to http

查看:411
本文介绍了将git子模块协议从git替换为http的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从git @ ... URL中添加一个子模块,以便能够在其中开发。现在我想部署应用程序,并用git:// ... one替换URL,因此它不需要对来自Capistrano的子模块的repo进行身份验证。编辑 .gitmodules

编辑 .gitmodules

编辑 file(然后提交并推送它)对于任何新的克隆都是足够的。



另外,当子模块是初始化(例如 git submodule init ... git submodule update --init ... git克隆 - 递归... 等),它的URL从 .gitmodules 文件复制到存储库的 .git /配置文件。



因此,如果您有任何现有的部署克隆通过 git:// ... URLs访问子模块),你还必须更新它们的 .git / config 。您可以使用 git submodule sync 自动将子模块URL从当前的​​ .gitmodules 文件复制到您的 .git / config 文件(也就是说,一旦你已经提交了更新 .gitmodules 文件的提交)。



.git / config 中的子模块URL通常不会自动更新,因为在某些情况下您只想覆盖URL。具体来说,您经常希望在您的存储库的 .git / config 中使用 git @ ... URL(这样您可以推送通过SSH),但在 .gitmodules 中放置 git:// ... URL(以便公众不需要做基于SSH的认证)。

I add a submodule from a git@... URL, to be able to develop in it. Now I want to deploy the app and replace the URL with an git://... one, so it doesn't need authentication to the submodule's repo from Capistrano. Is editing the URL in .gitmodules totally enough to accomplish this?

解决方案

Editing the .gitmodules file (then committing, and pushing it) will be adequate for any new clones.

Additionally, when a submodule is initialized (e.g. git submodule init …, git submodule update --init …, or git clone --recursive …, etc.) its URL is copied from the .gitmodules file to the repository’s .git/config file.

So, if you have any existing "deployment clones" (the ones you now want to access the submodules through git://… URLs), you will also have to update the URL in their .git/config. You can use git submodule sync to automatically copy the submodule URLs from the current .gitmodules file to your .git/config file (i.e. once you have pulled the commit that updates the .gitmodules file).

The submodule URLs in .git/config are not normally automatically updated because there are cases where you only want to override the URL in certain situations. Specifically, you will often want to use git@… URLs in your repository’s .git/config (so you can push over SSH), but put git://… URLs in .gitmodules (so that the general public does not need to do SSH-based authentication).

这篇关于将git子模块协议从git替换为http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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