Git递归地将遥控器添加到子模块 [英] Git add remotes to submodules recursively

查看:65
本文介绍了Git递归地将遥控器添加到子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算机上的/path/to/repo上有一个git repo,其中包含几个子模块/path/to/repo/submoduleA/path/to/repo/foo/bar/submoduleB.

I have a git repo located on my machine at /path/to/repo, which contains several submodules, /path/to/repo/submoduleA and /path/to/repo/foo/bar/submoduleB.

由于我无法更改工作流程,因此git repo被复制(如在scp -r中一样)复制到远程服务器上,我在该服务器上处理代码.我想将所做的更改拉回到原始计算机上.不能从远程服务器进行克隆/推送.

Due to a workflow that I cannot change, the git repo gets copied (as in scp -r) to a remote server, where I work on the code. I want to pull the changes back to the original machine. Cloning/pushing from the remote server isn't an option.

转到每个子模块并执行

git remote add <name> <url>:/server/path/to/repo/<path to submodule>

有更快的方法吗?神奇的东西

Is there a faster way? Something magical like

git remote add --submodules <name> <url>:/server/path/to/repo

会递归到每个子模块,并将适当的相对路径添加到每个子模块的远程位置? git remote --help没有显示任何有用的内容,并且 Git专业版书子模块部分.

executed from the top-level repo that will recurse to each submodule and add the appropriate relative path onto the remote of each submodule? git remote --help doesn't show anything useful, and neither the Git Pro Book section on submodules.

我最好的猜测是

git submodule foreach 'git remote add <name> <url>:/server/path/to/repo/...'

可能会起作用.我只是不知道git submodule foreach

might work, if there there is a way to replace the ... with the loop-dependent relative path of each submodule in that foreach. I just don't know of such a mechanism built into git submodule foreach

推荐答案

git submodule foreach does include a list of variables which should help:

该命令可以访问变量:

The command has access to the variables:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