最近在弄hugo搭博客,涉及到了git的submodule操作,在这里做一个记录,如何正确的操作git的submodule
移除子模块
To remove a submodule you need to:
- Delete the relevant section from the .gitmodules file.
- Stage the .gitmodules changes git add .gitmodules
- Delete the relevant section from .git/config.
- Run git rm –cached path_to_submodule (no trailing slash).
- Run rm -rf .git/modules/path_to_submodule (no trailing slash).
- Commit git commit -m “Removed submodule "
- Delete the now untracked submodule files rm -rf path_to_submodule
I think above can be simplified using following commands:
git submodule deinit <path_to_submodule>
git rm <path_to_submodule>
git commit-m "Removed submodule "
rm -rf .git/modules/<path_to_submodule>
删除完后,就可以重新添加submodule了
克隆项目
- 克隆包含子模块代码:
git clone --recursive [URL to Git repo]
- 如果已经拉取了代码
git submodule update --init # if there are nested submodules: git submodule update --init --recursive
更新
git submodule update --remote --merge