17

在工作中,我们在 HTTP 代理后面,并且 git 协议(端口 9418)被拒绝。我的项目具有 NPM 依赖项,其中一些依赖项具有使用 git 协议的依赖项,例如:

在我的package.json

"dependencies": {
    "jsdoc3" : "git+https://github.com/jsdoc3/jsdoc.git"
}

package.jsonjsdoc3 的:

"dependencies": {
    "crypto-browserify": "git://github.com/dominictarr/crypto-browserify.git#95c5d505",
    "github-flavored-markdown": "git://github.com/hegemonic/github-flavored-markdown.git"
}

我怎样才能获得这些依赖关系,如何告诉 NPM 使用git+https://协议而不是git://协议或能够使用 git 协议?

为了简化我在 Windows 上的操作(在 Linux 上创建 SSH 隧道会更容易),我使用 GIT-Bash。

谢谢

4

6 回答 6

36

您可以使用以下命令告诉 git 使用 https 而不是 git://:

git config --global url."https://".insteadOf git://
于 2013-10-31T15:05:34.457 回答
5

最后我找到了一个肮脏的解决方案,但效果很好。我已经修改了 NPM 的代码,用协议替换了git协议http(感谢开源)

npm v1.1.69 上,在文件npm/lib/cache.js中,我在函数中添加了以下几行addRemoteGit

 // ssh paths that are scp-style urls don't need the ssh://
 if (parsed.pathname.match(/^\/?:/)) {
   u = u.replace(/^ssh:\/\//, "")
 }

 //begin trick
 if(/^git:/.test(u)){
     u = u.replace(/^git/, 'https');
 }
 //end trick

 log.verbose("addRemoteGit", [u, co])
于 2013-02-19T11:03:40.090 回答
3

npm wiki 中建议了两个 git 命令(参考:npm 仅默认使用 git:// 和 ssh+git://)。

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
于 2015-06-05T14:29:35.277 回答
1

可以在您的依赖 URL中指定 git+https://git+http://

我从以下 package.json

{
  "name": "Sample package",
  "description": "Pacake for a Stackoverflow question",
  "author": "rk <rk@example.sampletld>",
  "dependencies": {
    "crypto-browserify": "git+https://github.com/dominictarr/crypto-browserify.git#95c5d505",
    "github-flavored-markdown": "git+https://github.com/hegemonic/github-flavored-markdown.git"
  },
  "engine": "node 0.4.1"
}

然后我跑了npm install,其中node_modules包含以下内容

C:\Users\myself\node\node_modules>dir
 Volume in drive C is WINDOWS
 Volume Serial Number is 6E7A-96BE

 Directory of C:\Users\myself\node\node_modules

18/02/2013  13:57    <DIR>          .
18/02/2013  13:57    <DIR>          ..
18/02/2013  13:58    <DIR>          .bin
18/02/2013  13:57    <DIR>          crypto-browserify
18/02/2013  13:56    <DIR>          express
18/02/2013  13:57    <DIR>          github-flavored-markdown
18/02/2013  13:56    <DIR>          optimist
               0 File(s)              0 bytes
               7 Dir(s)  31,641,919,488 bytes free

C:\Users\myself\node\node_modules>

我用 git+http 和 git+https 两种协议都试过了,两者都有效,但裸 http 无法工作,产生错误。

于 2013-02-18T14:11:35.763 回答
1

除了@Nowres 建议之外,我还必须执行以下操作才能使其正常工作

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
于 2015-03-23T14:32:56.433 回答
1

npm ci一直在尝试使用ssh://,所以我不得不做以下事情:

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf ssh://
于 2021-02-10T10:58:44.563 回答