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

git submodule sync无作用?子模块未加载的原因及修复方法

问题原因

你手动修改了.gitmodules文件添加子模块配置,但没有将子模块的引用记录(gitlink)添加到Git仓库的索引并提交。Git识别子模块需要两个核心要素:

  • .gitmodules文件中的配置信息
  • 仓库中对应子模块路径的特殊gitlink文件(会被Git视为一个文件,需通过git add加入索引)

仅修改.gitmodules的话,Git不会自动创建或识别这个子模块,所以git submodule status会显示子模块数量为0。

修复步骤
  1. 确保当前处于仓库根目录,执行命令将子模块路径加入Git索引:
git add parent/showcase
  1. 提交变更,让仓库记录子模块的引用:
git commit -m "Add parent/showcase submodule reference"
  1. 重新执行子模块同步与更新命令:
git submodule sync
git submodule update --init --remote --recursive
  1. 再次查看子模块状态:
git submodule status

此时应该能正常显示parent/showcase子模块的信息。

如果执行git add parent/showcase时提示路径不存在,可直接用git submodule add命令重新关联(该命令会自动更新.gitmodules并添加gitlink):

git submodule add https://github.com/tribbloid/spookystuff-showcase parent/showcase

提交变更后即可完成修复。

内容的提问来源于stack exchange,提问作者tribbloid

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 03:50:03