为什么 git 子模块更新在 git checkout 上不是自动的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1899792/
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
Why is git submodule update not automatic on git checkout?
提问by serbaut
When switching branches with git checkout I would assume that most of the time you would want to update your submodules.
当使用 git checkout 切换分支时,我会假设大部分时间您都希望更新子模块。
- In what situation do you notwant to update submodules after switching?
- What would break if this was done automatically by git checkout?
- 在什么情况下,你不希望更新子模块切换后?
- 如果这是由 git checkout 自动完成的,会中断什么?
Updated with example:
更新示例:
- Branch A has submodule S at 3852f1
- Branch B has submodule S at fd72d7
- 分支 A 在 3852f1 有子模块 S
- 分支 B 在 fd72d7 处有子模块 S
On branch A, git checkout B will result in a working copy of branch B with submodule S at 3852f1 (with a modified S). git submodule update will checkout S at fd72d7.
在分支 A 上, git checkout B 将生成分支 B 的工作副本,子模块 S 位于 3852f1(带有修改的 S)。git submodule update 将在 fd72d7 处检出 S。
采纳答案by Aaron
I believe that the submodules not updating automatically is in line with the development goals of Git. Git is meant to work in a distributed mode and doesn't presume that you are even able to connect to a non-local repository unless you explicitly tell it to. Git not auto-refreshing a submodule would be the expected behavior when thought of that way.
我认为不自动更新的子模块符合 Git 的开发目标。Git 旨在以分布式模式工作,并且不假定您甚至能够连接到非本地存储库,除非您明确告诉它。考虑到这种方式时,Git 不自动刷新子模块将是预期的行为。
With that being said, if you know that you always want those sub-modules to be pulled in and you know that you would never branch off of those submodules to another local repository, then it shouldn't break anything if you automatically refreshed them after a checkout.
话虽如此,如果您知道您总是希望将这些子模块拉入并且您知道您永远不会将这些子模块分支到另一个本地存储库,那么如果您在之后自动刷新它们,它就不应该破坏任何东西结帐。
回答by VonC
With Git 2.27 (Q2 2020), the "--recurse-submodules
" option is better documented.
在 Git 2.27(2020 年第二季度)中,“ --recurse-submodules
”选项得到了更好的记录。
See commit acbfae3, commit 4da9e99, commit d09bc51, commit b3cec57, commit dd0cb7d(06 Apr 2020) by Damien Robert (damiens-robert
).
(Merged by Junio C Hamano -- gitster
--in commit cc908db, 28 Apr 2020)
请参阅Damien Robert ( ) 的commit acbfae3、commit 4da9e99、commit d09bc51、commit b3cec57、commit dd0cb7d(2020 年 4 月 6 日)。(由Junio C Hamano合并-- --在cc908db 提交中,2020 年 4 月 28 日)damiens-robert
gitster
doc
:--recurse-submodules
mostly applies to activesubmodulesSigned-off-by: Damien Robert
Helped-by: Philippe BlainThe documentation refers to "initialized" or "populated" submodules, to explain which submodules are affected by '
--recurse-submodules
', but the real terminology here is 'active
' submodules. Update the documentation accordingly.Some terminology:
- Activeis defined in gitsubmodules(7), it only involves the configuration variables '
submodule.active
', 'submodule.<name>.active
' and 'submodule.<name>.url
'.
The functionsubmodule.c::is_submodule_active
checks that a submodule is active.- Populatedmeans that the submodule's working tree is present (and the gitfile correctly points to the submodule repository), i.e. either the superproject was cloned with
--recurse-submodules
, or the user rangit submodule update --init
, orgit submodule init [<path>]
andgit submodule update [<path>]
separately which populated the submodule working tree.
This does not involve the 3 configuration variables above.- Initialized(at least in the context of the man pages involved in this patch) means both "populated" and "active"as defined above, i.e. what
[
git submodule update --init](https://git-scm.com/docs/git-submodule)
does.The
--recurse-submodules
option mostly affects active submodules.An exception is
git fetch
where the option affects populated submodules.
As a consequence, ingit pull --recurse-submodules
the fetch affects populated submodules, but the resulting working tree update only affects active submodules.In the documentation of
git-pull
, let's distinguish between the fetching part which affects populated submodules, and the updating of worktrees, which only affects active submodules.
doc
:--recurse-submodules
主要适用于活动子模块签字人:Damien Robert
帮助人:Philippe Blain该文档提到了“初始化”或“填充”子模块,以解释哪些子模块受“
--recurse-submodules
”影响,但这里真正的术语是“active
”子模块。相应地更新文档。一些术语:
- Active定义在 gitsubmodules(7) 中,它只涉及配置变量 '
submodule.active
'、'submodule.<name>.active
' 和 'submodule.<name>.url
'。
该函数submodule.c::is_submodule_active
检查子模块是否处于活动状态。- 填充装置,所述子模块的工作树存在(以及gitfile正确地指向子模块储存库),即,或者上层项目克隆用
--recurse-submodules
,或者用户RANgit submodule update --init
,或git submodule init [<path>]
和git submodule update [<path>]
分开该填充子模块工作树。
这不涉及上面的 3 个配置变量。- 初始化(至少在此补丁中涉及的手册页的上下文中)意味着如上定义的“已填充”和“活动”,即
[
git submodule update --init](https://git-scm.com/docs/git-submodule)
所做的。该
--recurse-submodules
选项主要影响活动的子模块。一个例外是
git fetch
该选项影响填充的子模块。
因此,在git pull --recurse-submodules
fetch 中会影响填充的子模块,但由此产生的工作树更新仅影响活动的子模块。在 的文档中
git-pull
,让我们区分影响填充子模块的获取部分和仅影响活动子模块的工作树的更新。