将 .git/config 中子模块的 https 地址更改为 ssh 地址



我需要使用 ssh 转发代理在远程服务器上启用 git 克隆。存储库具有最初添加的子模块及其https地址。为了使转发代理正常工作,我认为我需要将这些地址更改为相应的ssh地址。

.git/config更改这些地址可以解决我的问题吗?

使用git config --global url.<base>.insteadOf即时替换 URL。类似的东西

git config --global url.<new-url-with-https>.insteadOf git@<server>:<user>/<repo>.git

查看 https://stackoverflow.com/search?q=%5Bgit-submodules%5D+insteadof 中的更多示例

模块的 URL 存储在沙盒根目录下的.gitmodules中。此文件作为 Git 存储库的一部分进行跟踪。如果在此处进行更改并提交,则 Git 存储库的其他用户可以看到该更改。

当您调用git submodule sync然后调用git submodule init时,URL 将被解析并复制到.git/config。当你调用git submodule update时,子模块被克隆,它的 URL 也可以在.git/modules/<module-name>/config中找到。

要永久更改网址,请编辑.gitmodules并再次拨打git submodule syncgit submodule init

要临时更改网址,请改为进行以下两项更改:

更改子模块.git/config中的 URL

进入子模块并调用:

git remote set-url origin <new-url-with-https>

第二个命令将更新.git/modules/<module-name>/config中的 URL,即子模块的.git文件夹。

编辑:如果模块和子模块都位于同一台服务器上,则对子模块使用相对URL将一劳永逸地解决问题:每个沙箱将使用克隆主存储库的相同协议获取子模块。另请参阅:https://stackoverflow.com/a/68120599/3216427

最近,github 弃用了git://协议,我想更新存储库中的子模块以使用https://而不是git://

我做了以下工作:

$ vim .gitmodules # Change all the git:// URLs into https:// URLs
$ git submodule init
$ git add .gitmodules
$ git commit -m "Update submodules"
$ git push origin main

您可以执行相同的操作将 URL 转换为ssh://

相关内容

最新更新