哪个是更智能的 git 协议,ssh 或 git(通过 ssh)或 https 协议?

发布于 2024-09-09 11:34:48 字数 1269 浏览 4 评论 0原文

哪个高效? SSH:// 或 Git:// (文件压缩)

我在 Git 中的理解是,git 协议很智能,因为通信两端都有协议代理来压缩文件传输,从而通过有效地使用网络带宽来实现更快的克隆。

一本 O'Reilly 的书中,我发现了以下陈述。

For secure, authenticated connections, the Git native 
protocol can be tunneled over an SSH connection using
the following URL templates:

ssh: //[user@]example.com[:port]/path/to/repo.git
ssh: //[user@]example.com/path/to/repo.git
ssh: //[user@]example.com/~user2/path/to/repo.git
ssh: //[user@]example.com/~/path/to/repo.git*

我不确定作者所说的是否是真的。他谈到 git 协议通过 SSH 建立隧道。

从我的角度来看,除非连接到 git 端口(代理端口),否则该协议不会生效。而SSH只是一种未压缩的文件传输。但根据作者的说法,如果我们使用 SSH,他说 git 协议是通过它建立隧道的。那么 SSH 在 GIT 中是否更智能呢?

冯·C, 感谢您的回答。 “网络协议(HTTP 和 Git)通常是只读的” 当您使用 --enable=receive-pack 运行守护程序时,可以使 Git 成为 rw

以下是我的担忧。
当他们说 git 协议很智能时,他们的意思是当您执行 git clone 时,Git 服务器代理会压缩发送回客户端的数据,因此克隆应该更快。在我的用例中,我将在香港设置 Git 服务器,并在圣何塞和其他国家/地区使用它,因此,由于延迟问题,我希望通过网络提高效率。

所以我的问题是,当我使用 git clone ssh://user@server/reposloc 时,我是否也能获得 git 协议的好处?根据 O'Reilly 作者的书,他的意思是 git 通过 ssh 建立隧道,那么当我没有在服务器上运行 git 守护进程时,git 协议如何工作。

那么使用 SSh://xyz...它是否同时具有 ssh 和 git 协议的优点?

提前感谢您的回答。

Which is efficient? SSH:// or Git:// (File compression)

I understand in Git, git protocol is smart because there is a protocol agent on both ends of communication to compress the file transfer resulting in faster clone by efficiently using the network bandwidth.

From an O'Reilly book I found the following statements.

For secure, authenticated connections, the Git native 
protocol can be tunneled over an SSH connection using
the following URL templates:

ssh: //[user@]example.com[:port]/path/to/repo.git
ssh: //[user@]example.com/path/to/repo.git
ssh: //[user@]example.com/~user2/path/to/repo.git
ssh: //[user@]example.com/~/path/to/repo.git*

I'm not sure if the author means what he says. He talks of git protocol getting tunneled over SSH.

From my perspective, unless you connect to the git port (agent port), the protocol is not in effect. And SSH is merely an uncompressed file transfer. But as per the author, if we use SSH he says the git protocol is tunneled over it. So is SSH smarter in GIT?

Von C,
Thanks for your answer. "Network protocols (HTTP and Git) are generally read-only" Git can be made rw when you run the daemon with --enable=receive-pack.

Following are my concerns.
When they say git protocol is smart, they mean when you execute git clone, Git server agent compresses the data that is sent back to the client, so the clone should be faster. In my use case I'll be setting the Git server in Hongkong and using it on San Jose and other countries as well, So I want to be efficient over network due to latency concerns.

So my question is when I use git clone ssh://user@server/reposloc do I get the benefits of git protocol also? As per O'Reilly author book he means git is tunneled over ssh, then how does git protocol work when I don't have git daemon running on the server.

So using SSh://xyz... does it give both the benefit of ssh and git protocols?

Appreciate your answers in advance.

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

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

发布评论

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

