Git 从现有存储库将子模块添加到超级项目

发布于 2024-09-19 22:25:20 字数 717 浏览 7 评论 0原文

我在一个目录中有几个(大约 10-15 个)Git 存储库:

~/plugins/admin
~/plugins/editor
~/plugins/etc

每个存储库都有自己独立的存储库和远程服务器。

问题是,要从所有存储库中提取所有更改,我必须:

cd ~/plugins/admin
git pull origin master
password: ********
cd ..

cd ~/plugins/editor
git pull origin master
password: ********
cd ..

cd ~/plugins/etc
git pull origin master
password: ********
cd ..

如何设置 Git 子模块以使用 1 个命令提取所有存储库,

或者为 Windows、Linux 和 Mac 编写一个脚本(因为我使用所有 3 个命令)操作系统)来有效地做同样的事情。请记住,存储库可以位于不同的分支上,并且不一定具有跟踪分支设置。

相同的注释:

  • 所有存储库的密码都是相同的
  • 远程服务器是相同的存储库(显然在单独的存储库/目录中)
  • 我只想输入一次密码
  • 我只想输入一个命令来提取所有存储库
  • 公钥/私钥不是
  • 我通过 ssh 连接到远程的选项

I have several (about 10-15) Git repositories in a directory:

~/plugins/admin
~/plugins/editor
~/plugins/etc

Each have their own separate repository and remote server.

The problem is that to pull all the changes from all the repositories I have to:

cd ~/plugins/admin
git pull origin master
password: ********
cd ..

cd ~/plugins/editor
git pull origin master
password: ********
cd ..

cd ~/plugins/etc
git pull origin master
password: ********
cd ..

How can I setup either Git submodules to pull all the repositories with 1 command,

OR alternatively write a script for Windows, Linux and Mac (as I use all 3 operating systems) to effectively do the same thing. Keeping in mind that the repos can be on different branches and don't necessarily have a tracking branch setup.

Same notes:

  • The password is the same for all repos
  • The remote server is the same repos (obviously in seperate repos/directories)
  • I only want to type the password in once
  • I only want to type one command to pull all repos
  • Public/private keys are not an option
  • I'm connecting to the remote via ssh

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

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

发布评论

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

评论(3

沙沙粒小 2024-09-26 22:25:20
bash-3.2$ git submodule add git@repoUrl:SubmoduleName.git existing/submodule/path
Adding existing repo at 'existing/submodule/path' to the index

当您尝试从某些 git 存储库已存在的位置添加子模块时,该存储库将添加到 index.html 中。

bash-3.2$ git submodule add git@repoUrl:SubmoduleName.git existing/submodule/path
Adding existing repo at 'existing/submodule/path' to the index

when you're trying to add submodule from place where some git repo already exists this repo will be added in index.

天赋异禀 2024-09-26 22:25:20

使用 Perl,就像 Git 一样。假设您有每个密码:

#!/usr/bin/perl

@dirs = ("admin", "editor", "etc" );
foreach(@dirs)
{
  chdir($_);
  exec( "git pull origin master" );
  chdir("..");
}

通过一些额外的改进,您可以添加更好的错误处理和一次读取密码,而不是每次。

Use Perl, just as Git does. Assuming you have the password for each:

#!/usr/bin/perl

@dirs = ("admin", "editor", "etc" );
foreach(@dirs)
{
  chdir($_);
  exec( "git pull origin master" );
  chdir("..");
}

With a little additional polish you could add better error handling and reading the password once, rather than each time.

云淡月浅 2024-09-26 22:25:20

(我知道这个问题很老了,但也许我的回答对某人有用。)

现在你可以使用 git submodule foreach 来完成这样的任务。

也许 git pull git pull --recurse-submodules=yes 也可以帮助你

(I know that this question very old, but maybe my reply will be useful for someone.)

Nowadays you can use git submodule foreach for such task.

And maybe git pull git pull --recurse-submodules=yes also can help you

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