【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

 

参考资料

1. git submodule

2. git submodule的使用

3. 使用 Git Submodule 管理项目

4. Git submodule 知识总结

posted @   苏格拉底的落泪  阅读(57)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
历史上的今天:
2019-05-11 【C++编程】std::move
点击右上角即可分享
微信分享提示