I know there are many questions on how to ignore directories, and I usually haven't had any problem until now, but now I'm stuck with something I don't understand.
Here is my directory structure:
/src
/war
com.example.MyProject/
WEB-INF/
classes/
deploy/
lib/
I want to ignore content of directories classes/
, deploy/
and com.example.MyProject/
, and here is my .gitignore file:
*.log
war/WEB-INF/classes/
war/WEB-INF/deploy/
com.example.MyProject/
Files under com.example.MyProject/
are automatically generated, and git ignores all of them except for a file named com.example.MyProject.nocache.js
. In fact, when I do git status
I get:
# On branch myBranch
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: .gitignore
# ......
# modified: war/com.example.MyProject/com.example.MyProject.nocache.js
Why does git refuse to ignore that single file in that directory? What am I doing wrong?
If a file is already being tracked by Git, adding the file to .gitignore
won't stop Git from tracking it. You’ll need to do git rm --cached <file>
to keep the file in your tree and then ignore it
If the file has already been added to the index, it will still stay in there, even though you add it to the .gitignore
file.
Try removing the file from the git index:
git rm --cached war/com.example.MyProject/com.example.MyProject.nocache.js
The --cached
option makes sure that the file stays in your folder and just gets removed from the index
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