本地Git子模块添加报错求助:如何将bar仓库作为foo的子模块?
解决Git子模块添加时"transport 'file' not allowed"错误
原因
这个错误是因为Git的全局或本地配置中,protocol.file.allow被设置为false或none,禁止了通过file协议访问本地仓库。
解决方法
- 临时允许当前仓库使用file协议:在foo仓库目录下执行
git config protocol.file.allow always - 全局允许file协议(所有仓库生效):执行
git config --global protocol.file.allow always - 限制允许的路径(更安全):如果不想完全放开,可指定仅允许特定路径的file访问,比如只允许
/tmp下的仓库:
全局设置则添加git config protocol.file.allow /tmp/--global参数:git config --global protocol.file.allow /tmp/
验证与重试
执行以下命令查看当前配置是否生效:
git config --get protocol.file.allow
之后重新执行子模块添加命令即可:
git submodule add --branch main /tmp/bar the_bar
内容的提问来源于stack exchange,提问作者Andrei Cherniaev
相关产品推荐
相关产品推荐

