I'm pretty new to Git and trying to understand how it works and why. I have a web project that I'm working on and I have a .gitignore file that has the following line:

www/*

Now, I need to add just the www folder to my repo, so I've added just an empty .gitignore file to it and updated my main .gitignore file like so:

!www/.gitignore
www/*

Except, now when I do git status, nothing comes up as needed to be added. In order to add it to the staging, I have to do git add www/.gitignore -f.

Why doesn't Git just recognize the exclusion automatically and add the file for me when I do git add *? Thanks!

有帮助吗?

解决方案

Order matters. Both rules match the same file, so the later one wins, and the file is ignored. Your earlier ! is overridden by your second rule.

You need to put the exclusion second:

www/*
!www/.gitignore

其他提示

Try removing anything about the www directory from your root .gitignore, then make the contents of www/.gitignore:

*
!.gitignore

This is how my repo is set up currently and I've had no issues.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top