如何制作浅git子模块? [英] How to make shallow git submodules?
问题描述
是否可能有浅层子模块?我有一个包含多个子模块的超项目,每个子模块都有悠久的历史,因此不必要地拖累了所有历史.
我所发现的只是此未答复的线程. /p>
我应该 hack git-submodule 实施吗?
新的git submodule update"可以选择浅部克隆子模块存储库.
(并且git 2.10 Q3 2016允许使用git config -f .gitmodules submodule.<name>.shallow true
进行记录.
请参阅此答案的结尾)
请参见提交275cd184d52b5b81cb89e4ec33e540fb2ae61c1f :
将
--depth
选项添加到"git submodule"的添加和更新命令中,然后将其传递给clone命令.当子模块很大并且您对除最新提交以外的任何东西都不感兴趣时,这很有用.添加了测试,并对缩进进行了一些调整,以符合子模块更新可以处理pwd中的符号链接"测试文件的其余部分.
签名人:Fredrik Gustafsson
<iveqy@iveqy.com>
旁白:Jens Lehmann<Jens.Lehmann@web.de>
这意味着它有效:
git submodule add --depth 1 -- repository path
git submodule update --depth -- [<path>...]
使用:
--depth::
此选项对
add
和update
命令有效.
创建一个浅"克隆,其历史记录将被截断为指定的修订版本.
atwyman 添加fatal: reference is not a tree" .
是的.
也就是说,直到git 2.8(2016年3月).使用2.8,即使可以从远程回购HEAD头之一直接访问SHA1,submodule update --depth
也有一次成功的机会.
请参见提交fb43e31 (2016年2月24日): //github.com/stefanbeller"rel =" noreferrer> Stefan Beller(stefanbeller
).
帮助: Junio C Hamano(gitster
).
(由 Junio C Hamano-gitster
-合并在 MVG 指出提交fb43e31 ( git 2.9,2016年2月)
在我看来, commit fb43e31 请求通过SHA1 ID缺少提交,因此服务器上的
uploadpack.allowReachableSHA1InWant
和uploadpack.allowTipSHA1InWant
设置可能会影响此设置是否起作用.
我写了一篇今天发布到git列表,指出了如何在某些情况下(即,如果提交也是标签的话),可以使用浅层子模块更好地工作.
让我们拭目以待.我想这就是为什么fb43e31将对特定SHA1的获取作为对默认分支的获取之后的回退的原因.
不过,在深度1"的情况下,我认为尽早中止是有意义的:如果列出的引用均与请求的引用不匹配,并且服务器不支持SHA1的询问,则没有意义.正在获取任何内容,因为我们将无法以任何一种方式满足子模块的要求.
2016年8月更新(3年后)
使用Git 2.10(2016年第三季度),您将能够做到
git config -f .gitmodules submodule.<name>.shallow true
有关更多信息,请参见"没有额外重量的Git子模块".
Git 2.13(2017年第二季度)确实添加了提交8d3047c (2017年4月19日)通过塞巴斯蒂安·舒伯特(sschuberth
).
(由 Sebastian Schuberth-sschuberth
-在西罗圣蒂莉添加了在他的答案中)
.gitmodules
上的
shallow = true
仅在使用--recurse-submodules
时影响远程HEAD跟踪的参考,即使目标提交是由分支指向的,即使您将branch = mybranch
放在也是如此.
Git 2.20(Q4 2018)改进了对子模块的支持,当工作树中缺少.gitmodules
文件时,该子模块支持已更新为从HEAD:.gitmodules
的blob读取.
请参见提交2b1257e ,提交b5c259f ,提交23dd8f5 ,提交b2faad4 ,提交996df4d ,提交d1b13df , 提交45f5ef3 ,安东尼奥·奥斯佩特( ).
(由 Junio C Hamano-gitster
-合并在git submodule add"命令最终会失败;这样可以防止命令使存储库处于虚假状态(例如,子模块存储库已克隆,但由于config_set_in_gitmodules_file_gently
失败而未更新.gitmodules
).
此外,由于config_from_gitmodules()
现在可以访问全局对象
存储,有必要保护所有调用该函数的代码路径
禁止同时访问全局对象存储.
目前,这仅发生在builtin/grep.c::grep_submodules()
中,因此请致电
grep_read_lock()
,然后调用涉及config_from_gitmodules()
的代码.
注意:在极少数情况下,此新功能不起作用
正确的方法是:在其工作树中嵌套不带.gitmodules
的子模块.
注意:Git 2.24(Q4 2019)修复了克隆浅子模块时可能出现的段错误.
请参见提交ddb3c85 (2019年9月30日): //github.com/auselen"rel =" noreferrer>阿里·乌特库·塞伦( 帮助者:Junio C Hamano '
警告:在Git 2.25(2020年第一季度)中," 已指导文档和代码在用户看到故障时提出更清晰的建议. 请参见提交4f3e57e , Jonathan Tan ( 签名人:Jonathan Tan 当用 失败: 如果无法添加从超级项目的替代项计算出的替代项,则无论是在这种情况下还是其他情况下,建议在克隆时配置" 详细信息: 在Git 2.25(2020年第一季度)中,"git clone --recurse-submodules"与备用对象存储之间的交互设计不良. 签名人:Jonathan Tan 提交 31224cbdc7 (" 如果在超级项目上将" " 指定如何使用通过 Is it possible to have shallow submodules? I have a superproject with several submodules, each with a long history, so it gets unnecessarily big dragging all that history. All I have found is this unanswered thread. Should I just hack git-submodule to implement this? New in the upcoming git1.8.4 (July 2013): " (And git 2.10 Q3 2016 allows to record that with See commit 275cd184d52b5b81cb89e4ec33e540fb2ae61c1f: Add the Tests are added and some indention adjustments were made to conform to the rest of the testfile on "submodule update can handle symbolic links in pwd". Signed-off-by: Fredrik Gustafsson That means this works: With:
This option is valid for
atwyman adds in the comments: As far as I can tell this option isn't usable for submodules which don't track That is true. See commit fb43e31 (24 Feb 2016) by Stefan Beller ( When reviewing a change that also updates a submodule in Gerrit, a common review practice is to download and cherry-pick the patch locally to test it. If
MVG points out in the comments to commit fb43e31 (git 2.9, Feb 2016) It would seem to me that commit fb43e31 requests the missing commit by SHA1 id, so the I guess this is a reason why fb43e31 made the fetch for a specific SHA1 a fallback after the fetch for the default branch.
Update August 2016 (3 years later) With Git 2.10 (Q3 2016), you will be able to do See "Git submodule without extra weight" for more. Git 2.13 (Q2 2017) do add in commit 8d3047c (19 Apr 2017) by Sebastian Schuberth ( a clone of this submodule will be performed as a shallow clone (with a history depth of 1) However, Ciro Santilli adds in the comments (and details in his answer)
Git 2.20 (Q4 2018) improves on the submodule support, which has been updated to read from the blob at See commit 2b1257e, commit 76e9bdc (25 Oct 2018), and commit b5c259f, commit 23dd8f5, commit b2faad4, commit 2502ffc, commit 996df4d, commit d1b13df, commit 45f5ef3, commit bcbc780 (05 Oct 2018) by Antonio Ospite ( When the This makes it possible to use at least the ' Writing to Add a similar check also in Moreover, since NOTE: there is one rare case where this new feature does not work
properly yet: nested submodules without
Note: Git 2.24 (Q4 2019) fixes a possible segfault when cloning a submodule shallow. See commit ddb3c85 (30 Sep 2019) by Ali Utku Selen ( Git 2.25 (Q1 2020), clarifies the See commit f0e58b3 (24 Nov 2019) by Philippe Blain ( Helped-by: Junio C Hamano '
Warning: With Git 2.25 (Q1 2020), the interaction between " The documentation and code have been taught to make more clear recommendations when the users see failures. See commit 4f3e57e, commit 10c64a0 (02 Dec 2019) by Jonathan Tan ( Signed-off-by: Jonathan Tan When recursively cloning a superproject with some shallow modules defined in its fails with: When a alternate computed from the superproject's alternate cannot be added, whether in this case or another, advise about configuring the " That is detailed in: With Git 2.25 (Q1 2020), The interaction between "git clone --recurse-submodules" and alternate object store was ill-designed. Signed-off-by: Jonathan Tan Commit 31224cbdc7 (" If " The " The config submodule documentation now includes:auselen
).
(由 Junio C Hamano-gitster
-合并在提交f0e58b3 (2019年11月24日),由 Junio C Hamano-gitster
-合并在 doc
:提到"git子模块更新"会获取缺少的提交
帮助人:约翰内斯·辛德尔林
签名人:Philippe Blain git submodule
更新'将从子模块中获取新提交如果找不到超级项目中记录的SHA-1,则为远程.文档中未提及.
git clone --recurse-submodules
"与备用对象存储之间的交互设计不良.
jhowtan
).
(由 Junio C Hamano-gitster
-合并在 submodule--helper
:建议致命替代错误
代理人:杰夫·金 .gitmodules
中定义的某些浅层模块递归克隆超级项目,然后使用"--reference=<path>
"重新克隆时,会发生错误.例如:git clone --recurse-submodules --branch=master -j8 \
https://android.googlesource.com/platform/superproject \
master
git clone --recurse-submodules --branch=master -j8 \
https://android.googlesource.com/platform/superproject \
--reference master master2
fatal: submodule '<snip>' cannot add alternate: reference repository
'<snip>' is shallow
submodule.alternateErrorStrategy
"配置选项并使用"--reference-if-able
"而不是"--reference
".
Doc
:解释submodule.alternateErrorStrategy
代理人:杰夫·金 clone
:递归和引用选项触发子模块替代" ,2016-08-17,Git v2.11.0-rc0-合并在第1批)教会Git支持配置选项" submodule.alternateLocation
超级项目上的"strong>"和" submodule.alternateErrorStrategy
".submodule.alternateLocation
"配置为"superproject
",则每当克隆该超级项目的子模块时,它就会从超级项目的$GIT_DIR/objects/info/alternates
计算该子模块的类似替代路径,并引用它.submodule.alternateErrorStrategy
"选项确定如果无法引用该替代项,将发生什么情况.
但是,尚不清楚克隆是否继续进行,就好像该选项未设置为"die"时未指定替代项一样(如配置子模块文档现在包括:
submodule.alternateErrorStrategy::
submodule.alternateLocation
计算的子模块的备用项处理错误.
可能的值为ignore
,info
,die
.
默认值为die
.
请注意,如果设置为ignore
或info
,并且如果计算出的替代项存在错误,则克隆将继续进行,就像未指定替代项一样..
git submodule update
" can optionally clone the submodule repositories shallowly.git config -f .gitmodules submodule.<name>.shallow true
.
See the end of this answer)
--depth
option to the add and update commands of "git submodule", which is then passed on to the clone command. This is useful when the submodule(s) are huge and you're not really interested in anything but the latest commit.<iveqy@iveqy.com>
Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
git submodule add --depth 1 -- repository path
git submodule update --depth -- [<path>...]
--depth::
add
and update
commands.
Create a 'shallow' clone with a history truncated to the specified number of revisions.
master
very closely. If you set depth 1, then submodule update
can only ever succeed if the submodule commit you want is the latest master. Otherwise you get "fatal: reference is not a tree
".
That is, until git 2.8 (March 2016). With 2.8, the submodule update --depth
has one more chance to succeed, even if the SHA1 is directly reachable from one of the remote repo HEADs.stefanbeller
).
Helped-by: Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
-- in commit 9671a76, 26 Feb 2016)
submodule: try harder to fetch needed sha1 by direct fetching sha1
However when testing it locally, the 'git submodule update
' may fail fetching the correct submodule sha1 as the corresponding commit in the submodule is not yet part of the project history, but also just a proposed change.$sha1
was not part of the default fetch, we try to fetch the $sha1
directly. Some servers however do not support direct fetch by sha1, which leads git-fetch
to fail quickly.
We can fail ourselves here as the still missing sha1 would lead to a failure later in the checkout stage anyway, so failing here is as good as we can get.
uploadpack.allowReachableSHA1InWant
and uploadpack.allowTipSHA1InWant
settings on the server will probably affect whether this works.
I wrote a post to the git list today, pointing out how the use of shallow submodules could be made to work better for some scenarios, namely if the commit is also a tag.
Let's wait and see.
Nevertheless, in case of "--depth 1" I think it would make sense to abort early: if none of the listed refs matches the requested one, and asking by SHA1 isn't supported by the server, then there is no point in fetching anything, since we won't be able to satisfy the submodule requirement either way.
git config -f .gitmodules submodule.<name>.shallow true
sschuberth
).
(Merged by Sebastian Schuberth -- sschuberth
-- in commit 8d3047c, 20 Apr 2017)
shallow = true
on .gitmodules
only affects the reference tracked by the HEAD of the remote when using --recurse-submodules
, even if the target commit is pointed to by a branch, and even if you put branch = mybranch
on the .gitmodules
as well.
HEAD:.gitmodules
when the .gitmodules
file is missing from the working tree.ao2
).
(Merged by Junio C Hamano -- gitster
-- in commit abb4824, 13 Nov 2018)
submodule
: support reading .gitmodules
when it's not in the working tree.gitmodules
file is not available in the working tree, try
using the content from the index and from the current branch.
This covers the case when the file is part of the repository but for some
reason it is not checked out, for example because of a sparse checkout.git submodule
' commands
which read the gitmodules
configuration file without fully populating
the working tree..gitmodules
will still require that the file is checked out,
so check for that before calling config_set_in_gitmodules_file_gently
.git-submodule.sh::cmd_add()
to anticipate the eventual failure of the "git submodule add
" command when .gitmodules
is not safely writeable; this prevents the command from leaving the repository in a spurious state (e.g. the submodule repository was cloned but .gitmodules
was not updated because config_set_in_gitmodules_file_gently
failed).config_from_gitmodules()
now accesses the global object
store, it is necessary to protect all code paths which call the function
against concurrent access to the global object store.
Currently this only happens in builtin/grep.c::grep_submodules()
, so call
grep_read_lock()
before invoking code involving config_from_gitmodules()
..gitmodules
in their working tree.
auselen
).
(Merged by Junio C Hamano -- gitster
-- in commit 678a9ca, 09 Oct 2019)
git submodule update
documentation.phil-blain
).
(Merged by Junio C Hamano -- gitster
-- in commit ef61045, 05 Dec 2019)
doc
: mention that 'git submodule update' fetches missing commits
Helped-by: Johannes Schindelin
Signed-off-by: Philippe Blaingit submodule
update' will fetch new commits from the submodule remote if the SHA-1 recorded in the superproject is not found. This was not mentioned in the documentation.
git clone --recurse-submodules
" and alternate object store was ill-designed.
jhowtan
).
(Merged by Junio C Hamano -- gitster
-- in commit 5dd1d59, 10 Dec 2019)
submodule--helper
: advise on fatal alternate error
Acked-by: Jeff King.gitmodules
, then recloning with "--reference=<path>
", an error occurs. For example:git clone --recurse-submodules --branch=master -j8 \
https://android.googlesource.com/platform/superproject \
master
git clone --recurse-submodules --branch=master -j8 \
https://android.googlesource.com/platform/superproject \
--reference master master2
fatal: submodule '<snip>' cannot add alternate: reference repository
'<snip>' is shallow
submodule.alternateErrorStrategy
" configuration option and using "--reference-if-able
" instead of "--reference
" when cloning.
Doc
: explain submodule.alternateErrorStrategy
Acked-by: Jeff Kingclone
: recursive and reference option triggers submodule alternates", 2016-08-17, Git v2.11.0-rc0 -- merge listed in batch #1) taught Git to support the configuration options "submodule.alternateLocation
" and "submodule.alternateErrorStrategy
" on a superproject.submodule.alternateLocation
" is configured to "superproject
" on a superproject, whenever a submodule of that superproject is cloned, it instead computes the analogous alternate path for that submodule from $GIT_DIR/objects/info/alternates
of the superproject, and references it.submodule.alternateErrorStrategy
" option determines what happens if that alternate cannot be referenced.
However, it is not clear that the clone proceeds as if no alternate was specified when that option is not set to "die" (as can be seen in the tests in 31224cbdc7).
Therefore, document it accordingly.
submodule.alternateErrorStrategy::
Specifies how to treat errors with the alternates for a submodule as computed via submodule.alternateLocation
.
Possible values are ignore
, info
, die
.
Default is die
.
Note that if set to ignore
or info
, and if there is an error with the computed alternate, the clone proceeds as if no alternate was specified.
这篇关于如何制作浅git子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!