문제

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