问题描述
我一直以为我知道如何忽略和否定模式,但是我很沮丧.我有一个基准Drupal安装,我想忽略sites/
文件夹中的所有内容,除了几个特定的子目录:sites/all
和sites/my-project
.
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
考虑到项目根目录中的上述.gitignore
文件,当我执行git add .
时,我从www/sites/all
中得到了我期望的一切,但从www/sites/my-project
中什么也没有得到.我在这里想念什么?我现在只关心一个文件(www/sites/my-project/settings.sample.php
),但我不知道为什么它没有像其他所有文件一样添加.
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.
更新
哇!看起来我关心的 文件被忽略了(这可以解释为什么目录被忽略了).我不知道在哪里或为什么,但是它给了我看的地方...
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...
推荐答案
我没看到问题:
$ 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
所以一切似乎都正常.
尝试执行rm -rf .git/ && git init
,以防万一您先前忽略或添加了任何其他文件.
Try doing a rm -rf .git/ && git init
just in case you previously ignored or added any other file.
我认为settings.php
中的点可能被解释为*
,因此它与.sample.
相匹配,但似乎没有.
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.
尝试删除并重新init
存储库.
Try deleting and re-init
ing the repository.
这篇关于忽略目录...但不忽略一两个子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!