19

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?

tanguy_k
  • 11,307
  • 6
  • 54
  • 58
esp
  • 7,314
  • 6
  • 49
  • 79

5 Answers5

24

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
faazshift
  • 475
  • 3
  • 6
  • 1
    The 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
13

According to npm cli docs you can skip the generation of a git tag by using

npm --no-git-tag-version version
Dethariel
  • 3,394
  • 4
  • 33
  • 47
  • 1
    Thank 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
  • This one worked for me, not the accepted answer. NPM v8.19.2 – Antonio Brandao Nov 14 '22 at 23:14
2

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

pcnate
  • 1,694
  • 1
  • 18
  • 34
2

I tried all the above solutions, nothing worked for me.

the below command works well.

git commit -m "message" --no-verify
Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
1

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
asvinp
  • 11
  • 1
  • 1