Bra*_*son 1748 git git-submodules
我们使用git子模块来管理一些依赖于我们开发的许多其他库的大型项目.每个库都是作为子模块引入依赖项目的单独repo.在开发过程中,我们经常想要抓住每个依赖子模块的最新版本.
git有内置命令来执行此操作吗?如果没有,Windows批处理文件或类似文件怎么样呢?
Hen*_*son 2325
对于git 1.8.2或更高版本,--init添加了该选项以支持更新远程分支的最新提示:
git submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)
这有额外的好处是尊重--remote或.gitmodules文件中指定的任何"非默认"分支(如果你碰巧有任何,默认是origin/master,在这种情况下,这里的一些其他答案也可以工作).
对于git 1.7.3或更高版本,你可以使用(但下面有关于更新仍然适用的问题):
git submodule update --recursive --remote
Run Code Online (Sandbox Code Playgroud)
要么:
git submodule update --recursive
Run Code Online (Sandbox Code Playgroud)
如果你想把你的子模块拉到repo指向的最新提交intead.
注意:如果这是您第一次签出仓库,则需要先使用.git/config:
git pull --recurse-submodules
Run Code Online (Sandbox Code Playgroud)
对于较旧的git 1.6.1或更高版本,你可以使用类似的东西(修改为适合):
git submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅git-submodule(1)
Ale*_*osh 617
如果你需要将子模块的东西拉到你的子模块库中使用
git pull --recurse-submodules --jobs=10
Run Code Online (Sandbox Code Playgroud)
一个功能git首先在1.7.3中学到了.
但这不会检查子模块中的正确提交(主存储库指向的提交)
要检查子模块中的正确提交,您应该在使用后更新它们
git pull --recurse-submodules --jobs=10
Run Code Online (Sandbox Code Playgroud)
abc*_*123 375
git submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)
从git repo目录中,对我来说效果最好.
这将拉出所有最新的包括子模块.
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.
Run Code Online (Sandbox Code Playgroud)
git submodule update --recursive
Run Code Online (Sandbox Code Playgroud)
从git repo目录中,对我来说效果最好.
这将拉出所有最新的包括子模块.
git submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)
gah*_*ooa 302
注意:这是从2009年开始,可能会很好,但现在有更好的选择.
我们用这个.它被称为git-pup:
#!/bin/bash
# Exists to fully update the git repo that you are sitting in...
git pull && git submodule init && git submodule update && git submodule status
Run Code Online (Sandbox Code Playgroud)
只需将其放在合适的bin目录(/ usr/local/bin)中.如果在Windows上,您可能需要修改语法才能使其工作:)
更新:
回应原作者关于拉入所有子模块的所有HEAD的评论 - 这是一个很好的问题.
我很确定在git内部没有这个命令.为此,您需要确定HEAD对于子模块的真正含义.这可能就像说master是最新的分支等一样简单......
在此之后,创建一个执行以下操作的简单脚本:
git submodule status"已修改"的存储库.输出行的第一个字符表示这一点.如果修改了子仓库,您可能不想继续.git checkout master && git pull.检查错误.我想提一下,这种风格并不是git子模块的设计用途.通常情况下,您想说"LibraryX"的版本为"2.32"并保持这种状态,直到我告诉它"升级".
也就是说,从某种意义上说,你正在用所描述的脚本做什么,但更自动.需要护理!
更新2:
如果您使用的是Windows平台,则可能需要使用Python来实现脚本,因为它在这些方面非常强大.如果您使用的是unix/linux,那么我建议只使用一个bash脚本.
需要澄清吗?刚发表评论.
mtu*_*tte 157
亨里克走在正确的轨道上.'foreach'命令可以执行任何任意shell脚本.拉最新的两种选择可能是,
git submodule foreach git pull origin master
Run Code Online (Sandbox Code Playgroud)
和,
git submodule foreach /path/to/some/cool/script.sh
Run Code Online (Sandbox Code Playgroud)
这将迭代所有初始化的子模块并运行给定的命令.
zac*_*eat 142
以下在Windows上为我工作.
git submodule init
git submodule update
Run Code Online (Sandbox Code Playgroud)
ant*_*xic 33
编辑:
在评论中指出(philfreo)需要最新版本.如果有任何嵌套子模块需要在其最新版本中:
git submodule foreach --recursive git pull
Run Code Online (Sandbox Code Playgroud)
-----下面的过时评论-----
这不是官方的做法吗?
git submodule update --init
Run Code Online (Sandbox Code Playgroud)
我每次都用它.到目前为止没问题.
编辑:
我发现你可以使用:
git submodule foreach --recursive git submodule update --init
Run Code Online (Sandbox Code Playgroud)
这也将递归地拉出所有子模块,即依赖性.
Seb*_*tte 33
因为它可能会发生,你的子模块的默认分支是不是 master,我这是怎么自动化全Git的子模块的升级:
git submodule init
git submodule update
git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'
Run Code Online (Sandbox Code Playgroud)
Yas*_*ash 28
克隆和初始化子模块
git clone git@github.com:speedovation/kiwi-resources.git resources
git submodule init
Run Code Online (Sandbox Code Playgroud)
在开发过程中,只需拉动并更新子模块即可
git pull --recurse-submodules && git submodule update --recursive
Run Code Online (Sandbox Code Playgroud)
git submodule foreach git pull origin master
Run Code Online (Sandbox Code Playgroud)
git submodule update --remote --merge
Run Code Online (Sandbox Code Playgroud)
注意:最后两个命令具有相同的行为
Jen*_*ohl 20
我不知道从哪个版本的git开始工作,但这就是你要搜索的内容:
git submodule update --recursive
Run Code Online (Sandbox Code Playgroud)
我也用它git pull来更新根存储库:
git pull && git submodule update --recursive
Run Code Online (Sandbox Code Playgroud)
小智 17
根据从远程提取每个子模块的“最新”代码的现有答案来澄清一些事情。
如果“ latest ”表示已签入的子模块指针,则务必使用:
git submodule update --recursive
- or -
git pull --recurse-submodules --jobs=X
Run Code Online (Sandbox Code Playgroud)
如果“ latest ”意味着main的最新版本,那么这样的事情就可以工作:
git submodule foreach "git checkout main && git pull"
Run Code Online (Sandbox Code Playgroud)
不幸的是,这意味着没有“--jobs”选项,因此我们无法并行运行它。我见过的最接近并行运行的方法是使用pfs python 代码。
Bin*_* Ho 15
我经常使用这个命令,到目前为止它有效。
git pull
git submodule foreach --recursive git checkout master
git submodule foreach --recursive git pull
Run Code Online (Sandbox Code Playgroud)
希望这更快。
Von*_*onC 11
正如抗毒剂的回答所述,简单的git submodule foreach --recursive git pull就足够了。
弗朗西斯·培根的答案可能git pull --recurse-submodules有所不同。
您可以测试一下,看看使用详细选项会发生什么情况:
git pull -v --recurse-submodules
Run Code Online (Sandbox Code Playgroud)
但为此,您将需要 Git 2.40(2023 年第一季度)。
“ git pull -v --recurse-submodules” ( man )尝试-v向下传递给底层( man ),但底层不理解请求并被拒绝:这已在 Git 2.40 (Q1 2023) 中得到纠正。git submodule update
请参阅Sven Strickroth ( )的提交 6f65f84(2022 年 12 月 10 日)。(由Junio C Hamano 合并 -- --在提交 b3b9e5c中,2022 年 12 月 28 日)csware
gitster
submodule:接受-v更新命令签署人:Sven Strickroth
由于a56771a(“
builtin/pull:尊重子模块中的详细设置”,2018-01-25,Git v2.17.0-rc0 -合并在批#3中列出),“git pull -v --recurse-submodules” (man)将传播-v到子模块命令,但因为后者命令不理解该选项,它会呕吐。教“
git submodule update” (男人)接受修复它的选项。
不再“呕吐”(即显示用法“ git submodule foreach [--quiet] [--recursive] [--] <command>”),因为这-v是 的未知选项git submodule。
上面的答案很好,但是我们使用git-hooks使其更容易,但事实证明,在git 2.14中,可以将其设置git config submodule.recurse为true,以使子模块在拉到git存储库时得以更新。
但是,如果所有子模块都在分支上,这将具有推动所有子模块更改的副作用,但是如果您已经需要这种行为,则可以完成此工作。
可以使用以下方法完成:
git config submodule.recurse true
Run Code Online (Sandbox Code Playgroud)
从存储库的顶层:
git submodule foreach git checkout develop
git submodule foreach git pull
Run Code Online (Sandbox Code Playgroud)
这将切换所有分支以开发并拉取最新版本
对我来说,git 2.24.03,更新到 .gitmoodule 中定义的远程分支的最新提交。
git submodule update --recursive --init
git submodule update --recursive --remote
git 版本 2.24.3 (Apple Git-128)
请注意:
有人说这
git pull --recurse-submodules与git submodule update --recursive --remote. 但是从我的测试来看,git pull --recurse-submodules可能无法更新到 .gitmoodule 中定义的远程分支的最新提交。
| 归档时间: |
|
| 查看次数: |
947146 次 |
| 最近记录: |