Git submodule
允许一个git
仓库,作为另一个git
仓库的子目录,并且保持父项目和子项目相互独立。
添加
cd <git repo dir>
git submodule add <仓库地址> <本地路径>
添加成功后,在父仓库根目录增加了.gitmodule
文件,内容如下:
[submodule "themes/hugo-bootstrap-x"]
path = themes/hugo-bootstrap-x
url = https://github.com/xiexianbin/hugo-bootstrap-x.git
并且在父仓库的.git
配置文件中加入了submodule
段。
cat .git/config
...
[submodule "themes/hugo-bootstrap-x"]
url = https://github.com/xiexianbin/hugo-bootstrap-x.git
active = true
检出子仓库
clone
一个包含子仓库的仓库目录,并不会clone
下子仓库的文件,需要添加如下操作:
git submodule init
git submodule update
或者使用组合指令:
git submodule update --init --recursive
此时子目录在一个未命名分支,此时子仓库有改动并没有检测到,切换到master分支,并git pull最新代码之后,回到主仓库目录,会显示子仓库修改,需要在主仓库提交修改,即修改指定的commit id:
# 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)
(commit or discard the untracked or modified content in submodules)
modified: themes/hugo-bootstrap-x (modified content)
更新
git add themes/hugo-bootstrap-x
git commit -m "..."
git push
删除子仓库
- 删除.gitsubmodule里相关部分
- 删除.git/config 文件里相关字段
- 删除子仓库目录
$ git rm --cached <子仓库路径>
如果未按照上述步骤删除,可能残留在.git/modudles文件夹内
- 上一页:运行k3s
- 下一页:Go package 包
专栏文章
- Git 专题介绍
- Gitops 介绍
- Git 常用命令
- Duplicating a git repository
- 图解4种git合并分支方法
- Git stash简介
- 使用 GPG 签名 Git Commit
- Git LFS 使用
- Git 仓库瘦身
- git hook 之 pre-commit 代码检查使用介绍
- Git 创建空的远程/本地分支
- Git submodule 使用介绍(当前)
最近更新
最新评论
加载中...