git Git子模块推送

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5814319/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:48:32  来源:igfitidea点击:

Git submodule push

gitgit-submodules

提问by webjay

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?

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

回答by manojlds

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

子模块只不过是另一个存储库中的 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"

回答by VonC

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

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

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

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

Probably done after this patchand the --on-demandoption:

可能在此补丁--on-demand选项之后完成:

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 checkis 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-demandis 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.

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

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

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 allits submodules.

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

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)

请参阅Mike Crowe ( ) 的commit d34141ccommit f5c7cd9(2015 年 12 月 3 日)、f5c7cd9 提交(2015 年 12 月 3 日)和b33a15b(2015 年 11 月 17 日(由Junio C Hamano合并-- --提交 5d35d72 中,2015 年 12 月 21 日)mikecrowe
gitster

push: add recurseSubmodulesconfig option

The --recurse-submodulescommand 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.recurseSubmodulesto provide a default for this parameter.
This also requires the addition of --recurse-submodules=noto allow the configuration to be overridden on the command line when required.

The most straightforward way to implement this appears to be to make pushuse code in submodule-configin a similar way to fetch.

push: 添加recurseSubmodules配置选项

--recurse-submodules命令行参数已存在一段时间,但它没有配置文件等同。

遵循 for 对应参数的样式git fetch,让我们发明push.recurseSubmodules为这个参数提供一个默认值。
这还需要添加--recurse-submodules=no以允许在需要时在命令行上覆盖配置。

实现这看似最简单的方法是,使 push利用代码submodule-config以类似的方式fetch

The git configdoc now include:

git config文档现在包括

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'.

push.recurseSubmodules

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

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

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

So:

所以:

git config push.recurseSubmodules on-demand
git push


Git 2.12 (Q1 2017)

Git 2.12(2017 年第一季度)

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

git push --dry-run --recurse-submodules=on-demand实际上会起作用。

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

参见布兰登·威廉姆斯 ( ) 的commit 0301c82commit 1aa7365(2016 年 11 月 17 日)(由Junio C Hamano合并-- --commit 12cf113,2016 年 12 月 16 日)mbrandonw
gitster

push run with --dry-rundoesn'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 pushto respect the --dry-runoption when configured to recursively push submodules 'on-demand'.
This is done by passing the --dry-runflag to the child process which performs a push for a submodules when performing a dry-run.

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

当配置为“按需”递归推送子模块时,教导push尊重该--dry-run选项。
这是通过将--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.

仍然在 Git 2.12 中,您现在有一个 " --recurse-submodules=only" 选项,可以在不推送顶级 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)

请参阅Brandon Williams ( ) 的commit 225e8bfcommit 6c656c3commit 14c01bd(2016 年 12 月 19 日(由Junio C Hamano合并-- --commit 792e22e,2017 年 1 月 31 日)mbrandonw
gitster