简体   繁体   English

从git获取npm包的不同协议

[英]Different protocols to get npm package from git

From the npm docs ( https://docs.npmjs.com/cli/install ) 从npm docs( https://docs.npmjs.com/cli/install

The following is not completely clear: 以下内容并不完全清楚:

npm install <git remote url>:

Installs the package from the hosted git provider, cloning it with git. First it tries via the https (git with github) and if that fails, via ssh.

    <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish>]

<protocol> is one of git, git+ssh, git+http, or git+https.

What is the differene between these 4 options (git, git+ssh, ...)? 这4个选项(git,git + ssh,...)之间的区别是什么?

For full details, read Git on the Server - The Protocols . 有关完整的详细信息,请阅读服务器上的Git-协议

All of the protocols negotiate the file transfers you need to clone/pull/push a repository; 所有协议都会协商克隆/拉动/推送存储库所需的文件传输; they differ mostly in their authentication mechanism. 它们的主要区别在于身份验证机制。

git

This talks directly to the daemon that comes packaged with Git - you can just spin it up and hand out a URL. 这直接与Git随附的守护程序对话-您可以将其旋转并发出URL。 It has no authentication on it, so you typically don't want to allow push over it (everyone with the URL could push), but that saves on overhead and makes it a good option for mass public distribution (like NPM). 它没有身份验证,因此您通常不想允许对其进行推送(每个拥有URL的人都可以推送),但是这样可以节省开销,并且使其成为进行大规模公共发行(如NPM)的不错的选择。

git+ssh

The same as git , just transported over SSH. git相同,只是通过SSH传输。 You have to have an SSH key set up with the server, but for the trouble you get authentication and encryption. 您必须在服务器上设置SSH密钥,但是由于麻烦,您需要进行身份验证和加密。

git+http

This comes in two modes, Dumb and Smart. 这有两种模式,哑和智能。

Dumb HTTP is basically the repository served by a standard web server, which is easy to set up, but can make for slow transfers because the client has to walk commits and request entire packfiles even if it only needs one object in the file. 哑HTTP基本上是由标准Web服务器提供的存储库,该存储库易于设置,但传输速度较慢,因为客户端必须走提交并请求整个packfile,即使它只需要文件中的一个对象。 Serving this way is read only because the web server can't receive files appropriately. 以这种方式提供服务是只读的,因为Web服务器无法正确接收文件。

Smart HTTP was introduced in 1.6.6 and lets the client request specific objects like it does with git and git+ssh . Smart HTTP 在1.6.6引入,使客户端可以像gitgit+ssh一样请求特定的对象。 The server can then make a custom packfile to send back, which is much more efficient. 然后,服务器可以制作一个自定义的packfile发送回去,这效率更高。 The smarter server can also now support pushes, though again you'll want to authenticate the user. 现在,更智能的服务器还可以支持推送,不过您仍然需要对用户进行身份验证。

git+https

The same as git+http , but over HTTPS, so you get authentication and encryption. git+http相同,但通过HTTPS进行,因此您可以进行身份​​验证和加密。 The nice thing over git+ssh is you can use a simple username and password instead of having to set up a key pair, which is easier for a lot of users. git+ssh是,您可以使用简单的用户名和密码,而不必设置密钥对,这对许多用户来说更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM