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

不移动Git子模块仅重命名的方法求助

解决Git子模块重命名引用的问题

具体操作步骤

  • 先确认当前工作区无未提交更改:
    git status
    
  • 提交已修改的.gitmodules文件:
    git add .gitmodules
    git commit -m "Rename submodule reference to my_submodule"
    
  • 更新Git对子模块的内部记录:
    1. 移除子模块在索引中的旧条目(不会删除实际文件):
      git rm --cached path/to/submodule
      
    2. 添加新的子模块引用(关联原路径,不移动文件):
      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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 05:57:22