简体   繁体   English

npm从私有gitlab安装git + ssh

[英]npm install git+ssh from private gitlab

I have a private Gitlab. 我有一个私人的Gitlab。 There I have a repo which I do git clone from this address: [git@10.15.8.210:8888]:recsystem/robotRecSystem.git 那里有一个我可以从此地址进行git克隆的[git@10.15.8.210:8888]:recsystem/robotRecSystem.git

Until node 7.2.1 (npm v3.10.10) I could install like this: 在节点7.2.1(npm v3.10.10)之前,我可以这样安装:

$ npm install git+ssh://[git@10.15.8.210:8888]:recsystem/robotRecSystem.git --save
src@0.0.0 /home/pauloh/src/recsystem-web/src
└── robotRecSystem@1.1.0  (git+ssh://[git@10.15.8.210:8888]:recsystem/robotRecSystem.git#b589aa1d17cb44d5c17e5fd69929a7a8b64c9eba)

But since node 8.9.0 (npm v5.5.1) when I get an error with the same command: 但是从节点8.9.0(npm v5.5.1)开始,当我使用同一命令遇到错误时:

$ npm install git+ssh://[git@10.15.8.210:8888]:recsystem/robotRecSystem.git --save
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://%5Bgit@10.15.8.210/:8888]:recsystem/robotRecSystem.git
npm ERR! 
npm ERR! ssh: Could not resolve hostname 10.15.8.210/: Name or service not known
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! 
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pauloh/.npm/_logs/2018-07-11T13_00_48_101Z-debug.log

Reading the error, npm fails when calling the command git ls-remote. 读取错误后,调用命令git ls-remote时npm失败。 It tryies this command: 它尝试以下命令:

/usr/bin/git ls-remote -h -t ssh://%5Bgit@10.15.8.210/:8888]:recsystem/robotRecSystem.git

It would work if I change this command to: 如果我将此命令更改为:

/usr/bin/git ls-remote -h -t [git@10.15.8.210:8888]:recsystem/robotRecSystem.git

So, I think the problems are: 因此,我认为问题是:

  • my url string [git@10.15.8.210:8888]:recsystem/robotRecSystem.git is not a normal url, since it is not a protocol://user@hostname:port/path 我的网址字符串[git@10.15.8.210:8888]:recsystem/robotRecSystem.git不是普通网址,因为它不是protocol://user@hostname:port/path
  • npm is not parsing correctly my url string. npm无法正确解析我的网址字符串。
  • npm is changing the character [ to %5B and it is not working npm正在将字符[更改为%5B ,但无法正常工作
  • npm is prefixing the protocol ssh:// and it is not working npm为协议ssh://加上前缀,并且不起作用

How could I change my url string to npm parse it correctly? 我如何将我的网址字符串更改为npm才能正确解析?

The brackets in npm install documentation ( https://docs.npmjs.com/cli/install ) npm install文档中的括号( https://docs.npmjs.com/cli/install

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

mean only that this part may not be used, not that you have to include the brackets... 意味着仅此部分可能不被使用,而不是您必须包括方括号...

Therefore, git+ssh://git@10.15.8.210:8888:recsystem/robotRecSystem.git seems to be what you are looking for. 因此, git+ssh://git@10.15.8.210:8888:recsystem/robotRecSystem.git似乎就是您想要的。

OR 要么

You can use the definition of GIT_SSH_COMMAND variable to set the port beforehand to eliminate possible problems with the colons: 您可以使用GIT_SSH_COMMAND变量的定义来预先设置端口,以消除冒号可能引起的问题:

GIT_SSH_COMMAND='ssh -p 8888' git+ssh://git@10.15.8.210:recsystem/robotRecSystem.git

OR even better 甚至更好

You may define the port in the .ssh/config as described in: https://www.digitalocean.com/community/tutorials/how-to-configure-custom-connection-options-for-your-ssh-client 您可以按照以下说明在.ssh/config定义端口: https : //www.digitalocean.com/community/tutorials/how-to-configure-custom-connection-options-for-your-ssh-client

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

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