问题
I always thought I knew how to ignore and negate patterns, but I'm stumped. I have a baseline Drupal install and I'd like to ignore everything in the sites/
folder except for a couple of specific subdirectories: sites/all
and sites/my-project
.
.vagrant
settings.php
# A directory set aside for user contributed assets
uploads/
# All we care about is sites/all and sites/my-project
www/sites/*
!www/sites/all
!www/sites/my-project
Given the above .gitignore
file in the project root, when I do a git add .
, I get everything I'd expect from www/sites/all
, but nothing from www/sites/my-project
. What am I missing here? There's only one file that I care about (www/sites/my-project/settings.sample.php
) right now, but I can't figure out why it's not adding like everything else.
I know I could force it, but I want to understand the larger issue. What am I missing here? For whatever it's worth, this is my initial commit. I don't that it matters in any way, but I also don't know that it doesn't.
UPDATE
Whoops! Looks like the one file I care about is being ignored (which would explain why the directory is ignored). I have no idea where or why, but it gives me places to look...
回答1:
I don't see a problem:
$ find .
.
./.gitignore
./www
./www/sites
./www/sites/ignored
./www/sites/ignored/file
./www/sites/my-project
./www/sites/my-project/file
./www/sites/my-project/settings.sample.php
./www/sites/all
./www/sites/all/file
$ git init
Initialized empty Git repository in /home/desert69/tmp/gitignore/.git/
$ cat .gitignore
.vagrant
settings.php
# A directory set aside for user contributed assets
uploads/
# All we care about is sites/all and sites/my-project
www/sites/*
!www/sites/all
!www/sites/my-project
$ git add .
$ git status --short
A .gitignore
A www/sites/all/file
A www/sites/my-project/file
A www/sites/my-project/settings.sample.php
$ git --version
git version 1.7.10.4
So everything seems to be working.
Try doing a rm -rf .git/ && git init
just in case you previously ignored or added any other file.
I thought maybe there was anything with the dot in settings.php
being interpreted as an *
so it matched .sample.
, but don't seems to.
Try deleting and re-init
ing the repository.
来源:https://stackoverflow.com/questions/15416442/ignoring-a-directory-but-not-a-subdirectory-or-two