git 子模块 foreach 不工作

发布于 2024-12-25 16:45:49 字数 397 浏览 0 评论 0原文

我想弄清楚为什么 git submodule foreach 命令对我不起作用。我克隆了一个 git 存储库,它有几个子模块。我想立即初始化并更新所有子模块以获取子模块源。但是无论我尝试 git submodule foreach 都不适合我...我尝试了几件事:

git submodule foreach init
git submodule foreach update
git submodule foreach update --init
git submodule foreach --recursive git submodule update --init

每个命令都会执行但没有任何输出...如果我单独初始化/更新每个模块(不使用 foreach)那么就没问题。

有什么想法吗?

I want to figure out why git submodule foreach command is not working for me. I have cloned a git repository which has several submodules. I wanted to init and update all submodules at once to pull down the submodules sources. But whatever I try git submodule foreach is not working for me... I tried several things:

git submodule foreach init
git submodule foreach update
git submodule foreach update --init
git submodule foreach --recursive git submodule update --init

Every command will execute but without any output... If I go and init/update each module separately (without using foreach) then no problem.

Any ideas?

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

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

发布评论

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

评论(3

纸伞微斜 2025-01-01 16:45:49

git submodule initgit submodule update 应该适用于 .gitmodules 中注册的所有子模块,所以它不为每个子模块执行它们是没有意义的。

如果子模块中有子模块,git submodule update --recursive 将递归地处理所有子模块。

git submodule init or git submodule update are supposed to work for all submodules registered in .gitmodules, so it doesn't make sense to execute them for each submodules.

If you had submodules within submodules, git submodule update --recursive would take care of all submodules recursively.

一梦等七年七年为一梦 2025-01-01 16:45:49

克隆后,您通常需要做的就是:

git submodule update --init --recursive

最初完成此操作后,删除 --init 选项。

init 选项是将 .gitmodules 文件中指定的 url 复制到子模块存储库配置中的命令的一部分。如果您正在使用选择的特定遥控器并且项目已转移到您不想使用的遥控器,您可能不想执行此操作。一种典型的情况是,当您更愿意使用 GitHub 上的项目分支并且顶级存储库指向主存储库时。

After a clone all you usually need to do is:

git submodule update --init --recursive

After this is done initially, you drop the --init option.

The init option is the part of the command that copies the url specified in the .gitmodules file down into the submodule repo configuration. You may not want to do this if you are using a particular remote of choice and the project has move to one you don't want to use. A typical case of this is when you would rather use your fork of a project on GitHub and the top level repo points to the main one.

萌吟 2025-01-01 16:45:49

你必须运行:

git submodule init
git submodule update

--

你需要在树的根部有一个 .gitmodules 文件,它看起来像这样。

[submodule "LiveReload/Compilers"]
        path = LiveReload/Compilers
        url = git://github.com/livereload/livereload-plugins.git
[submodule "Shared/libs/fsmonitor"]
        path = Shared/libs/fsmonitor
        url = git://github.com/andreyvit/fsmonitor.c.git
[submodule "js"]
        path = js
        url = git://github.com/livereload/livereload-js.git

根据上述内容,输出应如下所示:

Nicks-MacBook:LiveReload2 admin$ git submodule init
Submodule 'LiveReload/Compilers' (git://github.com/livereload/livereload-plugins.git) registered for path 'LiveReload/Compilers'
Submodule 'Shared/libs/fsmonitor' (git://github.com/andreyvit/fsmonitor.c.git) registered for path 'Shared/libs/fsmonitor'
Submodule 'js' (git://github.com/livereload/livereload-js.git) registered for path 'js'
Nicks-MacBook:LiveReload2 admin$ git submodule update
Cloning into 'LiveReload/Compilers'...
remote: Counting objects: 7571, done.
remote: Compressing objects: 100% (5446/5446), done.
remote: Total 7571 (delta 2326), reused 6733 (delta 1488)
Receiving objects: 100% (7571/7571), 7.80 MiB | 2.73 MiB/s, done.
Resolving deltas: 100% (2326/2326), done.
Submodule path 'LiveReload/Compilers': checked out 'd770710edc2362caf4ed9adf303da1edc9e6e494'
Cloning into 'Shared/libs/fsmonitor'...
remote: Counting objects: 132, done.
remote: Compressing objects: 100% (79/79), done.
remote: Total 132 (delta 73), reused 112 (delta 53)
Receiving objects: 100% (132/132), 23.29 KiB, done.
Resolving deltas: 100% (73/73), done.
Submodule path 'Shared/libs/fsmonitor': checked out '1290027aea3a8e3f7fe06e3c228a16240c0fc17f'
Cloning into 'js'...
remote: Counting objects: 745, done.
remote: Compressing objects: 100% (413/413), done.
remote: Total 745 (delta 301), reused 703 (delta 259)
Receiving objects: 100% (745/745), 864.22 KiB | 820 KiB/s, done.
Resolving deltas: 100% (301/301), done.
Submodule path 'js': checked out '6aa86b01479c3aad785e9623f39cfcde2b8615f

You have to run:

git submodule init
git submodule update

--

You need a .gitmodules file at the root fo your tree, it looks like this.

[submodule "LiveReload/Compilers"]
        path = LiveReload/Compilers
        url = git://github.com/livereload/livereload-plugins.git
[submodule "Shared/libs/fsmonitor"]
        path = Shared/libs/fsmonitor
        url = git://github.com/andreyvit/fsmonitor.c.git
[submodule "js"]
        path = js
        url = git://github.com/livereload/livereload-js.git

Here's how the output should look based on the above:

Nicks-MacBook:LiveReload2 admin$ git submodule init
Submodule 'LiveReload/Compilers' (git://github.com/livereload/livereload-plugins.git) registered for path 'LiveReload/Compilers'
Submodule 'Shared/libs/fsmonitor' (git://github.com/andreyvit/fsmonitor.c.git) registered for path 'Shared/libs/fsmonitor'
Submodule 'js' (git://github.com/livereload/livereload-js.git) registered for path 'js'
Nicks-MacBook:LiveReload2 admin$ git submodule update
Cloning into 'LiveReload/Compilers'...
remote: Counting objects: 7571, done.
remote: Compressing objects: 100% (5446/5446), done.
remote: Total 7571 (delta 2326), reused 6733 (delta 1488)
Receiving objects: 100% (7571/7571), 7.80 MiB | 2.73 MiB/s, done.
Resolving deltas: 100% (2326/2326), done.
Submodule path 'LiveReload/Compilers': checked out 'd770710edc2362caf4ed9adf303da1edc9e6e494'
Cloning into 'Shared/libs/fsmonitor'...
remote: Counting objects: 132, done.
remote: Compressing objects: 100% (79/79), done.
remote: Total 132 (delta 73), reused 112 (delta 53)
Receiving objects: 100% (132/132), 23.29 KiB, done.
Resolving deltas: 100% (73/73), done.
Submodule path 'Shared/libs/fsmonitor': checked out '1290027aea3a8e3f7fe06e3c228a16240c0fc17f'
Cloning into 'js'...
remote: Counting objects: 745, done.
remote: Compressing objects: 100% (413/413), done.
remote: Total 745 (delta 301), reused 703 (delta 259)
Receiving objects: 100% (745/745), 864.22 KiB | 820 KiB/s, done.
Resolving deltas: 100% (301/301), done.
Submodule path 'js': checked out '6aa86b01479c3aad785e9623f39cfcde2b8615f
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文