最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Run a husky git hook manually (without triggering it wgit command) - Stack Overflow

programmeradmin3浏览0评论

I'm setting up a node project with husky and I want to have a git-hook script run manually, without having to trigger it in git.

Example:

My package.json has the following:

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

If I run npm run precommit, the lint-staged hook step runs, WITHOUT the commit actually occurring in git.

Is this possible?

I'm setting up a node project with husky and I want to have a git-hook script run manually, without having to trigger it in git.

Example:

My package.json has the following:

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

If I run npm run precommit, the lint-staged hook step runs, WITHOUT the commit actually occurring in git.

Is this possible?

Share Improve this question asked Nov 14, 2019 at 23:03 n8jadamsn8jadams 1,1653 gold badges12 silver badges22 bronze badges 3
  • Just call lint-staged command, "precommit": "lint-staged" – hoangdv Commented Nov 15, 2019 at 8:53
  • That didn't work, but @VonC's answer did (bash .git/hooks/pre-commit) – n8jadams Commented Nov 15, 2019 at 16:00
  • npx lint-staged works for me. – tolkinski Commented May 7, 2024 at 19:27
Add a comment  | 

2 Answers 2

Reset to default 16

It should be possible, since this answer illustrates you can simply call the .git/hooks/pre-commit

So as long as you are calling the hook directly, with its full path, you would run whatever it contains.

If pre-commit is installed globally, you can just run this in the terminal:

pre-commit run --all-files
发布评论

评论列表(0)

  1. 暂无评论