评论(7

一江春梦 2024-09-16 11:34:48

2010-2014 更新:

自从 Git 1.6.6+ (2010) 和 智能 http 的实现以来,ssh 和 https 是等效的协议

smart http

您现在可以使用 ssh 或 https 来读/写访问您的回购协议。
您还可以检测您的远程服务器是否支持智能http
如果必须使用代理,请添加正确的环境变量。

2015 年第 3 季度,Yousha Aleayoub 提到评论中

GitHub "我应该使用哪个远程 URL?"

https:// 克隆 URL 可在所有存储库(公共和私有)上使用。
它们很聪明,因此会根据您对存储库的权限为您提供只读或读/写访问权限。

git-http-backend 是:

简单的 CGI 程序,用于将 Git 存储库的内容提供给通过 http://https:// 协议访问存储库的 Git 客户端。
该程序支持使用智能HTTP协议和向后兼容的哑HTTP协议的客户端获取,以及使用智能HTTP协议的客户端推送。


原始答案(2010 年 7 月):

来自 Pro Git Book

Git 最常见的传输协议可能是 SSH。
这是因为大多数地方都已经设置了对服务器的 SSH 访问 — 如果没有设置,也很容易做到。

SSH 也是唯一可以轻松读取和写入的基于网络的协议。其他两个网络协议(HTTP 和 Git)通常是只读的,因此即使您将它们提供给普通大众,您仍然需要 SSH 来执行自己的写入命令。

SSH也是一种经过身份验证的网络协议;由于它无处不在,因此通常很容易设置和使用。

所以它并不比 Git 协议“更智能”,只是对 Git 协议未解决的某些功能的补充协议。

Git 协议的缺点是缺乏身份验证。通常不希望 Git 协议成为项目的唯一访问方式。
一般来说,您会将其与 SSH 访问配对,供少数具有推送(写入)访问权限的开发人员使用,并让其他人使用 git:// 进行只读访问

它还需要防火墙访问端口 9418,这不是企业防火墙始终允许的标准端口。在大型公司防火墙后面,这个不起眼的端口通常被阻止。

(这就是为什么在我的商店中,我需要使用 ssh+git 而不仅仅是 git,即使是读取访问:9418 阻止...)

Update 2010-2014:

Both ssh and https are equivalent, since Git 1.6.6+ (2010) and the implementation of smart http protocol:

smart http

You now can use ssh or https for read/write access to your repos.
You can also detect if your remote server supports smart http.
Add the right environment variable if you have to use a proxy.

Q3 2015, as Yousha Aleayoub mentions in the comments:

GitHub "Which remote URL should I use?"

The https:// clone URLs are available on all repositories, public and private.
They are smart, so they will provide you with either read-only or read/write access, depending on your permissions to the repository.

The git-http-backend is the:

simple CGI program to serve the contents of a Git repository to Git clients accessing the repository over http:// and https:// protocols.
The program supports clients fetching using both the smart HTTP protocol and the backwards-compatible dumb HTTP protocol, as well as clients pushing using the smart HTTP protocol.


Original answer (July 2010):

From the Pro Git Book:

Probably the most common transport protocol for Git is SSH.
This is because SSH access to servers is already set up in most places — and if it isn’t, it’s easy to do.

SSH is also the only network-based protocol that you can easily read from and write to. The other two network protocols (HTTP and Git) are generally read-only, so even if you have them available for the unwashed masses, you still need SSH for your own write commands.

SSH is also an authenticated network protocol; and because it’s ubiquitous, it’s generally easy to set up and use.

So it is not "smarter" than Git protocol, just a complementary protocol for certain features not addressed by the Git protocol.

The downside of the Git protocol is the lack of authentication. It’s generally undesirable for the Git protocol to be the only access to your project.
Generally, you’ll pair it with SSH access for the few developers who have push (write) access and have everyone else use git:// for read-only access

It also requires firewall access to port 9418, which isn’t a standard port that corporate firewalls always allow. Behind big corporate firewalls, this obscure port is commonly blocked.

(that is why in my shop, I need to use ssh+git and not just git, even for read access: 9418 is blocked...)

二货你真萌 2024-09-16 11:34:48

看看此页面的第二部分

唯一的“ “dumb”协议是直接的 HTTP,不需要在服务器上做任何特殊的工作。在 git:// 和 ssh:// 协议中,都会在与运行 git 的客户端进行通信的服务器上分叉一个 git upload-pack 进程(不是守护进程)获取包。在 ssh:// 和 git:// 中,您可以获得“智能”通信。

Take a look at the second part of this page

The only "dumb" protocol is straight HTTP, which requires no special effort on the server. In both the git:// and ssh:// protocols, a git upload-pack process (which is not a daemon) is forked on the server that communicates with the client who's running git fetch-pack. In both ssh:// and git://, you get "smart" communication.

难以启齿的温柔 2024-09-16 11:34:48

(我想在@erjian的回答中添加评论,但我不允许,因为我没有足够的StackOverflow声誉。)

看来从Git 1.6.6开始,HTTP不再是“哑巴”了。来自 Git 网站的博客

然而,自去年年底(2009年)发布1.6.6版本以来,
Git 现在可以像 git 一样高效地使用 HTTP 协议
或 ssh 版本

(I wanted to add a comment to @erjiang answer, but I'm not allowed because I don't have enough StackOverflow reputation.)

It seems that since Git 1.6.6, HTTP is not "dumb" anymore. From Git website's blog:

As of the release of version 1.6.6 at the end of last year (2009), however,
Git can now use the HTTP protocol just about as efficiently as the git
or ssh versions

慈悲佛祖 2024-09-16 11:34:48

当您通过 ssh 访问 git 时,它只是通过 ssh 隧道传输 git 协议,这样更容易设置且更安全,这是访问远程存储库的首选方式。

这实际上比裸 git 协议“更智能”,因为它可以通过 ssh 机制强制执行用户身份验证。无论传输层如何,git 都会完成所有压缩以及不在客户端上进行的压缩,并在服务器上对其进行解压缩。

“git”服务器不会这样做,所有这一切在使用 ssh 时也会发生。如果您希望能够写入远程存储库,则应避免使用 git 服务器。如果你想只读访问 git 或 HTTP 传输是“OK”,但如果你有开发人员需要写入存储库,你应该使用 ssh。为 git 服务器设置隧道只会增加复杂性和配置,这会很脆弱并且不会给你带来任何好处。

When you access git over ssh it just tunnels the git protocol over ssh, way easier to set up and way more secure, this the preferred way to access remote repositories.

This is actually "smarter" than the bare git protocol, because it can enforce user authentication via ssh mechanisms. git does all the compressing and what not on the client regardless of the transport layer, and it decompresses it on the server.

The "git" server doesn't do this, all this happens when using ssh as well. the git server should be avoided if you want to be able to write to the remote repository. if you want read only access git or HTTP transports are "OK", but if you have developers that need to write to the respository you should just use ssh. Setting up tunnels for the git server is just adding to complexity and configuration that will be brittle and gain you nothing.

策马西风 2024-09-16 11:34:48

来自维基百科

要建立 SSH 隧道,需要配置 SSH 客户端将指定的本地端口转发到
远程计算机上的端口。 SSH 隧道建立后,用户可以
连接到指定的本地端口来访问网络服务。本地端口不需要
与远程端口具有相同的端口号。

如果您需要某种 ASCII 艺术表示形式:

Git Data ---> [SSH encrypts data] ----- Internet -----> [SSH decrypts data] ----> Git Data

From Wikipedia:

To set up an SSH tunnel, one configures an SSH client to forward a specified local port to
a port on the remote machine. Once the SSH tunnel has been established, the user can
connect to the specified local port to access the network service. The local port need not
have the same port number as the remote port.

If you need some kind of ASCII art representation:

Git Data ---> [SSH encrypts data] ----- Internet -----> [SSH decrypts data] ----> Git Data
请叫√我孤独 2024-09-16 11:34:48

各种协议处于不同的级别(例如 ISO 7 层模型),因此您可以同时拥有两者,就像您可以通过有线或无线或光纤进行连接一样。

The various protocols are at different levels (e.g. the ISO 7 layer model), so you can have both, just as you could be connected by Wires or Wirelessly, or fibre.

世界如花海般美丽 2024-09-16 11:34:48

在 git 克隆期间快速搜索包文件将列出从服务器发送到客户端的单个包文件。包文件列在 .git/objects/pack/pack-XXXX.pack 下。从服务器发送到客户端的文件首先被打包、压缩。然后是打包内容的单个副本。在服务器端使用 lsof -p 与客户端使用 lsof -p 比较打包文件时可以看出这一点。在示例案例中,200MB的文件从服务器上传到客户端......

1) Server side 
   lsof -p 8079 | grep pack
   git-uploa 8079  REG  253,2 277896169 5140075 /home/server/work/work0617/.git/objects/pack/pack-492945ae602a975d46df133f6ded9642146fb6a7.pack
   git-uploa 8079  REG  253,2   1703472 5140076 /home/server/work/work0617/.git/objects/pack/pack-492945ae602a975d46df133f6ded9642146fb6a7.idx
   git-uploa 8079  REG  253,2 277896169 5140075 /home/server/work/work0617/.git/objects/pack/pack-492945ae602a975d46df133f6ded9642146fb6a7.pack

