【git命令】git submodule
正文
git submodule
创建子模块:
# Usage
$ git submodule add [url] [path]
# With path
$ git submodule add https://github.com/laozhu/hugo-nuo themes/hugo-nuo
$ git submodule -b branch_name add https://github.com/laozhu/hugo-nuo themes/hugo-nuo # 指定分支
# Without path
$ cd themes
$ git submodule add https://github.com/laozhu/hugo-nuo
$ git submodule -b branch_name add https://github.com/laozhu/hugo-nuo # 指定分支
在 my-blog 这个仓库下面多出了一个
.gitmodules
文件,该文件列出了所包含的子模块列表,并为列表中每一个子模块指定了本地路径(path)和远程仓库地址(url),除此以外我们还可选为子模块指定 branch
分支,不指定默认为 master
分支。$ cat .gitmodules
[submodule "themes/hugo-nuo"]
path = themes/hugo-nuo
url = https://github.com/laozhu/hugo-nuo
查看子模块:
$ git submodule
# 已检出子模块代码
cedbe91340dbcff661fa089b116441b11b050d38 themes/hugo-nuo (heads/master)
# 前面带 - 表示未检出代码,子模块是空文件夹
-cedbe91340dbcff661fa089b116441b11b050d38 themes/hugo-nuo (heads/master)
删除子模块:git中删除子模块略微麻烦一些,因为目前还没有 git submodule rm
这样的命令行,我们要做很多工作才能删得干净:
$ git submodule deinit themes/hugo-nuo # 子模块为themes/hugo-nuo
$ vim .gitmodules # 移除要删除的子模块
$ git add .gitmodules
$ git rm --cached themes/hugo-nuo
$ rm -rf .git/modules/themes/hugo-nuo
$ rm -rf themes/hugo-nuo
$ git commit -m "Remove submodule themes/hugo-nuo"
从远程仓库拉取子模块:
git submodule update --remote
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
2019-05-11 【C++编程】std::move