IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> Git Submodule Test -> 正文阅读

[开发工具]Git Submodule Test

Git Submodule Test

Assume three repositories: repoa, repob, repoc

  • supermodule: repoa
  • submodule: repob, repoc

1. Add submodules

Add a repository as the current repository’s submodule.

e.g., change directory to repoa:

$ git submodule add ssh://cy@192.168.5.45/home/cy/repob
$ git submodule add ssh://cy@192.168.5.45/home/cy/repoc

.gitmodules is as the following:

$ cat .gitmodules
[submodule "repob"]
        path = repob
        url = ssh://cy@192.168.5.45/home/cy/repob
[submodule "repoc"]
        path = repoc
        url = ssh://cy@192.168.5.45/home/cy/repoc

2. Clone a repository with submodules

e.g., Clone a repository with its submodules:

$ git clone --recurse-submodules ssh://cy@192.168.5.45/home/cy/repoa

The above is a simple way. We can also clone supermodule and its submodules seprated, without parameter --recurse-submodules.

e.g.,

$ git clone ssh://cy@192.168.5.45/home/cy/repoa
$ git submodule init
$ git submodule update

more details:

$ git submodule init 
Submodule 'repob' (ssh://cy@192.168.5.45/home/cy/repob) registered for path 'repob'
Submodule 'repoc' (ssh://cy@192.168.5.45/home/cy/repoc) registered for path 'repoc'
$ git submodule update
Cloning into '/home/cy/sandbox/repoa/repob'...
Cloning into '/home/cy/sandbox/repoa/repoc'...
Submodule path 'repob': checked out '644355143d331c0dd2b37e8e090f8fabba2031e3'
Submodule path 'repoc': checked out '42b2b2369122f5cf25e4569011177caf58d01d5e'

git submodule init and git submodule update can be merged as git submodule update --init.

3. Use submodule for development

A feature in development would work with a special branch of submodules.

If submodules ara changed, the supermodule can detect it. The supermodule’s repository holds the head commit hash code of the current submodules. The submodules are still independent.

You can change directory to submodules and switch to the proper branches and can work in the submodules directories as they are standalone repositories.

e.g., when a submodule changed:

When stepping into the submodule repob’s directory, it shows that its workspace is at commit 6443551.

cy@cy:~/sandbox/repoa$ ls
hellogit  helloworld  repob  repoc
cy@cy:~/sandbox/repoa$ cd repob
cy@cy:~/sandbox/repoa/repob$ git branch
* (HEAD detached at 6443551)
  master

Switching to another branch to demonstrate changes on submodule. You can also make some changes on the current branch and commit.

cy@cy:~/sandbox/repoa/repob$ git checkout master
Previous HEAD position was 6443551 commit from branch another-b-branch
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
cy@cy:~/sandbox/repoa/repob$ cd ..
cy@cy:~/sandbox/repoa$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   repob (new commits)

no changes added to commit (use "git add" and/or "git commit -a")

In the supermode, it shows that the head commit of submodule is changed.

cy@cy:~/sandbox/repoa$ git diff
diff --git a/repob b/repob
index 6443551..337ce9e 160000
--- a/repob
+++ b/repob
@@ -1 +1 @@
-Subproject commit 644355143d331c0dd2b37e8e090f8fabba2031e3
+Subproject commit 337ce9e16cdd60ed6a5e3941f946741ae6549571

4. Not need to set branch of submodule

Per git’s documents, we can set submodules branch. e.g.,

$ git submodule set-branch --branch another-b-branch repob/

The submodule’s branch is appended to file .gitsubmodes:

[submodule "repob"]
        path = repob
        url = ssh://cy@192.168.5.45/home/cy/repob
[submodule "repob/"]
        branch = another-b-branch

However, the block [submodule] is useless. Please ignore [submodule] in .gitsubmodes.

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2022-10-31 12:20:15  更:2022-10-31 12:21:28 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/28 3:50:22-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计