2) Client side
   lsof -p 3140 | grep pack
   git     3140  3u   REG    8,1 101031935 3681610 /home/client/work/work0617/work0617/.git/objects/pack/tmp_pack_pRfYPa

 3) The server side pack file 277MB. The file on the client side is 101MB and growing. So a single compressed file is copied over.

A quick search of the pack files during a git clone will list a single pack file that is sent from the server to the client. The pack file is listed under .git/objects/pack/pack-XXXX.pack. The files to be sent from the server to the client are first packed, compressed. Then there is a single copy of the packed contents. This can be seen when comparing the packed files using lsof -p on the server side and lsof -p on the client side. In the sample case a 200MB files is uploaded from the server to the client....

1) Server side 
   lsof -p 8079 | grep pack
   git-uploa 8079  REG  253,2 277896169 5140075 /home/server/work/work0617/.git/objects/pack/pack-492945ae602a975d46df133f6ded9642146fb6a7.pack
   git-uploa 8079  REG  253,2   1703472 5140076 /home/server/work/work0617/.git/objects/pack/pack-492945ae602a975d46df133f6ded9642146fb6a7.idx
   git-uploa 8079  REG  253,2 277896169 5140075 /home/server/work/work0617/.git/objects/pack/pack-492945ae602a975d46df133f6ded9642146fb6a7.pack

2) Client side
   lsof -p 3140 | grep pack
   git     3140  3u   REG    8,1 101031935 3681610 /home/client/work/work0617/work0617/.git/objects/pack/tmp_pack_pRfYPa

 3) The server side pack file 277MB. The file on the client side is 101MB and growing. So a single compressed file is copied over.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文