Git 子模块推送

发布于 2024-11-03 22:30:14 字数 62 浏览 3 评论 0原文

如果我修改子模块,我可以将提交推回到子模块原点,还是需要克隆? 如果克隆,我可以将克隆存储在另一个存储库中吗?

If I modify a submodule, can I push the commit back to the submodule origin, or would that require a clone?
If clone, can I store a clone inside another repository?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眸中客 2024-11-10 22:30:14

子模块只不过是另一个存储库中 git 存储库的克隆,带有一些额外的元数据(gitlink 树条目、.gitmodules 文件)

$ cd your_submodule
$ git checkout master
<hack,edit>
$ git commit -a -m "commit in submodule"
$ git push
$ cd ..
$ git add your_submodule
$ git commit -m "Updated submodule"

A submodule is nothing but a clone of a git repo within another repo with some extra meta data (gitlink tree entry, .gitmodules file )

$ cd your_submodule
$ git checkout master
<hack,edit>
$ git commit -a -m "commit in submodule"
$ git push
$ cd ..
$ git add your_submodule
$ git commit -m "Updated submodule"
遗忘曾经 2024-11-10 22:30:14

请注意,自 git1.7.11 ([ANNOUNCE] Git 1.7.11.rc1发行说明,2012 年 6 月)提到:

git push --recurse-submodules”学会了选择性地查看绑定到超级项目的子模块的历史并将它们推出。

可能是在此补丁 和 --on-demand 选项:

recurse-submodules=<check|on-demand>::

确保要推送的修订版本使用的所有子模块提交在远程跟踪分支上可用。

  • 如果使用check,则会检查要推送的修订版本中更改的所有子模块提交是否在远程上可用。
    否则推送将被中止并以非零状态退出。
  • 如果使用on-demand,则将推送要推送的修订版本中更改的所有子模块。
    如果 on-demand 无法推送所有必要的修订,它也将被中止并以非零状态退出。

因此,您可以使用(来自父存储库)一次性推送所有内容:

git push --recurse-submodules=on-demand

此选项仅适用于一层嵌套。对另一个子模块内部的子模块的更改不会被推送。


使用 git 2.7(2016 年 1 月),一个简单的 git Push 就足以推送父存储库...及其所有子模块。

请参阅提交 d34141c提交 f5c7cd9 (2015 年 12 月 3 日),提交 f5c7cd9(2015 年 12 月 3 日),以及提交 b33a15b(11 月 17 日) 2015),作者:Mike Crowe (mikecrowe)
(由 Junio C Hamano -- gitster -- 合并于 提交 5d35d72,2015 年 12 月 21 日)

push:添加recurseSubmodules配置选项

--recurse-submodules 命令行参数已存在于某些
时间,但它没有等效的配置文件。

按照git fetch对应参数的风格,我们
发明 push.recurseSubmodules 来为此参数提供默认值。
这还需要添加 --recurse-submodules=no
允许在命令行上覆盖配置
必填。

实现这一点的最直接方法似乎是
push 使用 submodule-config 中的代码的方式与 fetch 类似。

git config 文档现在包括

push.recurseSubmodules

确保要推送的修订版本使用的所有子模块提交在远程跟踪分支上可用。

  • 如果值为“check”,则 Git 将验证要推送的修订版中更改的所有子模块提交是否在子模块的至少一个远程上可用。如果缺少任何提交,推送将中止并以非零状态退出。
  • 如果值为“on-demand”,则将推送要推送的修订版本中更改的所有子模块。如果 on-demand 无法推送所有必要的修订,它也将被中止并以非零状态退出。 -
  • 如果值为“no”,则保留推送时忽略子模块的默认行为。

您可以在推送时通过指定“--recurse-submodules=check|on-demand|no”来覆盖此配置。

所以:

git config push.recurseSubmodules on-demand
git push

Git 2.12(2017 年第一季度)

git push --dry-run --recurse-submodules=on-demand 实际上可以工作。

