我们使用git子模块来管理一些依赖于我们开发的许多其他库的大型项目。每个库都是一个单独的repo,作为子模块引入到依赖项目中。在开发过程中,我们经常想要获取每个依赖子模块的最新版本。
如何获取所有git子模块的最新更改?
我们使用git子模块来管理一些依赖于我们开发的许多其他库的大型项目。每个库都是一个单独的repo,作为子模块引入到依赖项目中。在开发过程中,我们经常想要获取每个依赖子模块的最新版本。
如何获取所有git子模块的最新更改?
当前回答
我不知道这是从哪个版本的git开始工作的,但这就是您正在搜索的:
git submodule update --recursive
我也使用git pull来更新根存储库:
git pull && git submodule update --recursive
其他回答
我想你必须写一个剧本才能做到这一点。老实说,我可能会安装python,这样您就可以使用os.walk来cd到每个目录并发出相应的命令。使用python或其他脚本语言(而不是批处理),可以轻松添加/删除子项目,而无需修改脚本。
亨里克走在正确的轨道上。git子模块foreach命令可以执行任意shell脚本。最新的两个选择可能是:
git submodule foreach git pull origin master
and:
git submodule foreach /path/to/some/cool/script.sh
这将遍历所有初始化的子模块并运行给定的命令。
下面是从所有git存储库中提取的命令行,无论它们是否是子模块:
ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
find "$ROOT" -name .git -type d -execdir git pull -v ';'
如果您在顶级git存储库中运行它,可以将“$ROOT”替换为。。
windows 2.6.3的Git:
git子模块更新--rebase--remote
我编写了这个简单的shell脚本,对我来说很好。
#!/bin/bash
#git init
git init
#git clone repo including submodules
git clone --recurse-submodules https://github.com/username/project.git
#change directory -repo
cd project
#update the remote ie tag/commits
git submodule update --remote
#add commit
git commit -a -m "commit in submodule"
#git push
git push -u origin