Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update the version in package.json without clean git working directory (without a task runner like Gulp)

Tags:

npm

When running a: npm version prepatch I get the error: "Git working directory not clean." And then a list of files that aren't committed yet.

However, I'd like to do this prerelease to test some stuff locally using a private npm registry. Meaning that I don't have to commit the files just yet using Git.

Is it possible to update the version in package.json without clean git working directory?

like image 740
Remi Avatar asked Aug 29 '18 10:08

Remi


People also ask

What is npm version command?

Synopsis. npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git] 'npm [-v | --version]' to print npm version. 'npm view <pkg> version' to view a package's published version. 'npm ls' to inspect current package/dependency versions.

What means package JSON?

The package. json file is the heart of any Node project. It records important metadata about a project which is required before publishing to NPM, and also defines functional attributes of a project that npm uses to install dependencies, run scripts, and identify the entry point to our package.


2 Answers

From the npm version documentation at https://docs.npmjs.com/cli/version:

If run in a git repo, it will also create a version commit and tag. This behavior is controlled by git-tag-version (see below), and can be disabled on the command line by running npm --no-git-tag-version version. It will fail if the working directory is not clean, unless the -f or --force flag is set.

I'm not 100% certain whether you just need --no-git-tag-version, or if you'll also need the --force flag.

like image 165
Phil Hayward Avatar answered Oct 20 '22 15:10

Phil Hayward


You can use git stash.

E.g.

git stash 
npm version patch 
git stash pop

This will reset your working directory temporarily (remove uncommitted changes). Then you can run npm version {major|minor|patch}. Afterwards, using git stash pop will re-apply your uncommitted changes to your working directory.

Tutorial: https://www.atlassian.com/git/tutorials/saving-changes/git-stash#stashing-your-work

like image 45
Learner Avatar answered Oct 20 '22 15:10

Learner