I am trying to remove a previously tracked directory from git that works, but it is added back with each subsequent git add . , git add -A etc. Here is what I did:
Add to .gitignore to the project root:
node_modules
Do the following:
git rm -r --cached node_modules git commit -a -m "removed node_modules" git push origin master
So far, so good that it removes a directory from a remote repository. The problem is that when I later run git status , it tells me that the node_modules directory is not checked and continues to add it to future commits.
What am I missing and / or how can I find the root of my problem?
From here :
The git add command does not add ignored files by default .... The git add command can be used to add ignored files with the -f (force) option.
Additional information from the comments:
I am tracking a .gitignore file.
git check-ignore node_modules/ returns node_modules / as expected.
No use of submodules.
Update:
I created a pattern that seems to replicate the problem by following the steps above:
https://github.com/awhitehouse104/SampleRepo
Resolution:
To summarize the answer and comments below, the problem was the encoding of my .gitignore file. I used echo 'node_modules' > .gitignore to create the file on windows 8 and it appeared as UTF-16 with the specification (as per the answer below). After a few google searches, it seems like this is the default encoding with powershell, and I can confirm that saving, since UTF-8 seems to have solved the problem.
TL; DR; Probably do not use this method of creating .gitignore files or be prepared to change the encoding
echo 'node_modules' > .gitignore
git gitignore
aw04 Sep 04 '15 at 15:14 2015-09-04 15:14
source share