1

I have a lot of subfolders and files like node_modules>yargs-parser>README.md. And I wrote node_modules in .gitignore file but when I change something in a file like README.md, git is not ignoring the changes. How can I ignore?

Serdar Gun
  • 97
  • 6
  • What do you mean by "git is not ignoring the changes"? Did you already commit the file to the repository? – melpomene Sep 20 '19 at 07:08
  • 2
    Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – melpomene Sep 20 '19 at 07:08
  • your gitignore should contain `node_modules/`. Also if the file is already added to git, it cannot be ignored. Remove the file from git and it will be ignored in the future – Amir Schnell Sep 20 '19 at 07:09
  • I mean I want to ignore all files in the node_modules folder. And yes I committed. – Serdar Gun Sep 20 '19 at 07:10
  • That's not what "ignore" means. – melpomene Sep 20 '19 at 07:10
  • `node_modules/` means "ignore all the folders not files" and `node_modules` means ignore all the folders and files and I wrote `node_modules`. You can check Amir: https://labs.consol.de/development/git/2017/02/22/gitignore.html – Serdar Gun Sep 20 '19 at 07:13
  • Ahh I will ask something, .gitignore files ignores only the files that I will add not I already added right? – Serdar Gun Sep 20 '19 at 07:16

3 Answers3

1

If the file you are trying to ignore is already on the index, you need to remove it first with git rm --cached <file> then you can ignore it in .gitignore

-1

Your .gitignore file should be ideally on the root, along with .git folder. For various other examples, see the thread: Git ignore sub folders.

Check if you have spelling error or file permission issue on .gitignore file.

The file itself should should be committed.

Bimal Poudel
  • 1,214
  • 2
  • 18
  • 41
-2

to ignore everything inside you can add:

node_modules/*
EFOE
  • 609
  • 1
  • 10
  • 20