【记录】Git|如何优雅的删除子模块(submodule)或修改Submodule URL

shandianchengzi
全栈领域新星创作者
博客专家认证
2023-05-07 10:09:29

[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>

 

...全文
924 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

4

社区成员

发帖
与我相关
我的任务
社区描述
在这里,记录我认为写得有最帮助的推文~~~ 同类型的推文只选我看过的最棒的!欢迎大家用自己更棒的推文替换它!
物联网系统安全python 个人社区 湖北省·武汉市
社区管理员
  • shandianchengzi
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