请参阅 提交 0301c82提交 1aa7365(2016 年 11 月 17 日),作者:Brandon Williams (mbrandonw)
(由 Junio C Hamano -- gitster -- 合并于 提交 12cf113,2016 年 12 月 16 日)

使用 --dry-run 进行推送运行 当推送配置为推送子模块时,实际上(Git 2.11 Dec. 2016 及更低版本/之前)不会执行试运行
按需。
相反,所有需要推送的子模块实际上都被推送到其远程,而超级项目的任何更新都作为空运行执行。
这是一个错误,而不是预运行的预期行为。

在配置为“按需”递归推送子模块时,教导 push 遵守 --dry-run 选项。
这是通过将 --dry-run 标志传递给子进程来完成的,该子进程在执行空运行时执行子模块推送。


仍然在 Git 2.12 中,您现在有一个“--recurse-submodules=only”选项可以在不推送顶级超级项目的情况下推送子模块

请参阅提交225e8bf提交 6c656c3, 提交 14c01bd(2016 年 12 月 19 日)作者:Brandon Williams (mbrandonw)
(由 Junio C Hamano -- gitster -- 合并于 提交 792e22e,2017 年 1 月 31 日)


使用 Git 2.36(2022 年第 2 季度),“git fetch --仅协商< /a>"(man ) 是 git 推送(man) 来找出我们历史的哪一部分在另一边缺失了。
即使设置了 fetch.recursesubmodules 配置变量,它也不应该递归到子模块,也不应该触发“gc”。
代码已经被收紧,以确保它只进行共同祖先发现,而不进行其他操作。

请参阅提交 386c076提交 135a12b, 提交 bec587d(2022 年 1 月 18 日)作者:Glen Choo (chooglen)
请参阅 commit de4eaae(2022 年 1 月 20 日),作者:Junio C Hamano (gitster)
(由 Junio C Hamano -- gitster -- 合并于 提交 472a219,2022 年 2 月 9 日)

fetch --negotiate-only:不更新子模块

签字人:Glen Choo

git fetch --negotiate-only(man) 是推送协商的实现细节,与大多数 git fetch(man) 调用,实际上并不更新主存储库。
因此,即使启用了子模块递归,它也不应该更新子模块。

这不仅慢,而且是错误的,例如使用“submodule.recurse=true”进行推送协商将导致子模块更新,因为它调用git fetch --negotiate-only< /代码>.

如果给出了 --negotiate-only,则通过禁用子模块递归来修复此问题。
由于这使得 --negotiate-only--recurse-submodules 不兼容,请检查此无效组合并终止。

fetch-options 现在包含在其 手册页

这与 --recurse-submodules=[yes|on-demand] 不兼容。


在 Git 2.39(2022 年第 4 季度)中,使用“--recurse-submodules=on-demand”递归推送所有子模块。

请参阅 提交 e62f779(2022 年 11 月 14 日),作者:乔纳森·谭 (jhowtan)
(由 Junio C Hamano -- gitster -- 合并于 提交 173fc54,2022 年 11 月 23 日)

Doc:文档push.recurseSubmodules =仅

签字人:Jonathan Tan
签字人:Taylor Blau

Git 学会了通过用户通过 6c656c3 ("子模块:添加 RECURSE_SUBMODULES_ONLY 值",2016-12-20,Git v2.12.0-rc0 -- < a href="https://github.com/git/git/commit/792e22e3fd99f204be11b0ff173f2d991308dca5" rel="noreferrer">合并 第 8 批) 和 225e8bf ("push: 添加仅推送子模块的选项", 2016-12-20, Git v2.12.0-rc0 -- 合并列于 第 8 批 a>).
对于经常使用此功能的用户来说,最好有一个等效的配置。

事实证明,这样的配置 (push.recurseSubmodules=only) 已经受到支持,尽管提交消息中既没有记录也没有提及,因为 - -recurse-submodules=only 功能已实现(用于解析 --recurse-submodules 的函数已更新为仅支持,但相同的函数用于解析 push。 recurseSubmodules 也是如此)。
剩下的就是记录它并测试它,这就是这次提交的作用。

