【问题标题】:Run a husky git hook manually (without triggering it w/git command)手动运行一个 husky git 钩子(不使用 git 命令触发它)
【发布时间】:2020-03-11 01:34:59
【问题描述】:

我正在使用husky 设置一个节点项目,我希望手动运行一个 git-hook 脚本,而不必在 git 中触发它。

例子:

我的 package.json 有以下内容:

{
...
    "scripts": {
        "precommit": // something goes here
    }
...
    "husky": {
        "hooks": {
            "pre-commit": "lint-staged"
        }
    },
...
}

如果我运行npm run precommitlint-staged 钩子步骤运行,没有实际发生在 git 中的提交。

这可能吗?

【问题讨论】:

  • 只需调用lint-staged 命令,"precommit": "lint-staged"
  • 那没用,但@VonC 的回答确实有效 (bash .git/hooks/pre-commit)

标签: javascript git githooks husky


【解决方案1】:

应该可以,因为this answer 说明您可以简单地调用.git/hooks/pre-commit

因此,只要您使用完整路径直接调用钩子,您就可以运行它包含的任何内容。

【讨论】:

  • 谢谢先生。我以为我梳理了SO,但错过了那个。 ://
  • @n8jadams 没问题。从一开始我就一直在梳理 SO。
  • 老实说,我觉得哈士奇应该有一个捷径,就像pre-commit一样。
猜你喜欢
  • 2021-03-12
  • 1970-01-01
  • 1970-01-01
  • 2018-03-25
  • 2022-08-19
  • 1970-01-01
  • 2020-02-08
  • 2015-07-18
  • 1970-01-01
相关资源
最近更新 更多