4
社区成员




[Git] 如何优雅的删除子模块(submodule)或修改Submodule URL - 简书 (jianshu.com)
收录原因:太常用了,这篇写得非常简单且能用、就是这几个指令。
删除:
# 逆初始化模块,其中{MOD_NAME}为模块目录,执行后可发现模块目录被清空
git submodule deinit {MOD_NAME}
# 删除.gitmodules中记录的模块信息(--cached选项清除.git/modules中的缓存)
git rm --cached {MOD_NAME}
# 如果你通过 git rm 删不掉,就会报错如下:
#A git directory for 'xxxx' is found locally with remote(s):
# origin git@git.xxxxxxx.git
#If you want to reuse this local git directory instead of cloning again from
# git@git.xxxxxxx.git
#use the '--force' option. If the local git directory is not the correct repo
#or you are unsure what this means choose another name with the '--name' option.
# 此时你可以考虑去.git/modules文件夹下删掉对应的,这样就不会从本地缓存中拉取了。
# 提交更改到代码库,可观察到'.gitmodules'内容发生变更
git commit -am "Remove a submodule."
修改:
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." # 提交变更
添加:
git submodule add <url> <path>