You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 05:12:01