npm version
commits the change to package.json and creates a tag. Is there a way to prevent commit hook from being executed while using this command?
5 Answers
Not sure why this functionality didn't exist in npm
before, but I contributed it a little while ago, as I needed it myself. It shipped with npm@5.4.0
. To use it, set the config option commit-hooks = false
in your .npmrc
and the underlying git
call will not run commit hooks when creating the version commit. If you only want to disable commit hooks on a single versioning, you can run something similar to:
npm version --no-commit-hooks minor
or alternatively:
npm version --commit-hooks false minor

- 475
- 3
- 6
-
1The docs say the flag is 'commit-hooks' and it takes a boolean. Might be worth updating the answer with the link, too: https://docs.npmjs.com/cli/version#commit-hooks. – loujaybee Mar 11 '19 at 17:22
-
3@loujaybee The way npm processes CLI flags allows interpreting boolean flags prefixed with `--no-` as equivalent to setting the flag to `false`. I chose to demonstrate that form for the sake of brevity. However I added an example to demonstrate that other command form for greater completeness. – faazshift Mar 11 '19 at 21:30
According to npm cli docs you can skip the generation of a git tag by using
npm --no-git-tag-version version

- 3,394
- 4
- 33
- 47
-
1Thank you. Docs doesn't really say "only"... Commit is one of the steps but the docs say nothing about controlling the commit behaviour. There may be some undocumented option or package.json configuration. – esp May 19 '17 at 19:27
-
This is the correct answer if you want to avoid touching `git` at all. With `--no-commit-hooks`, it complained when working directory wasn't clean. – Lewis Nov 13 '20 at 03:31
-
From the docs
commit-hooks
- Default: true
- Type: Boolean
Run git commit hooks when using the
npm version
command.
If you simply want to allow this one time run the follow
npm version --no-commit-hooks patch|minor|major
To control this permanently, run the following command
npm config set commit-hooks false
Or add this line to your .npmrc
file
commit-hooks=false

- 1,694
- 1
- 18
- 34
-
Using .npmrc file is the best bet. As humans we're great at forgetting to include special flags. – Robert May 08 '20 at 05:03
-
I tried all the above solutions, nothing worked for me.
the below command works well.
git commit -m "message" --no-verify

- 8,831
- 9
- 65
- 77
The following worked for me in a Git repo if you're looking for no tag and no commit but just the increment. (Replace patch with major or minor depending on your use case)
npm --no-git-tag-version version patch

- 11
- 1
- 1