技术归档文章随笔一句话导航搜索关于

Git 常用命令

日期: 2021-03-04 分组: Git 标签: Git通用知识 2分钟 251字

子仓库模块

1. 添加子模块到当前 git 仓库下

Terminal window
1
# 添加lib模块到当前仓库下的lib仓库同名目录
2
git submodule add /path/to/repos/lib.git

此操作会在当前仓库下添加一个 .gitmodules 文件

1
[submodule "lib"]
2
path = lib
3
url = /path/to/repos/lib.git

2. 克隆含有子项目的仓库

  • 方法1
Terminal window
1
# 用来初始化本地配置文件,向.git/config文件中写入了子模块的信息
2
git submodule init
3
# 从子仓库中拉取所有的数据找到父级仓库对应中
4
# 拉去的数据为父仓库提交的最后一次子仓库更改的提交记录
5
# 并将数据保存到父仓库对应的目录中
6
git submodule update
  • 方法2
Terminal window
1
# 递归拉取所有的父仓库和子仓库的相关内容
2
git clone --recursive

3. 一次性操作多个仓库

Terminal window
1
git submodule foreach <git command>
2
3
# 如
4
git submodule foreach git commit -m "commit"
5
git submodule foreach git pull
6
git submodule foreach git push

foreach 后面使用的就是你要对子模块使用的git命令。

人应当是有理想的.
文章目录