Git clone from remote ssh repository - 在执行 clone 命令之前更改远程网络上的机器

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

Git clone from remote ssh repository - change the machine on the remote network before executing the clone command

gitproxysshgit-clone

提问by Deve

I'd like to clone a git repository from my company's servers to my personal computer. The only way to acces these servers from "outside" is by logging in per ssh to 'machine1'

我想将 git 存储库从我公司的服务器克隆到我的个人计算机。从“外部”访问这些服务器的唯一方法是通过 ssh 登录到“machine1”

ssh [email protected]

Unfortunately, git ist not installed on that specific machine. So a git clone like

不幸的是,该特定机器上并未安装 git。所以一个 git clone 就像

git clone ssh://[email protected]/path/to/repo <local-repo-path>

won't work. What I would have to do is to change to another machine 'machine2' where git is installed after having logged in to the network via 'machine1'. So to get the clone working I would have to execute a command like

不会工作。我必须做的是在通过“machine1”登录网络后,更改到另一台安装了 git 的机器“machine2”。所以为了让克隆工作,我必须执行一个命令

ssh machine2

before actually executing the git command. Is there any way to do that? Something like a pre-clone hook maybe?

在实际执行 git 命令之前。有没有办法做到这一点?像预克隆钩子之类的东西?

Is it possible to somehow pack the remote repository into a file (patch?), to copy that file onto the local machine and to clone from that file?

是否有可能以某种方式将远程存储库打包到一个文件(补丁?)中,将该文件复制到本地机器上并从该文件进行克隆?

Looking forward to your hints and suggestions!

期待您的指点和建议!

回答by bdonlan

You can do this by configuring a ssh proxy command. Note: this assumes netcatis available on the proxy server; you can replace netcat with a similar script in perl or whatever if needed.

您可以通过配置 ssh 代理命令来执行此操作。注意:这里假设netcat在代理服务器上可用;如果需要,您可以用 perl 中的类似脚本或任何其他脚本替换 netcat。

Add the following to your ~/.ssh/config, creating it if needed:

将以下内容添加到您的~/.ssh/config,根据需要创建它:

Host machine1
User yourusername
HostName machine1.yourcompany.com

Host machine2
User yourusername
ProxyCommand ssh machine1 nc %h %p
HostName machine2.internal.network

Now you can ssh machine2and it will automatically tunnel through machine1. This means using git is as simple as git clone ssh://machine2/path.

现在你可以了ssh machine2,它会自动通过 machine1 隧道。这意味着使用 git 就像git clone ssh://machine2/path.

It is also possible to bundle the repository into a single file, using the git bundlecommand. This shouldn't be necessary with a proper ssh proxy setup though.

也可以使用git bundle命令将存储库捆绑到单个文件中。但是,对于适当的 ssh 代理设置,这应该不是必需的。