I have been having an issue with .gitignore not ignoring my node_modules directory.
Here is my .gitignore file:
*~
~*
*.log
images/
images/*
images/**/*
.idea/
.idea/*
import_errors/
output/
output/*
node_modules/
node_modules/*
uploads/
downloads/
tmp/
.DS_Store
!.keep
!*/
I also tried running commands to update the git-index and remove the folder from the index
$ git rm --cached node_modules
fatal: pathspec 'node_modules' did not match any files
$ git update-index --assume-unchanged node_modules
fatal: Unable to mark file node_modules
Normally I would just issue those two command, but I keep getting those errors. The first command is supposed to unstage the file and the second command is suppose to update the git index to stop tracking the file. But for some reason that does not happen and I do not know what else could be wrong.
I found the answer after carefully examining the gitignore file again. Turns out that my last rule says:
!*/
Which means that all the folders under the root of the project should be kept. I did that a long time ago before I fully understood how git worked. It was meant to keep certain folders there but just empty with no content in them. But that is what the rule above it is about and this rule does not need to be there.
So removing that line and doing $ git rm --cached node_modules does the trick. The command both removes it from the staging area and then updates the index so you do not have to run the second command $ git update-index --assume-unchange.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With