fatal: No url found for submodule path ‘xxx/xxx’ in .gitmodules
错误现场还原:
- windows上add submodule
- mac上clone主体项目
- git submodule init时发生错误
- 查看.gitmodules内容如下
[submodule ".\\xxx\\xxx"] path = .\\xxx\\xxx url = http://xxx.xxx.xxx.git
错误分析:
- url错误,仔细查验后确定无误
- path错误,window|mac路径反斜杠问题,修改为/后验证仍然报错
- submodule name问题,修正为不带路径名xxx后仍旧报错
重新复盘,综合思考:
fatal: No url found for submodule path ‘xxx/xxx
’ in .gitmodules
报错中,/而不是\,没有./
回忆下执行git submodule add时有写./xxx/xxx,尝试修改.gitmodules
[submodule "xxx/xxx"]
path = xxx/xxx
url = http://xxx.xxx.xxx.git
重新执行命令:
git submodule init
# Submodule 'xxx/xxx' (http://xxxx/xxx/xxx.git) registered for path 'xxx/xxx'
git submodule sync
# Synchronizing submodule url for 'xxx/xxx'
git submodule update
#Cloning into '/Users/xxx/xxx/xxx'...
#Submodule path 'xxx/xxx': checked out '39cabde3d5c8aeba5623424asd7f5948e7f515f9f28db'
ok,解决
推测既然有path属性submodule name不包含路径也是可以的,尝试改为:
[submodule "xxx"]
path = xxx/xxx
url = http://xxx.xxx.xxx.git
结果可以正常init,sync
总结,
1.git submodule add [path] 路径中不要写./
2.windows上添加子模块后最好改把.gitmodule的路径反斜杠改下