移动子模块
Version > 1.8
跑:
$ git mv old/path/to/module new/path/to/module
Version <= 1.8
-
编辑
.gitmodules并适当更改子模块的路径,并使用git add .gitmodules将其放入索引中。 -
如果需要,创建子模块( ) 的新位置的父目录。
mkdir -p new/path/to -
将所有内容从旧目录移动到新目录( )。
mv -vi old/path/to/module new/path/to/submodule -
确保 Git 跟踪此目录( )。
git add new/path /to -
删除旧目录。
git rm --cached old/path/to/module -
将包含其所有内容的目录移动到。
.git/modules/ old/path/to/module.git/modules/ new/path/to/module -
编辑文件,确保 worktree 项指向新位置,因此在此示例中应该是。通常,在该位置的直接路径中应该还有两个
..然后目录。。编辑文件,确保其中的路径指向主项目.git文件夹中的正确新位置,因此在此示例中。.git/modules/ new/path/to /configworktree = ../../../../../ old/path/to/modulenew/path/to/module /.gitgitdir: ../../../.git/modules/ new/path/to/module之后
git status输出如下:# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: .gitmodules # renamed: old/path/to/submodule -> new/path/to/submodule # -
最后,提交更改。