git 子模块的使用
2021-05-07 本文已影响0人
Biao_349d
-
创建 submoduleA
创建 submoduleB -
初始化上面两个项目的git
-
在 submoduleB 中添加子模块并且关联到submoduleA
git submodule add https://github.com/chaconinc/submoduleA
运行 git status
$ 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文件
- 克隆含有子模块的项目
git clone https://github.com/chaconinc/submoduleB
这时候submoduleB>submoduleA文件夹是空的
初始化更新子模块
git submodule init
git submodule update
第二甚至更多次的时候 更新所有子模块
git submodule update --remote
如果子模块下还有子模块
git submodule update --recursive
- 更多配置
设置之后, git status的时候, 可以看到子模块的更新commit
git config status.submodulesummary 1
git status
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: .gitmodules
modified: submoduleA (new commits)
Submodules changed but not updated:
* submoduleA b035a71...c67058d (2):
> feat: xx
no changes added to commit (use "git add" and/or "git commit -a")
配置更新子模块的分支
git config -f .gitmodules submodules.submoduleA.branch master
.gitmodules
[submodule "submoduleA"]
path = submoduleA
url = https://github.com/zgbbiao/submoduleA.git
[submodules "submoduleA"]
branch = master