- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 dotfiles 存储库,其中我所有的 vim 插件都存储为子模块,因此当它们有更改时很容易更新。我以为这两个命令做同样的事情,但我注意到这一定不是这种情况。
我知道我在几个子模块中有更新要下 pull ,所以我从父存储库的根目录运行 git pull origin master --recurse-submodules
。它似乎遍历每个子模块,但只从它们的原始存储库中获取更新。
当我运行 git submodule foreach git pull origin master
时,它实际上在每个存储库中运行了 git pull origin master
,执行获取和 merge 。
使用--recurse-submodules
有什么意义?我对它实际尝试做的事情感到有点困惑,谷歌对我的发现有点神秘。我想也许你们这些聪明人会有更简单的解释。
最佳答案
该选项主要用于获取所有子模块提交,而不是像 master 那样只 pull 一个特定的分支,原因在以下两个提交中详述:
(注意 Git 2.11 中修复了一个错误,请参阅此答案的末尾)
对于 git pull
,此选项已在 ( commit 7dce19d, Nov. 2010, git 1.7.4-rc0) :
fetch
/pull
: Add the--recurse-submodules
option
Until now you had to call "
git submodule update
" (without-N|--no-fetch
option) or something like "git submodule foreach git fetch
" to fetch new commits in populated submodules from their remote.This could lead to "
(commits not present)
" messages in the output of"git diff --submodule
" (which is used by "git gui
" and "gitk
") afterfetching or pulling new commits in the superproject and is an obstacle forimplementing recursive checkout of submodules.
Also "git submodule update
" cannot fetch changes when disconnected, so it was very easy to forget to fetch the submodule changes before disconnecting only to discover later that they are needed.This patch adds the "
--recurse-submodules
" option to recursively fetcheach populated submodule from the url configured in the.git/config
of thesubmodule at the end of each "git fetch
" or during "git pull
" in thesuperproject. The submodule paths are taken from the index.
Commit 88a2197 (March 2011, git 1.7.5-rc1)解释更多:
fetch
/pull
: recurse into submodules when necessary
To be able to access all commits of populated submodules referenced by thesuperproject, it is sufficient to only then let "
git fetch
" recurse into asubmodule when the new commits fetched in the superproject record newcommits for it.
- Having these commits present is extremely useful when using the "
--submodule
" option to "git diff
" (which is what "git gui
" and"gitk
" do since 1.6.6), as all submodule commits needed for creating adescriptive output can be accessed.- Also merging submodule commits (added in 1.7.3) depends on the submodule commits in question being present to work.
- Last but not least this enables disconnected operation when usingsubmodules, as all commits necessary for a successful "
git submodule update -N
" will have been fetched automatically.So we choose this mode as the default for fetch and pull.
git pull origin master --recurse-submodules
git submodule foreach git pull origin master
第一个应该是pull,而不仅仅是fetch,相当于第二个。也许这是参数顺序问题:
git pull --recurse-submodules origin master
但是,这不是为给定分支更新子模块的推荐方法:请参阅以下部分。
请注意,从 master 实际 pull 的正确方法是 register the master branch to the submodule ,使该子模块成为跟踪大师:
git config -f .gitmodules submodule.<path>.branch <branch>
那么一个简单的 git submodule update --remote --recursive
就足够了。
要获取/pull 的分支记录在父存储库中(在 .gitmodules
文件中),因此您甚至不必记住您希望子模块针对哪个分支进行更新。
更新 Git 2.11(2011 年第四季度)
Having a submodule whose "
.git
" repository is somehow corruptcaused a few commands that recurse into submodules loop forever.
参见 commit 10f5c52 (2016 年 9 月 1 日)作者:Junio C Hamano (gitster
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 293c232 ,2016 年 9 月 12 日)
最近的 2016 年提交使用 Git 2.21(2018 年第 4 季度)进行了扩展:“git fetch --recurse-submodules
”( man ) 可能无法获取绑定(bind)到 super 项目的必要提交,这是得到纠正。
参见 commit be76c21 (2018 年 12 月 6 日),和 commit a62387b , commit 26f80cc , commit d5498e0 , commit bcd7337 , commit 16dd6fe , commit 08a297b , commit 25e3d28 , commit 161b1cf (2018 年 11 月 28 日)Stefan Beller (stefanbeller
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 5d3635d ,2019 年 1 月 29 日)
submodule.c
: fetch in submodules git directory instead of in worktreeSigned-off-by: Stefan Beller
Keep the properties introduced in 10f5c52656 ("
submodule
: avoid auto-discovery inprepare_submodule_repo_env()
", 2016-09-01, Git v2.11.0-rc0 -- merge listed in batch #1), by fixating thegit
directory of the submodule.
但是... "git fetch
"( man ) 无法正确处理嵌套子模块,其中不感兴趣的最内层子模块已在上游更新,已更正使用 Git 2.30(2021 年第一季度)。
参见 commit 1b7ac4e (2020 年 11 月 12 日)Peter Kaestle (dscho
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit d627bf6 ,2020 年 11 月 25 日)
submodules
: fix of regression on fetching of non-init subsub-repoSigned-off-by: Peter Kaestle
A regression has been introduced by a62387b ("
submodule.c
: fetch in submodules git directory instead of in worktree", 2018-11-28, Git v2.21.0-rc0 -- merge listed in batch #4).The scenario in which it triggers is when one has a remote repository with a subrepository inside a subrepository like this:
superproject/middle_repo/inner_repo
Person A and B have both a clone of it, while Person B is not working with the
inner_repo
and thus does not have it initialized in his working copy.Now person A introduces a change to the
inner_repo
and propagates it through themiddle_repo
and the superproject.Once person A pushed the changes and person B wants to fetch them using "
git fetch
"(man) on superproject level, B'sgit
(man) call will return with error saying:Could not access submodule '
inner_repo
' Errors during submodule fetch:> middle_repoExpectation is that in this case the inner submodule will be recognized as uninitialized subrepository and skipped by the
git fetch
(man) command.This used to work correctly before 'a62387b ("
submodule.c
: fetch in submodules git directory instead of in worktree", 2018-11-28, Git v2.21.0-rc0 -- merge listed in batch #4)'.Starting with a62387b the code wants to evaluate
"is_empty_dir()
" inside.git/modules
for a directory only existing in the worktree, delivering then of course wrong return value.This patch reverts the changes of a62387b and introduces a regression test.
警告:修复“git fetch --recurse-submodules
”( man) 的早期尝试破坏了另一个用例;使用 Git 2.30(2021 年第一季度)恢复它,直到找到更好的解决方案。
参见 commit 7091499 (2020 年 12 月 2 日)Junio C Hamano (gitster
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit f3e5dcd ,2020 年 12 月 3 日)
Revert "submodules
: fix of regression on fetching of non-init subsub-repo"
This reverts commit 1b7ac4e6d4d490b224f5206af7418ed74e490608 Ralf Thielow reports that "
git fetch
"(man) withsubmodule.recurse
set can result in a bogus and infinitely recursive fetching of the same submodule.
使用 Git 2.30.1(2021 年第一季度),“git fetch --recurse-submodules
”( man ) 修复(第二次尝试)。
参见 commit 505a276 (2020 年 12 月 9 日)Peter Kaestle (dscho
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit c977ff4 ,2021 年 1 月 6 日)
submodules
: fix of regression on fetching of non-init subsub-repoSigned-off-by: Peter Kaestle
CC: Junio C Hamano
CC: Philippe Blain
CC: Ralf Thielow
CC: Eric Sunshine
Reviewed-by: Philippe Blain
A regression has been introduced by a62387b ("
submodule.c
: fetch in submodules git directory instead of in worktree", 2018-11-28, Git v2.21.0-rc0 -- merge listed in batch #4).The scenario in which it triggers is when one has a repository with a submodule inside a submodule like this:
superproject/middle_repo/inner_repo
Person A and B have both a clone of it, while Person B is not working with the
inner_repo
and thus does not have it initialized in his working copy.Now person A introduces a change to the
inner_repo
and propagates it through themiddle_repo
and the superproject.Once person A pushed the changes and person B wants to fetch them using "
git fetch
"(man) at the superproject level, B's git call will return with error saying:Could not access submodule '
inner_repo
' Errors during submodule fetch:middle_repoExpectation is that in this case the inner submodule will be recognized as uninitialized submodule and skipped by the
git fetch
command.This used to work correctly before 'a62387b ("
submodule.c
: fetch in submodules git directory instead of in worktree", 2018-11-28, Git v2.21.0-rc0 -- merge listed in batch #4)'.Starting with a62387b the code wants to evaluate
"is_empty_dir()
" inside.git/modules
for a directory only existing in the worktree, delivering then of course wrong return value.This patch ensures
is_empty_dir()
is getting the correct path of the uninitialized submodule by concatenation of the actual worktree and the name of the uninitialized submodule.The first attempt to fix this regression, in 1b7ac4e ("
submodules
: fix of regression on fetching of non-init subsub-repo", 2020-11-12, Git v2.30.0-rc0 -- merge listed in batch #8), by simply reverting a62387b, resulted in an infinite loop of submodule fetches in the simpler case of a recursive fetch of a superproject with uninitialized submodules, and so this commit was reverted in 7091499 (Revert "submodules
: fix of regression on fetching of non-init subsub-repo", 2020-12-02, Git v2.30.0-rc0 -- merge listed in batch #10).
To prevent future breakages, also add a regression test for this scenario.
"git
fetch --recurse-submodules
from`` "( man ) 多个 Remote (来自远程组,或 "--all")用于制作一个额外的 "git fetch
"( man ) 在子模块中,已使用 Git 2.37(2022 年第 3 季度)更正。
参见 commit 0353c68 (2022 年 5 月 16 日)Junio C Hamano (gitster
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit fa61b77,2022 年 5 月 25 日)
fetch
: do not run a redundant fetch from submoduleReviewed-by: Glen Choo
When 7dce19d ("
fetch/pull
: Add the--recurse-submodules
option", 2010-11-12, Git v1.7.4-rc0 -- merge) introduced the "--recurse-submodule" option, the approach taken was to perform fetches in submodules only once, after all the main fetching (it may usually be a fetch from a single remote, but it could be fetching from a group of remotes usingfetch_multiple()
) succeeded.
Later we added "--all" to fetch from all defined remotes, which complicated things even more.If your project has a submodule, and you try to run "
git fetch
"(man)--recurse-submodule
--all, you'd see a fetch for the top-level, which invokes another fetch for the submodule, followed by another fetch for the same submodule.
All but the last fetch for the submodule come from a "git fetch --recurse-submodules
"(man) subprocess that is spawned via thefetch_multiple()
interface for the remotes, and the last fetch comes from the code at the end.Because recursive fetching from submodules is done in each fetch for the top-level in
fetch_multiple()
, the last fetch in the submodule is redundant.
It only matters whenfetch_one()
interacts with a single remote at the top-level.While we are at it, there is one optimization that exists in dealing with a group of remote, but is missing when "
--all
" is used.
In the former, when the group turns out to be a group of one, instead of spawning "git fetch
" as a subprocess via thefetch_multiple()
interface, we use the normalfetch_one()
code path.
Do the same when handing "--all
", if it turns out that we have only one remote defined.
关于git - "git submodule foreach git pull origin master"和 "git pull origin master --recurse-submodules"有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33421431/
我时不时地输入“git”,然后想到别的东西,然后输入例如“git checkout master”。当然,这给我留下了 $ git git checkout master git: 'git' is
我做到了 git 克隆 git://foo.git 光盘富 ...编辑文件.. 现在我想重新开始。我不在乎我已经做出的任何改变,但我不想再次克隆整个巨型 foo.git,只是丢失我所有的更改。我怎
我在我的电脑上开发代码,我的计算节点很少。 为了让我的程序保持同步,我决定使用 git。以前,我以一种单向模式使用它来“下推”从 PC 到计算节点的更改。但是时不时遇到计算节点特有的小bug,现场修复
虽然它似乎什么也没做,但它没有给出任何警告或错误消息。有什么想法吗? 最佳答案 来自 Git 源的注释: /* * Read a directory tree. We currently ignor
我知道如何为这样的 HTTPS 请求提供用户名和密码: git clone https://username:password@remote 但我想知道如何像这样向 Remote 提供用户名和密码:
Git GUI、Git Bash 和 Git CMD 之间有什么区别?我是初学者,为了进行安装,我发现自己通常同时使用 git bash 和 git CMD 最佳答案 Git CMD 就像使用 git
有人能告诉我git中文件索引被删除是什么意思吗?这些文件在我的 VS Code 中标记为红色,但我仍然可以修改文件并将更改推送到将反射(reflect)这些更改的远程存储库。我认为这一切都是在我使用命
我通过 git 子树将 GLFV 库添加到项目中,但出现此警告“看起来您的 git 安装或您的 git-subtree 安装已损坏”。还描述了几个原因,为什么这可能是: 如 git --exec-pa
我有需要外部 git 项目的 repo,但我不想使用子模块,因为我想在 github 上存档所有文件,所以我认为我只是将具有 git repo 的整个目录添加到 git 但它不t 添加里面的 .git
我有需要外部 git 项目的 repo,但我不想使用子模块,因为我想在 github 上存档所有文件,所以我认为我只是将具有 git repo 的整个目录添加到 git 但它不t 添加里面的 .git
我一直在阅读一篇文章,作者在其中指示:在现有存储库中创建一个新存储库,并想知道这是否是他忽略的错误。稍后我会与他核实。 这些是我要检查的条件: 将现有目录制作成仓库的条件,并且已经 checkin 主
我确实在不同的计算机上处理相同的项目,我想知道是否有一种方法可以跟踪该 .git 文件夹,这样我就不必在所有本地文件中重新配置配置文件。 我将所有工作推送到 bitbucket。 最佳答案 不,没
这个问题在这里已经有了答案: How does git store files? (3 个答案) 关闭 9 年前。 我为我的许多项目创建了一个远程存储库,所以它是我的push 的目的地。与 git
应该如何在 git 中查看文件内容的完整历史记录? 一个文件在 git 中的历史很短,存储库通过 git-svn 同步,但在 svn 中的历史很长。 git 中的历史记录到达文件移动的位置。要查看历史
我是confused here ... 如何对修改后的文件进行git commit,以及如何对新文件进行git commit? 还有,你如何在git中单独提交文件? 最佳答案 git 提交过程分为两个
正在搜索 throw SO 来寻找答案。遇到这个似乎没有给出任何答案的旧线程。重新触发此线程,希望有人知道! 有人能告诉我 git subtree 和 git filter-branch 的区别吗?为
我想知道是否有一种方法可以避免在每个 Git 命令的开头键入单词 git。 如果有一种方法可以在打开命令提示符进入 “Git 模式” 后只使用一次 git 命令就好了。 例如: git> 之后,我们键
当您修改工作目录中的文件时,git 会告诉您使用“git add”暂存。 当您向工作目录添加新文件时,git 会告诉您使用“git add”开始跟踪。 我对这两个概念有点困惑,因为我假设跟踪文件的更改
为什么 git://有效 $ git clone git://github.com/schacon/grit.git Cloning into 'grit'... ... Checking conne
我在以下沙箱中练习 git:https://learngitbranching.js.org/?NODEMO 我在两个单独的 session 中运行了两组命令。第一组命令顺序如下: git clone
我是一名优秀的程序员,十分优秀!