【记录】Git|如何优雅的删除子模块(submodule)或修改Submodule URL
[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>
相关推荐
git中submodule子模块的添加、使用和删除的示例代码
主要介绍了git中submodule子模块的添加、使用和删除的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Git Submodule管理项目子模块的使用
主要介绍了Git Submodule管理项目子模块的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Git Submodule使用完整教程(小结)
主要介绍了Git Submodule使用完整教程(小结),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Git submodule 子模块的管理和使用介绍
场景: 当你在一个Git 项目上工作时,你需要在其中使用另外一个Git 项目。也许它是一个第三方开发的Git 库, 比如公司内部自己开发的公用代码库, 并在多个父项目中使用的。这个场景下,常见的问题产生了:你想将两个项目单独处理, 但是又需要在其中一个中, 使用另外一个。 在Git 中, 可以用子模块submodule来管理这些项目,submodule允许将一个Git 仓库当作另外一个Git 仓库的子目录。这允许克隆另外一个仓库到你的项目中, 并且保持你的提交相对独立。
详解git submodule使用以及注意事项
主要介绍了详解git submodule使用以及注意事项,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧


