Home > database >  node_modules keep being pushed with git despite it being ignored and removed
node_modules keep being pushed with git despite it being ignored and removed

Time:11-04

I'm trying to push my local git project into github remote repo. I added node_modules into one commit I made but this exceeds GitHub's file size limit of 100.00 MB when I try

git push -u origin main

then

remote: error: Trace: d8e81b49d1b7e109e7b4585cf6b84d574b3888e15cb1b4f858c87c5a0147bc57
remote: error: File node_modules/node-sass/build/Release/libsass.lib is 160.60 MB; this exceeds GitHub's file size limit of 100.00 MB

Then I added .gitignore but that doesn't work because the commit was already made

I tried to remove that node_modules from being tracked and commited using

git rm -r cached node_modules

but it keeps trying to push that when I do git push.

I don't know how to remove node_modules from being pushed

CodePudding user response:

As per the discussion under Tirth's answer:

You can create a new branch and manually add the commits that do not add the node_modules.

Assuming

  • you are on branch master
  • the commit that added the node_modules has the hash a1a1a1a1.
  • your working tree is clean i.e. everything is committed locally

  1. Checkout the commit before the error and create the new branch (called fixed).
    If a1a1a1a1 is the first commit on master, you'll have to create an orphan branch as per this post instead.
git checkout a1a1a1a1^
git switch -c fixed
  1. If the commit contained other things than the node modules, recreate that commit without the node_modules part.

  2. Add all the commits after a1a1a1a1 to the new branch

git cherry-pick a1a1a1a1..master

Once you are sure everything is there, you can delete the master, rename fixed to master and then (force) push the new master branch.

CodePudding user response:

If you just committed your node modules you could do

git reset HEAD~N

where N is how many commits you want to go behind. In this case I am assuming you want to go one commit behind. Doing this will un-commit your node modules and other things you committed and put them in your working tree. After this just remove the node un-stage node modules from working tree. Now you can commit again with the changes you want.

  •  Tags:  
  • git
  • Related