.gitignore is not ignored by node_modules

Even after adding the .gitignore file to the root of the .git repository, I cannot make git ignore the node_modules directory.

No files have been added for git for tracking.

I reviewed earlier questions, and also tried adding a comment line to the first line, since apparently git is not reading the first line of this file, and it still does not work. I also tried using the following command:

 git rm --cached -r . 

Can anyone help me out? The content of .gitignore :

 #first line node_modules/ 
+6
source share
3 answers

Even after adding the .gitignore file to the root of the .git repository, I cannot make git ignore the node_modules directory.

The .gitignore file should be placed in the root of the working tree (also known as the root of your project), which is located just above the .git directory. Inside the .git directory, the file has no effect.

This makes sense, because usually you want to put this file under version control to share the list of ignored files with all the developers of the project. And only files inside the working tree, outside .git are under version control, the .git directory is intended for internal git storage.

(If you want to ignore templates only locally without adding version control, you can do this by specifying templates in .git/info/exclude .)

[...], and also tried to add a comment line to the first line, since apparently git is not reading the first line of this file

For writing, it also reads the first line, there is nothing special about the first line in .gitignore .

+4
source

I solved the problem by deleting the file name in .gitignore and making it an invisible file or point file, just like the .gitignore file name .gitignore and saved the expression

node_modules/

in this file, so it works, and now git finally ignores the node-modules directory. I don't know exactly why this works, but at least it works.

+2
source

In my case, it was written in quotation marks, like this

 'functions/node_modules/' 

instead

 functions/node_modules/ 
0
source

Source: https://habr.com/ru/post/1263830/


All Articles