温欣爸比

  • 主页
  • Alfred Workflow
  • 《Vim 练级手册》
  • 常用命令
  • 代码笔记
  • 合辑
  • 在线工具
所有文章 友链 关于我

温欣爸比

  • 主页
  • Alfred Workflow
  • 《Vim 练级手册》
  • 常用命令
  • 代码笔记
  • 合辑
  • 在线工具

Git 工具 submodule

2017-09-19

Git submodule 是一个很好的多项目使用共同类库的工具,他允许类库项目做为repository,子项目做为一个单独的 Git 项目存在父项目中,子项目可以有自己的独立的commit,push,pull。而父项目以Submodule的形式包含子项目,父项目可以指定子项目header,父项目中会的提交信息包含Submodule的信息,再clone父项目的时候可以把Submodule初始化。

添加

1
$ git submodule add https://github.com/chaconinc/DbConnector

通过 git status 查看状态

1
2
3
4
5
6
7
8
9
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: .gitmodules
new file: DbConnector

此时项目中增加一个 .gitmodules 文件

1
2
3
4
$ cat .gitmodules
[submodule "DbConnector"]
path = DbConnector
url = https://github.com/chaconinc/DbConnector

增加一个模块,该文件就会增加一条记录。
该文件也会受到版本控制,这样项目就知道从哪里获取子模块

克隆含有子模块的项目

接下来我们将会克隆一个含有子模块的项目。 当你在克隆这样的项目时,默认会包含该子模块目录,但其中还没有任何文件:

1
$ git clone https://github.com/chaconinc/MainProject

现在 DbConnector 目录是空的,只有执行如下两个命令才可以

1
2
$ git submodule init
$ git submodule update

或者

1
$ git submodule update --init --recursive

不过还有更简单一点的方式。 如果给 git clone 命令传递 --recursive 选项,它就会自动初始化并更新仓库中的每一个子模块。

1
$ git clone --recursive https://github.com/chaconinc/MainProject

删除子模块

想要删除子模块需要进行两部操作

1
2
$ rm -rf DbConnector/
$ git rm DbConnector/

此时想要重新添加该子模块可能会报 ‘DbConnector’ already exists in the index 的错误,此时我们需要加上 --force 参数

1
$ git submodule add --force https://github.com/chaconinc/DbConnector

参考文献

  • Git 工具 - 子模块
最近更新
Alfred Workflow 命令行帮助工具
最近热读
Go 判断数组中是否包含某个 item
Vim 高级功能 vimgrep 全局搜索文件
办理北京工作居住证的一些细节
Go 语法错误:Non-declaration statement outside function body
Mac 电脑查看字体文件位置
扫码关注公众号,或搜索公众号“温欣爸比” 及时获取我的最新文章
赏

谢谢你请我喝咖啡

支付宝
微信
  • git
Vim 插件 pathogen 插件管理
Mysql 配置文件 my.cnf
  1. 1. 克隆含有子模块的项目
  2. 2. 删除子模块
  3. 3. 参考文献
© 2017 - 2022 温欣爸比 京ICP备15062634号 总访问量次 访客数人次 本文总阅读量次 216.73.216.209
Hexo Theme Yilia by Litten
  • 所有文章
  • 友链
  • 关于我

tag:

  • python
  • flask
  • javascript
  • docker
  • 工具
  • openresty
  • 微信
  • java
  • hexo
  • 杂谈
  • vim
  • git
  • mysql
  • http
  • linux
  • mac
  • tmux
  • ssh
  • 算法
  • 开发
  • node
  • 杂文
  • jinja2
  • maven
  • spring
  • 北京
  • 生活
  • springboot
  • react
  • shell
  • graphql
  • iterm
  • expect
  • nginx
  • sqlalchemy
  • html
  • electron
  • vagrant
  • elastic
  • 宝贝
  • ansible
  • css
  • jquery
  • go
  • markdown
  • awk
  • redis
  • leetcode
  • zsh
  • 漫威
  • ssr
  • android
  • ffmpeg
  • chrome
  • vmware
  • youtube
  • windows
  • jupyter
  • excel
  • jq
  • Mac
  • Homebrew
  • mongo
  • py2
  • HomeBrew
  • movie
  • nodejs

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • Guru99
每天看书
每天背单词
每天一篇
写写代码
听听周杰伦
爱爱老婆