The git submodule cheat sheet

栏目: IT技术 · 发布时间: 4年前

内容简介:A git submodule, in its essence, is a reference to another git repository. It’s a great way to include vendor code (like plugins or themes) into your own code base. This post contains some examples on how to use git submodules effectively.You need to know

A git submodule, in its essence, is a reference to another git repository. It’s a great way to include vendor code (like plugins or themes) into your own code base. This post contains some examples on how to use git submodules effectively.

Add a submodule

You need to know the remote git repository url and where you want to place that it in your repository.

git submodule add https://example.com/submodule-repo.git path/to/submodule
git add . 
git commit -m "adds submodule path/to/submodule"

Cloning a project with submodules

When you clone a repository that contains submodules there are a few extra steps to be taken.

git clone http://example.com/repo.git repo
cd repo
git submodule init
git submodule update

If you’re sure you want to fetch all submodules (and their submodules), you can also use this fancy one-liner:

git clone --recurse-submodules http://example.com/repo.git

Update your submodule

If you’re simply tracking the master branch for the submodule, you can suffice with a simple fetch and merge .

cd path/to/submodule
git fetch
git merge origin/master

If you’re in a hurry, you can streamline this for all submodules in your repo with:

git submodule update --remote --recursive

Don’t forget to commit this change to your own repo, so others are locked to this new version of the submodule as well.

Track a specific branch of version

The repo for your submodule may have a specific branch (e.g. stable ) or tag you want to track, instead of master .

git config -f .gitmodules submodule.path/to/submodule.branch stable
git submodule update --remote

Again, don’t forget to commit your changes to .gitmodules to send this change to other contributors to you repository.

Remove a submodule

Removing a git submodule consists of two steps: removing the reference and removing the locally cached version.

git submodule deinit path/to/submodule
git rm path/to/submodule
git commit -m "removes submodule path/to/submodule"

rm -rf .git/modules/path/to/submodule

Bonus: see submodule status in git status

You can configure git to show a submodule summary when you do a git status . There is a small performance trade-off here, but it might be useful to you.

git config status.submodulesummary 1

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

白话区块链

白话区块链

蒋勇 / 文延、嘉文 / 机械工业出版社 / 2017-10-1 / 59.00

由浅入深:从比特币开始,到区块链技术的骨骼(密码算法)和灵魂(共识算法),再到目前知名的区块链框架介绍,到最后从零构建一个微型区块链系统(微链),循序渐进。 多图多表:各种示例以及图表,通过流程图与示意图介绍比特币的源码编译、以太坊智能合约的开发部署、超级账本Fabric的配置使用、模拟比特币的微型区块链系统的设计实现等,形象而直观。 白话通俗:通过“村民账本记账”、“百花村选举记账”......一起来看看 《白话区块链》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码