【问题标题】:NPM - staged files not adding to commit with npm versionNPM - 暂存文件未添加到使用 npm 版本提交
【发布时间】:2022-01-20 17:59:42
【问题描述】:

目前正在尝试配置 npm,以便当我运行 npm version 时,它会在 package.json 中设置版本,然后将当前暂存的所有内容添加到其提交中,并且 npm 文档使它看起来像是可能的,但我不断收到错误消息,指出无法运行该命令,因为我的工作目录不干净。

理想情况下,我不想将-f 添加到我的npm version 命令中。

我的package.json

"scripts": {
    ...
    "nv": "node newversion.js", /*Creates a changelog and runs npm version*/
    "preversion": "git add -A",
    "version": "git add -A"
  }

npm version 1.4.1 -m "%s -> custom scrollbars"

->npm ERR! Git working directory not clean.

在运行 npm version 之前手动暂存也不起作用。

我有什么遗漏吗?我不是超级 npm- 或 package.json-knowledgeable 所以任何帮助将不胜感激。

最终,目标是能够运行 npm-version 并将任何内容暂存到工作目录中并将其添加到 npm-version 进行的提交中。

【问题讨论】:

    标签: git npm package.json npm-scripts


    【解决方案1】:

    另一种方法是使用package standard-version,它会生成更改日志并更新版本。

    参见 Indermohan Singh 的“Automatically generate and release a changelog using Node.js”(2021 年 7 月)(软件开发人员 Ubiq.ai | ragakosh.com 的创建者)

    npm run release
    

    运行上面的命令将在屏幕上显示以下消息:

    > changelog@1.0.0 release /home/imsingh/Develop/inder/changelog
    > standard-version
    
    ✔ bumping version in package.json from 1.0.0 to 1.1.0
    ✔ bumping version in package-lock.json from 1.0.0 to 1.1.0
    ✔ created CHANGELOG.md
    ✔ outputting changes to CHANGELOG.md
    ✔ committing package-lock.json and package.json and CHANGELOG.md
    ✔ tagging release v1.1.0
    ℹ Run `git push --follow-tags origin master && npm publish` to publish
    

    【讨论】:

    • 有什么办法可以让这个也将其他文件添加到提交中?我正在生成的更改日志是一个显示在应用程序中的 json 文件
    • @Wubzy 不在其当前实现中。但是没有什么能阻止你添加其他文件,然后调用这个库。
    • 很公平。感谢您的帮助!
    猜你喜欢
    • 2020-07-18
    • 2017-01-05
    • 2019-05-06
    • 2018-12-05
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    相关资源
    最近更新 更多