Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change package-lock.json package back to original repo version

Tags:

git

npm

I'm working on a git pull request for Mocha.

I'm running into an error related to my package-lock.json file in where I accidentally updated the package ansi-regex from 2.1.1 to 3.0.0

I'm now having issues getting this version back to it's original, which was requested by the repo owners.

The major issue I am encountering is that this npm package only exists within package-lock

 "ansi-regex": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
      "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg="
    },

it doesn't exist inside the main package.json file.

Through research, I've found that it's not suggested to delete the package-lock file and regenerate it with npm i because that could introduce even more changes.

I've also tried the command:

git checkout --theirs package-lock.json
git add package-lock.json 

But the version remains 3.0.0

I've also tried to run a

npm uninstall --save [email protected] -package-lock.json

To manually remove the file, but the command completes without removing any packages.

I'm not sure how to get this version back to the one setup by the repo owners and could really use some help figuring out next steps.

Thank you

like image 613
Dan Avatar asked Dec 10 '22 01:12

Dan


1 Answers

You need to find the ID of a commit before the one where you modified package-lock.json, and restore the content of package-lock.json from that commit.


Using the command line (open git-bash for example) :

  • You can view the list of commits that modified package-lock.json using :

    git log package-lock.json
    
  • You can set package-lock.json back to its version in commit [ID] using :

    git checkout [ID] -- package-lock.json
    

You can do the same actions from a graphical client, just be sure to select the file from the past commit and checkout only that file, rather than checkout the whole commit.

like image 63
LeGEC Avatar answered Feb 12 '23 12:02

LeGEC