My gitignore file looks like this:

*.csv
*.dat
*.iml
*.log
*.out
*.pid
*.seed
*.sublime-*
*.swo
*.swp
*.tgz
*.xml
.DS_Store
.idea
.project
.strong-pm
coverage
node_modules
npm-debug.log
server-info
definitions/

Yet, suddenly git status shows me a lot of npm-debug.log files in red. enter image description here

I also get the message

nothing added to commit but untracked files present (use "git add" to track)

How do I remove all the npm-debug.log files from my local machine without accidentally deleting any important files?

Also, how do I prevent these files from being created in the first place?

2

There are 2 best solutions below

0
Mostafa Hussein On BEST ANSWER

You need to add npm-debug.log* to your .gitignore file, because the current status of the .gitignore file means npm-debug.log only.

Adding asterisk * will ensure that any file starting with npm-debug.log will be ignored

If you want to delete them forever from your machine use the following command:

rm -f npm-debug.log.*
1
d4vsanchez On

To ignore the npm-debug files on Git you're missing a star at the end of the string in your .gitignore file.

npm-debug.log*

And if you want to never generate those logs, you can execute the install with --loglevel=silent, anyway I don't recommend to do that, they may be useful.