git submodule 删除及修改

1.  删除子模块

# 逆初始化模块,其中{MOD_NAME}为模块目录,执行后可发现模块目录被清空
git submodule deinit {MOD_NAME} 
# 删除.gitmodules中记录的模块信息(--cached选项清除.git/modules中的缓存)
git rm --cached {MOD_NAME} 
# 提交更改到代码库,可观察到'.gitmodules'内容发生变更
git commit -am "Remove a submodule." 

此外,你可能还需要删除 .git/modules/{MOD_NAME}的缓存,否则无法创建同名的module.

 

 2. 修改模块URL

  1. 修改'.gitmodules'文件中对应模块的”url“属性;
  2. 使用 git submodule sync 命令,将新的URL更新到文件.git/config
thinker-g@localhost: ~/app$ git submodule sync 
Synchronizing submodule url for 'gitmods/thinker_g/Helpers'
thinker-g@localhost: ~/app$ # 运行后可观察到'.git/config'中对应模块的url属性被更新
thinker-g@localhost: ~/app$ git commit -am "Update submodule url." # 提交变更

PS: 本实验使用git 2.7.4 完成,较低版本git可能不能自动更新.git/config文件,需要修修改完".gitmodule"文件后手动修改.git/config.

以上。

 

 

 

posted @ 2019-07-29 20:34  QIYUEXIN  阅读(16063)  评论(1编辑  收藏  举报