递归 Git 推/拉?

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

Recursive Git push/pull?

gitrecursionpushpull

提问by David Y. Stephenson

I have a git repository that contains other git repositories. Are there commands that recursively push and/or pull for not only the meta-repository but the sub-repositories?

我有一个包含其他 git 存储库的 git 存储库。是否有不仅对元存储库而且对子存储库进行递归推送和/或拉取的命令?

采纳答案by mnagel

if you are talking about submodules, see cupcakes answer.

如果您在谈论子模块,请参阅纸杯蛋糕答案。

if you are talking about some folder hierarchy containing git repos, you can checkout clustergit, a tool i programmed: https://github.com/mnagel/clustergit

如果您正在谈论一些包含 git repos 的文件夹层次结构,您可以结帐clustergit,这是我编写的一个工具:https: //github.com/mnagel/clustergit

回答by vguerra

I find myself in the same situation whenever I want to update my llvm/clang repositories and with a bit of bash help I can 'git pull' each of them like this:

每当我想更新我的 llvm/clang 存储库时,我都会发现自己处于相同的情况,并且借助一些 bash 帮助,我可以像这样“git pull”每个存储库:

$> for dir in $(find . -name ".git"); do cd ${dir%/*}; git pull ; cd -; done

$> for dir in $(find . -name ".git"); do cd ${dir%/*}; git pull ; cd -; done

This will 'git pull' all git repos found under your current directory, and probably wont work if they are bare repositories.

这将“git pull”在您当前目录下找到的所有 git 存储库,如果它们是裸存储库,则可能无法工作。

回答by vguerra

Not quite git pull, but close:

不完全git pull,但接近:

git fetch --recurse-submodules

From the Git docs:

Git 文档

--recurse-submodules[=yes|on-demand|no]

This option controls if and under what conditions new commits of populated submodules should be fetched too. It can be used as a boolean option to completely disable recursion when set to no or to unconditionally recurse into all populated submodules when set to yes, which is the default when this option is used without any value. Use on-demand to only recurse into a populated submodule when the superproject retrieves a commit that updates the submodule's reference to a commit that isn't already in the local submodule clone.

--recurse-submodules[=yes|on-demand|no]

此选项控制是否以及在什么条件下也应该获取已填充子模块的新提交。它可以用作布尔选项,在设置为 no 时完全禁用递归,或者在设置为 yes 时无条件地递归到所有填充的子模块中,这是在没有任何值的情况下使用此选项时的默认值。仅当超级项目检索到将子模块的引用更新为不在本地子模块克隆中的提交时,按需使用仅递归到填充的子模块中。

回答by Dariusz Ostolski

I've just write a script to execute recursively on multiple git repositories. You can grab it from here:

我刚刚编写了一个脚本来在多个 git 存储库上递归执行。你可以从这里获取它:

https://github.com/DariuszOstolski/rgit

https://github.com/DariuszOstolski/rgit

The idea is exactly the same as in clustergit but implementation differs.

这个想法与 clustergit 中的完全相同,但实现不同。

回答by kenglxn

I needed this a while back and made a cli available through npm. https://github.com/kenglxn/gitr/blob/master/README.md

不久前我需要这个,并通过 npm 提供了一个 cli。https://github.com/kenglxn/gitr/blob/master/README.md

Just do "npm install -g gitr" and then you can do any git command recursively by using gitr.

只需执行“npm install -g gitr”,然后您就可以使用 gitr 递归地执行任何 git 命令。