当递归到本身具有 push.recurseSubmodules=only 配置的子模块时,可能会出现混淆,因为如果存储库仅推送其子模块而不推送其本身,则其超级项目永远无法被推。
因此,请将此类配置视为“按需”,并打印警告消息。

警告消息:

recursing into submodule with push.recurseSubmodules=only; using on-demand instead

git config 现在包含在其 手册页

可能是“检查”、“按需”、“”或“”,具有相同的行为
就像“push --recurse-submodules”一样。

git Push 现在包含在其

当使用“on-demand”或“only”时,如果子模块具有
push.recurseSubmodules={on-demand,only}”或“submodule.recurse”配置,
将会发生进一步的递归。在这种情况下,“only”被视为“on-demand”。

Note that since git1.7.11 ([ANNOUNCE] Git 1.7.11.rc1 and release note, June 2012) mentions:

"git push --recurse-submodules" learned to optionally look into the histories of submodules bound to the superproject and push them out.

Probably done after this patch and the --on-demand option:

recurse-submodules=<check|on-demand>::

Make sure all submodule commits used by the revisions to be pushed are available on a remote tracking branch.

  • If check is used, it will be checked that all submodule commits that changed in the revisions to be pushed are available on a remote.
    Otherwise the push will be aborted and exit with non-zero status.
  • If on-demand is used, all submodules that changed in the revisions to be pushed will be pushed.
    If on-demand was not able to push all necessary revisions it will also be aborted and exit with non-zero status.

So you could push everything in one go with (from the parent repo) a:

git push --recurse-submodules=on-demand

This option only works for one level of nesting. Changes to the submodule inside of another submodule will not be pushed.


With git 2.7 (January 2016), a simple git push will be enough to push the parent repo... and all its submodules.

See commit d34141c, commit f5c7cd9 (03 Dec 2015), commit f5c7cd9 (03 Dec 2015), and commit b33a15b (17 Nov 2015) by Mike Crowe (mikecrowe).
(Merged by Junio C Hamano -- gitster -- in commit 5d35d72, 21 Dec 2015)

push: add recurseSubmodules config option

The --recurse-submodules command line parameter has existed for some
time but it has no config file equivalent.

Following the style of the corresponding parameter for git fetch, let's
invent push.recurseSubmodules to provide a default for this parameter.
This also requires the addition of --recurse-submodules=no to
allow the configuration to be overridden on the command line when
required.

The most straightforward way to implement this appears to be to make
push use code in submodule-config in a similar way to fetch.

The git config doc now include:

push.recurseSubmodules:

Make sure all submodule commits used by the revisions to be pushed are available on a remote-tracking branch.

  • If the value is 'check', then Git will verify that all submodule commits that changed in the revisions to be pushed are available on at least one remote of the submodule. If any commits are missing, the push will be aborted and exit with non-zero status.
  • If the value is 'on-demand' then all submodules that changed in the revisions to be pushed will be pushed. If on-demand was not able to push all necessary revisions it will also be aborted and exit with non-zero status. -
  • If the value is 'no' then default behavior of ignoring submodules when pushing is retained.

You may override this configuration at time of push by specifying '--recurse-submodules=check|on-demand|no'.

So:

git config push.recurseSubmodules on-demand
git push

Git 2.12 (Q1 2017)

git push --dry-run --recurse-submodules=on-demand will actually work.

See commit 0301c82, commit 1aa7365 (17 Nov 2016) by Brandon Williams (mbrandonw).
(Merged by Junio C Hamano -- gitster -- in commit 12cf113, 16 Dec 2016)

push run with --dry-run doesn't actually (Git 2.11 Dec. 2016 and lower/before) perform a dry-run when push is configured to push submodules
on-demand.
Instead all submodules which need to be pushed are actually pushed to their remotes while any updates for the superproject are performed as a dry-run.
This is a bug and not the intended behaviour of a dry-run.

