美文网首页
【转载】[Git] 如何优雅的删除子模块(submodule)或

【转载】[Git] 如何优雅的删除子模块(submodule)或

作者: 1琥珀川1 | 来源:发表于2020-03-23 14:22 被阅读0次

    转载地址:https://www.jianshu.com/p/ed0cb6c75e25

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

    Done! Nice & clean!

    1. 修改某模块URL
      修改'.gitmodules'文件中对应模块的”url“属性;
      使用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.

    以上。

    作者:thinker_g
    链接:https://www.jianshu.com/p/ed0cb6c75e25
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

    相关文章

      网友评论

          本文标题:【转载】[Git] 如何优雅的删除子模块(submodule)或

          本文链接:https://www.haomeiwen.com/subject/pwrwyhtx.html