我们使用git子模块来管理一些依赖于我们开发的许多其他库的大型项目。每个库都是一个单独的repo,作为子模块引入到依赖项目中。在开发过程中,我们经常想要获取每个依赖子模块的最新版本。
如何获取所有git子模块的最新更改?
我们使用git子模块来管理一些依赖于我们开发的许多其他库的大型项目。每个库都是一个单独的repo,作为子模块引入到依赖项目中。在开发过程中,我们经常想要获取每个依赖子模块的最新版本。
如何获取所有git子模块的最新更改?
当前回答
根据从远程获取每个子模块的“最新”代码的现有答案,澄清一些问题。
如果“最新”是指签入的子模块指针,则无论如何使用:
git submodule update --recursive
- or -
git pull --recurse-submodules --jobs=X
如果“最新”是指main的最新版本,那么类似这样的内容可以起作用:
git submodule foreach "git checkout main && git pull"
不幸的是,这意味着没有“--jobs”选项,因此我们无法并行运行它。我所看到的最接近并行运行的方法是使用pfs-python代码。
其他回答
在init上运行以下命令:
git submodule update --init --recursive
在gitrepo目录中,最适合我。
这将拉动所有最新的子模块。
解释
git - the base command to perform any git command
submodule - Inspects, updates and manages submodules.
update - Update the registered submodules to match what the superproject
expects by cloning missing submodules and updating the working tree of the
submodules. The "updating" can be done in several ways depending on command
line options and the value of submodule.<name>.update configuration variable.
--init without the explicit init step if you do not intend to customize
any submodule locations.
--recursive is specified, this command will recurse into the registered
submodules, and update any nested submodules within.
之后,您可以运行:
git submodule update --recursive
在gitrepo目录中,最适合我。
这将拉动所有最新的子模块。
从回购协议的顶层:
git submodule foreach git checkout develop
git submodule foreach git pull
这将切换所有分支机构以开发和拉动最新的
我编写了这个简单的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
我通过修改上面gahooa的回答做到了这一点:
将其与git〔alias〕集成。。。
如果您的父项目在.gitmodules中有类似的内容:
[submodule "opt/submodules/solarized"]
path = opt/submodules/solarized
url = git@github.com:altercation/solarized.git
[submodule "opt/submodules/intellij-colors-solarized"]
path = opt/submodules/intellij-colors-solarized
url = git@github.com:jkaving/intellij-colors-solarized.git
在.gitconfig中添加类似的内容
[alias]
updatesubs = "!sh -c \"git submodule init && git submodule update && git submodule status\" "
然后,要更新子模块,请运行:
git updatesubs
我在环境设置repo中有一个示例。
我经常使用这个命令,到目前为止,它仍然有效。
git pull
git submodule foreach --recursive git checkout master
git submodule foreach --recursive git pull
希望能快点。