Teach push to respect the --dry-run option when configured to recursively push submodules 'on-demand'.
This is done by passing the --dry-run flag to the child process which performs a push for a submodules when performing a dry-run.


And still in Git 2.12, you now havea "--recurse-submodules=only" option to push submodules out without pushing the top-level superproject.

See commit 225e8bf, commit 6c656c3, commit 14c01bd (19 Dec 2016) by Brandon Williams (mbrandonw).
(Merged by Junio C Hamano -- gitster -- in commit 792e22e, 31 Jan 2017)


With Git 2.36 (Q2 2022), "git fetch --negotiate-only"(man) is an internal command used by git push(man) to figure out which part of our history is missing from the other side.
It should never recurse into submodules even when fetch.recursesubmodules configuration variable is set, nor it should trigger "gc".
The code has been tightened up to ensure it only does common ancestry discovery and nothing else.

See commit 386c076, commit 135a12b, commit bec587d (18 Jan 2022) by Glen Choo (chooglen).
See commit de4eaae (20 Jan 2022) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 472a219, 09 Feb 2022)

fetch --negotiate-only: do not update submodules

Signed-off-by: Glen Choo

git fetch --negotiate-only(man) is an implementation detail of push negotiation and, unlike most git fetch(man) invocations, does not actually update the main repository.
Thus it should not update submodules even if submodule recursion is enabled.

This is not just slow, it is wrong e.g. push negotiation with "submodule.recurse=true" will cause submodules to be updated because it invokes git fetch --negotiate-only.

Fix this by disabling submodule recursion if --negotiate-only was given.
Since this makes --negotiate-only and --recurse-submodules incompatible, check for this invalid combination and die.

fetch-options now includes in its man page:

This is incompatible with --recurse-submodules=[yes|on-demand].


With Git 2.39 (Q4 2022), push all submodules recursively with '--recurse-submodules=on-demand'.

See commit e62f779 (14 Nov 2022) by Jonathan Tan (jhowtan).
(Merged by Junio C Hamano -- gitster -- in commit 173fc54, 23 Nov 2022)

Doc: document push.recurseSubmodules=only

Signed-off-by: Jonathan Tan
Signed-off-by: Taylor Blau

Git learned pushing submodules without pushing the superproject by the user specifying --recurse-submodules=only through 6c656c3 ("submodules: add RECURSE_SUBMODULES_ONLY value", 2016-12-20, Git v2.12.0-rc0 -- merge listed in batch #8) and 225e8bf ("push: add option to push only submodules", 2016-12-20, Git v2.12.0-rc0 -- merge listed in batch #8).
For users who use this feature regularly, it is desirable to have an equivalent configuration.

It turns out that such a configuration (push.recurseSubmodules=only) is already supported, even though it is neither documented nor mentioned in the commit messages, due to the way the --recurse-submodules=only feature was implemented (a function used to parse --recurse-submodules was updated to support only, but that same function is used to parse push.recurseSubmodules too).
What is left is to document it and test it, which is what this commit does.

There is a possible point of confusion when recursing into a submodule that itself has the push.recurseSubmodules=only configuration, because if a repository has only its submodules pushed and not itself, its superproject can never be pushed.
Therefore, treat such configurations as being "on-demand", and print a warning message.

Warning message:

recursing into submodule with push.recurseSubmodules=only; using on-demand instead

git config now includes in its man page:

May be "check", "on-demand", "only", or "no", with the same behavior
as that of "push --recurse-submodules".

git push now includes in its man page:

When using 'on-demand' or 'only', if a submodule has a
"push.recurseSubmodules={on-demand,only}" or "submodule.recurse" configuration,
further recursion will occur. In this case, "only" is treated as "on-demand".

命硬 2024-11-10 22:30:14

可以使用git的foreach命令

bash 命令示例:

git submodule foreach "git add . && git commit -m 'update' && git push"

You can use the foreach command of git

example of bash command:

git submodule foreach "git add . && git commit -m 'update' && git push"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文