【问题标题】:Use of git tags in package.json (for git dependencies)在 package.json 中使用 git 标签(用于 git 依赖项)
【发布时间】:2016-05-15 17:04:50
【问题描述】:

是否有可能获得 git 依赖项的更新行为,就像 npm 包一样?

所以我有 git 依赖:

"dependencies": {
"my-module": "github:me/my-module"
}

并且希望每次我做npm install 时都更新它,添加修订哈希是解决方案,但每次在 github 上更新包时都需要做更多的工作来跟踪和更新 package.json 中的 i。

还有 git 标签(也可以使用 npm version.. 命令设置 - 它使用标签 v1.2.3 创建提交。所以我想也许这是在依赖 package.json 中使用此标签的方法?

希望我是清楚的。

repo 上的 git 标签给了我

v1.0.1 v1.0.0 ..

如果我尝试在模块名称版本之后添加 package.json,例如:#1.0.0 或 #v1.0.1

```
"dependencies": {
"my-module": "github:me/my-module#1.0.1"
}
```

安装失败并出现错误:

Command failed: git -c core.longpaths=true rev-list -n1 1.0.0
fatal: ambiguous argument '1.0.0': unknown revision or path not in the
ree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'


If you need help, you may report this error at:
    <https://github.com/npm/npm/issues>

...

【问题讨论】:

  • 如果git tag 为您提供v1.0.0 等值,那么您需要使用该确切值。使用1.0.0 会失败

标签: node.js git github npm


【解决方案1】:

我尝试使用 git+ssh 但没有用。最后,这对我在 bitbucket 中的 repo 有用

"my-module": "git+https://bitbucket.org/repos/myrepo/#0.1.0"

【讨论】:

    【解决方案2】:

    如果您正在寻找 git 依赖项的 semver 支持,恐怕您不走运。

    在安装 git 依赖项时,npm 允许您指定以下一项来控制您希望将哪些特定提交安装为依赖项:

    • 提交(提交的完整 sha1 字符串)
    • 提交(短提交字符串)
    • 分支
    • 标签

    格式定义如下:

    package.json:

    {
      "dependencies": {
        "some-dep": "username/reponame#commit-ish"
      }
    }
    

    其中commit-ish 是上面列出的项目之一。

    在指定 commit-ish 时尝试使用 semver 修饰符之一将失败,即。 #~1.2.3 不是有效的 commit-ishSee the docs for yourself.

    【讨论】:

      【解决方案3】:

      可以这样完成

      "my-module": "git+https://github.com/user/repo.git#v1.2.3"

      【讨论】:

      • 这确实有效,您确定将标签推送到 github 了吗? git push --follow-tags你的标签名正确吗?
      • 谢谢,但是没有像#^v1.0.0 这样的东西并自动更新补丁/次要版本?
      • 是的,很遗憾没有 semver 支持
      猜你喜欢
      • 2013-04-27
      • 2016-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2021-12-27
      相关资源
      最近更新 更多