git下submodule用法

基础用法

  • clone模块

使用之前建议将其他仓库先clone至自己的帐号下,方便模块中有些配置文件需要另行填写,这样可以直接在自己仓库中进行修改和更新

git submodule add https://github.com/bytetoy/hexo-theme-matery.git themes/hexo-theme-matery
Cloning into '/home/hotpod/web/bytetoy/themes/hexo-theme-matery'...
remote: Enumerating objects: 5550, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 5550 (delta 9), reused 5 (delta 5), pack-reused 5535 (from 2)
Receiving objects: 100% (5550/5550), 20.17 MiB | 13.03 MiB/s, done.
Resolving deltas: 100% (3551/3551), done.
  • 更新模块

当仓库中文件修改后,可以直接将仓库更新至本地,在模块目录下themes/hexo-theme-matery操作

git pull

删除模块

当不需要此模块,或者需要更换为其他仓库时,需要先删除已经下载的模块。

  • 删除原此模块的目录
rm -rf hexo-theme-matery
  • 删除.gitmodules文件的内容,此文件在子模块的上级仓库中,如下:
[submodule "themes/hexo-theme-matery"]
        path = themes/hexo-theme-matery
        url = https://github.com/bytetoy/hexo-theme-matery.git
  • 删除.git/config文件配置中的对应子模块内容
[submodule "themes/hexo-theme-matery"]
        url = https://github.com/bytetoy/hexo-theme-matery.git
        active = true
  • 删除.git/modules下对应子模块目录
rm -rf .git/modules/themes/hexo-theme-matery
  • 删除git索引中的对应子模块
git rm --cached themes/hexo-theme-matery

results matching ""

    No results matching ""

    results matching ""

      No results matching ""