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 的本地路径。

删除子模块的步骤稍显复杂:

  1. Delete the relevant section from the .gitmodules file.

     [submodule "protos"]
         path = tools/protos
         url = git@gitlab.acingame.com:xuedao-h5/xdh5_protofile.git
    
  2. Stage the .gitmodules changes.

     $ git add .gitmodules
    
  3. Delete the relevant section from .git/config.

     [submodule "protos"]
         url = git@gitlab.acingame.com:xuedao-h5/xdh5_protofile.git
         active = true
    
  4. Run git rm --cached path_to_submodule (no trailing slash).

     $ git rm --cached tools/protos
    
  5. Run rm -rf .git/modules/path_to_submodule (no trailing slash).

     $ rm -rf .git/modules/tools/protos
    
  6. Commit.

     $ git commit -m "Removed submodule"
    
  7. Delete the now untracked submodule files.

     $ rm -rf tools/protos