如何只更新特定的 git 子模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16728866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to only update specific git submodules?
提问by Calvin Cheng
So, updating all my submodules is done by running
所以,更新我所有的子模块是通过运行来完成的
git submodule foreach 'git pull origin master'
How do I update a specific submodule, located in say bundle/syntastic
, without updating any other submodules?
如何更新位于 say 中的特定子模块bundle/syntastic
而不更新任何其他子模块?
回答by antoine
I end up there by searching how to update specific submodule only, which means for me, updating a submodule to the ref pointed by its super-repo. Which is not the question nor the answer but only the title.
我最终通过搜索如何仅更新特定子模块来结束,这对我来说意味着将子模块更新为其超级存储库所指向的引用。这不是问题也不是答案,而只是标题。
So in a hope of helping some others like me the answer to the question title is :
因此,为了帮助像我这样的其他人,问题标题的答案是:
git submodule update <specific path to submodule>
which will put this submodule in the state of the ref commited in the super-repo.
这将使这个子模块处于超级存储库中提交的引用状态。
回答by malat
Actually the proper syntax is:
实际上正确的语法是:
$ git clone <remote.git>
$ cd <remote>
$ git submodule update --init -- <specific relative path to submodule>
回答by mpromonet
From the git submodule documentation
--remote This option is only valid for the update command. Instead of using the superproject's recorded SHA-1 to update the submodule, use the status of the submodule's remote-tracking branch. The remote used is branch's remote (branch..remote), defaulting to origin.
--remote 此选项仅对更新命令有效。不要使用超级项目记录的 SHA-1 来更新子模块,而是使用子模块的远程跟踪分支的状态。使用的远程是分支的远程(branch..remote),默认为origin。
In order to update a specific submodule you can use :
为了更新特定的子模块,您可以使用:
git submodule update --remote <path to the submodule>
In your case, it should be :
在你的情况下,它应该是:
git submodule update --remote bundle/syntastic
回答by micahblu
If you've just cloned a repo with submodules, you can clone a specific submodule with:
如果您刚刚使用子模块克隆了一个 repo,则可以使用以下命令克隆特定的子模块:
git submodule update --init submoduleName
git submodule update --init submoduleName
This will clone the master of that submodule, from their you can cd into the submodule and pull whatever branches you need.
这将克隆该子模块的主模块,您可以从它们 cd 进入子模块并拉出您需要的任何分支。
回答by VonC
How do I update a specific submodule, located in say
bundle/syntastic
, without updating any other submodules?
如何更新位于 say 中的特定子模块
bundle/syntastic
,而不更新任何其他子模块?
With Git 2.13 (and the help of submodule.<name>.update
config setting):
使用 Git 2.13(以及submodule.<name>.update
config setting的帮助):
git clone --recurse-submodules="bundle/syntastic"
git config submodule.syntastic.update "git pull origin master"
The second line (to be executed only once) is needed because the clone --recurse-submodules[=<pathspec]
command is equivalent to running git submodule update --init --recursive <pathspec>
immediately after the clone is finished.
And that would only checkout the submodule at its gitlink recorded SHA1, notat the latest remote origin/master
SHA1.
By adding the submodule.<name>.update
config setting, you ensure that the selective clone of the submodule will be followed by an update, only for that submodule.
第二行(只执行一次)是需要的,因为该clone --recurse-submodules[=<pathspec]
命令相当于git submodule update --init --recursive <pathspec>
在克隆完成后立即运行。
这只会在其 gitlink 记录的 SHA1 上签出子模块,而不是在最新的远程origin/master
SHA1 上。
通过添加submodule.<name>.update
配置设置,您可以确保子模块的选择性克隆之后会进行更新,仅针对该子模块。
As part of the Git 2.13 (Q2 2017) "active submodule" feature (see "Ignore new commits for git submodule
"), you have this commit bb62e0afrom Brandon Williams (bmwill
):
作为 Git 2.13(2017 年第二季度)“活动子模块”功能的一部分(请参阅“忽略新提交git submodule
”),您有来自Brandon Williams ( ) 的此提交 bb62e0a:bmwill
clone
: teach--recurse-submodules
to optionally take a pathspecTeach clone
--recurse-submodules
to optionally take a pathspec argument which describes which submodules should be recursively initialized and cloned.
If no pathspec is provided,--recurse-submodules
will recursively initialize and clone all submodules by using a default pathspec of ".
".
In order to construct more complex pathspecs,--recurse-submodules
can be given multiple times.This also configures the '
submodule.active
' configuration option to be the given pathspec, such that any future invocation ofgit submodule update
will keep up with the pathspec.Additionally the switch '
--recurse
' is removed from the Documentation as well as marked hidden in the options array, to streamline the options for submodules. A simple '--recurse
' doesn't convey what is being recursed, e.g. it could mean directories or trees (c.f.ls-tree
).
In a lot of other commands we already have '--recurse-submodules
' to mean recursing into submodules, so advertise this spelling here as the genuine option.
clone
: 教--recurse-submodules
选择一个路径规范教 clone
--recurse-submodules
选择采用 pathspec 参数,该参数描述应递归初始化和克隆哪些子模块。
如果未提供路径规范,--recurse-submodules
将使用默认路径规范“.
”递归初始化和克隆所有子模块。
为了构造更复杂的路径规范,--recurse-submodules
可以多次给出。这还将“
submodule.active
”配置选项配置为给定的路径规范,以便将来的任何调用都git submodule update
将与路径规范保持一致。此外,开关 '
--recurse
' 从文档中删除,并在选项数组中标记为隐藏,以简化子模块的选项。一个简单的 '--recurse
' 并不能传达正在递归的内容,例如它可能意味着目录或树(参见ls-tree
)。
在许多其他命令中,我们已经有 '--recurse-submodules
' 表示递归到子模块中,所以在这里宣传这个拼写是真正的选项。
So the git clone --recursive
man pagenow reads:
所以git clone --recursive
手册页现在是:
--recurse-submodules[=<pathspec]:
After the clone is created, initialize and clone submodules within based on the provided pathspec.
If no pathspec is provided, all submodules are initialized and cloned.
Submodules are initialized and cloned using their default settings.
The resulting clone hassubmodule.active
set to the provided pathspec, or ".
" (meaning all submodules) if no pathspec is provided.
This is equivalent to runninggit submodule update --init --recursive
immediately after the clone is finished. This option is ignored if the cloned repository does not have a worktree/checkout (i.e. if any of--no-checkout
/-n
,--bare
, or--mirror
is given)
创建克隆后,根据提供的 pathspec 初始化和克隆其中的子模块。
如果未提供 pathspec,则初始化和克隆所有子模块。
子模块使用其默认设置进行初始化和克隆。
生成的克隆已submodule.active
设置为提供的路径规范,.
如果未提供路径规范,则设置为“ ”(表示所有子模块)。
这相当于git submodule update --init --recursive
在克隆完成后立即运行。如果克隆库不具有worktree /结帐忽略此选项(即如果任何的--no-checkout
/-n
,--bare
或--mirror
给出)
Example from the t/t7400-submodule-basic.sh
test:
t/t7400-submodule-basic.sh
测试示例:
git clone --recurse-submodules="." \
--recurse-submodules=":(exclude)sub0" \
--recurse-submodules=":(exclude)sub2" \
multisuper multisuper_clone
That would clone and update every submodules, except sub0
and sub2
.
这将克隆和更新每个子模块,除了sub0
和sub2
。
Bonus, with Git 2.22 (Q2 2019) "git clone --recurs
" works better.
奖励,使用 Git 2.22(2019 年第二季度)“ git clone --recurs
”效果更好。
See commit 5c38742(29 Apr 2019) by Nguy?n Thái Ng?c Duy (pclouds
).
(Merged by Junio C Hamano -- gitster
--in commit 2cfab60, 19 May 2019)
参见Nguy?n Thái Ng?c Duy ( ) 的commit 5c38742(29 Apr 2019 )。(由Junio C Hamano合并-- --在commit 2cfab60,2019 年 5 月 19 日)pclouds
gitster
parse-options
: don't emit "ambiguous option" for aliasesChange the option parsing machinery so that e.g. "
clone --recurs ...
" doesn't error out because "clone
" understands both "--recursive
" and "--recurse-submodules
" to mean the same thing.Initially "clone" just understood --recursive until the
--recurses-submodules
alias was added in ccdd3da ("clone
: Add the--recurse-submodules
option as alias for--recursive
", 2010-11-04, Git v1.7.4-rc0).
Since bb62e0a("clone
: teach--recurse-submodules
to optionally take a pathspec", 2017-03-17, Git v2.13.0-rc0) the longer form has been promoted to the default.But due to the way the options parsing machinery works this resulted in the rather absurd situation of:
$ git clone --recurs [...] error: ambiguous option: recurs (could be --recursive or --recurse-submodules)
Add
OPT_ALIAS()
to express this link between two or more options and use it in git-clone.
parse-options
:不要为别名发出“模棱两可的选项”更改选项解析机制,以便例如“
clone --recurs ...
”不会出错,因为“clone
”将“--recursive
”和“--recurse-submodules
”都理解为相同的意思。最初“克隆”只是理解 --recursive 直到
--recurses-submodules
在 ccdd3da 中clone
添加--recurse-submodules
别名(“ :将选项添加 为--recursive
“的别名,2010-11-04,Git v1.7.4-rc0)。
自bb62e0a("clone
: teacher--recurse-submodules
to optional take a pathspec", 2017-03-17, Git v2.13.0-rc0) 起,较长的形式被提升为默认形式。但是由于选项解析机制的工作方式,这导致了相当荒谬的情况:
$ git clone --recurs [...] error: ambiguous option: recurs (could be --recursive or --recurse-submodules)
添加
OPT_ALIAS()
以表达两个或多个选项之间的链接,并在 git-clone 中使用它。