不移动Git子模块仅重命名的方法求助
解决Git子模块重命名引用的问题
具体操作步骤
- 先确认当前工作区无未提交更改:
git status - 提交已修改的
.gitmodules文件:git add .gitmodules git commit -m "Rename submodule reference to my_submodule" - 更新Git对子模块的内部记录:
- 移除子模块在索引中的旧条目(不会删除实际文件):
git rm --cached path/to/submodule - 添加新的子模块引用(关联原路径,不移动文件):
这里的git submodule add --name my_submodule user@bitbucket.org:account/repo.git path/to/submodule--name参数就是设置你需要的短引用名my_submodule,后面的路径保持原位置不变。
- 移除子模块在索引中的旧条目(不会删除实际文件):
- 同步配置并验证:
git submodule sync git submodule update --remote my_submodule
报错原因说明
你直接修改.gitmodules和.git/config后,Git索引里仍记录旧的子模块路径path/to/submodule,同时.git/modules目录下的子模块文件夹还是旧名称,导致Git无法识别my_submodule这个新引用。上述步骤会同步所有内部记录,让Git认可新的引用名。
内容的提问来源于stack exchange,提问作者Sarah
相关产品推荐
相关产品推荐

