关于 Git 子模块
git submodule add 可以添加一个子模块,如
$ cd tools
$ git submodule add git@gitlab.acingame.com:xuedao-h5/xdh5_protofile.git
即在 tools/ 目录下添加了一个子模块 xdh5_protofile。但是如果我想修改这个子模块在本地的名字呢?
$ git submodule add git@gitlab.acingame.com:xuedao-h5/xdh5_protofile.git tools/protos
tools/protos 为子模块 xdh5_protofile 的本地路径。
删除子模块的步骤稍显复杂:
-
Delete the relevant section from the
.gitmodulesfile.[submodule "protos"] path = tools/protos url = git@gitlab.acingame.com:xuedao-h5/xdh5_protofile.git -
Stage the
.gitmoduleschanges.$ git add .gitmodules -
Delete the relevant section from
.git/config.[submodule "protos"] url = git@gitlab.acingame.com:xuedao-h5/xdh5_protofile.git active = true -
Run
git rm --cached path_to_submodule(no trailing slash).$ git rm --cached tools/protos -
Run
rm -rf .git/modules/path_to_submodule(no trailing slash).$ rm -rf .git/modules/tools/protos -
Commit.
$ git commit -m "Removed submodule" -
Delete the now untracked submodule files.
$ rm -rf tools/protos