# ignoring files/directories in git

12 messages from 2008-09-21 to 2008-09-22. Participants: mwolfe38, Boaz Harrosh, Dmitry Potapov, Andreas Ericsson, Alex Riesen, Tim Harper.
Thread: https://gitlist.dev/t/15613

## mwolfe38, 2008-09-21 16:54

Subject: ignoring files/directories in git
Message-ID: <19596152.post@talk.nabble.com>
URL: https://gitlist.dev/e/19596152.post%40talk.nabble.com

```

I'm working on a project by myself and using git mostly just to learn about
it.
In my project I have several directories I do not want to have git ignore.
One of them being
cache/ and the other log/
I've added them to the .gitignore file which I have in the initial directory
of the repository
The contents of my gitignore are:

.settings
.cache
cache/
log/
.project

However, if I do 
git add .
It will add the files from cache and log anyways.
I know git add . will add anything that hasn't been added but shouldn't it
ignore files in .gitignore?
If not, what is the point, I would just ignore them manually anyways. 
The main reason i like doing git add .
is because i'm using symfony php framework which makes good use of scripts
which generates lots if initial files for you and thus adding one at a time
would be a pain.

Any idea what might be going on here?  I thought maybe I had added those
directories before putting them in .gitignore so i used git rm -r to remove
them but they still show back up with doing git add .

Thanks in advance
-- 
View this message in context: http://www.nabble.com/ignoring-files-directories-in-git-tp19596152p19596152.html
Sent from the git mailing list archive at Nabble.com.

```

## Boaz Harrosh, 2008-09-21 17:19

Subject: Re: ignoring files/directories in git
Message-ID: <48D68216.1080404@panasas.com>
URL: https://gitlist.dev/e/48D68216.1080404%40panasas.com
In-Reply-To: <19596152.post@talk.nabble.com>

```
mwolfe38 wrote:
> I'm working on a project by myself and using git mostly just to learn about
> it.
> In my project I have several directories I want to have git ignore. One of
> them being
> cache/ and the other log/
> I've added them to the .gitignore file which I have in the initial directory
> of the repository
> The contents of my gitignore are:
> 
> .settings
> .cache
> cache/
> log/

If I use "patches/" in my .gitignore file and then git-status 
then I get all these extra files in the "Untracked files:" section
but if I use plain "patches" (No slash at end) then it works. Sounds
like a bug to me but it sure is a workaround.

> .project
> 
> However, if I do 
> git add .
> It will add the files from cache and log anyways.
> I know git add . will add anything that hasn't been added but shouldn't it
> ignore files in .gitignore?
> If not, what is the point, I would just ignore them manually anyways. 
> The main reason i like doing git add .
> is because i'm using symfony php framework which makes good use of scripts
> which generates lots if initial files for you and thus adding one at a time
> would be a pain.
> 
> Any idea what might be going on here?  I thought maybe I had added those
> directories before putting them in .gitignore so i used git rm -r to remove
> them but they still show back up with doing git add .
> 
> Thanks in advance

Boaz

```

## Alex Riesen, 2008-09-21 17:20

Subject: Re: ignoring files/directories in git
Message-ID: <20080921172048.GA3877@blimp.localhost>
URL: https://gitlist.dev/e/20080921172048.GA3877%40blimp.localhost
In-Reply-To: <19596152.post@talk.nabble.com>

```
mwolfe38, Sun, Sep 21, 2008 18:54:01 +0200:
> In my project I have several directories I do not want to have git ignore.
> One of them being
> cache/ and the other log/
> I've added them to the .gitignore file which I have in the initial directory
> of the repository
> The contents of my gitignore are:
> 
> .settings
> .cache
> cache/
> log/
> .project
> 
> However, if I do 
> git add .
> It will add the files from cache and log anyways.
> I know git add . will add anything that hasn't been added but shouldn't it
> ignore files in .gitignore?

It should and indeed it does ignore them:

    $ mkdir ggg && cd ggg
    $ git init
    Initialized empty Git repository in /tmp/ggg/.git/
    $ >a
    $ mkdir cache log
    $ touch cache/b
    $ touch log/c
    $ echo cache/ >.gitignore
    $ echo log/ >>.gitignore
    $ cat .gitignore
    cache
    log
    $ git add .
    $ git ls-files
    .gitignore
    a

What is your git version and where have you got it from?
Is your .gitignore written exactly like this (case, some hidden
extension, like they do on Windows)? Any invisible characters in
.gitignore?

```

## mwolfe38, 2008-09-21 17:42

Subject: Re: ignoring files/directories in git
Message-ID: <19596620.post@talk.nabble.com>
URL: https://gitlist.dev/e/19596620.post%40talk.nabble.com
In-Reply-To: <19596152.post@talk.nabble.com>

```

Fixed, by removing the trailing / in the names it will then ignore all files
in that directory,
so now i just have
cache 
log
instead of 
cache/ and log/




mwolfe38 wrote:
> 
> I'm working on a project by myself and using git mostly just to learn
> about it.
> In my project I have several directories I want to have git ignore. One of
> them being
> cache/ and the other log/
> I've added them to the .gitignore file which I have in the initial
> directory of the repository
> The contents of my gitignore are:
> 
> .settings
> .cache
> cache/
> log/
> .project
> 
> However, if I do 
> git add .
> It will add the files from cache and log anyways.
> I know git add . will add anything that hasn't been added but shouldn't it
> ignore files in .gitignore?
> If not, what is the point, I would just ignore them manually anyways. 
> The main reason i like doing git add .
> is because i'm using symfony php framework which makes good use of scripts
> which generates lots if initial files for you and thus adding one at a
> time would be a pain.
> 
> Any idea what might be going on here?  I thought maybe I had added those
> directories before putting them in .gitignore so i used git rm -r to
> remove them but they still show back up with doing git add .
> 
> Thanks in advance
> 

-- 
View this message in context: http://www.nabble.com/ignoring-files-directories-in-git-tp19596152p19596620.html
Sent from the git mailing list archive at Nabble.com.

```

## Dmitry Potapov, 2008-09-21 17:42

Subject: Re: ignoring files/directories in git
Message-ID: <20080921174255.GF21650@dpotapov.dyndns.org>
URL: https://gitlist.dev/e/20080921174255.GF21650%40dpotapov.dyndns.org
In-Reply-To: <19596152.post@talk.nabble.com>

```
On Sun, Sep 21, 2008 at 09:54:38AM -0700, mwolfe38 wrote:
> 
> I've added them to the .gitignore file which I have in the initial directory
> of the repository
> The contents of my gitignore are:
> 
> .settings
> .cache
> cache/
> log/
> .project
> 
> However, if I do 
> git add .
> It will add the files from cache and log anyways.
> I know git add . will add anything that hasn't been added but shouldn't it
> ignore files in .gitignore?

It does ignore files in .gitignore. What version of Git do you use?
IIRC, some old ones did not like the slash at the end of name.

Dmitry

```

## mwolfe38, 2008-09-22 00:06

Subject: Re: ignoring files/directories in git
Message-ID: <19599905.post@talk.nabble.com>
URL: https://gitlist.dev/e/19599905.post%40talk.nabble.com
In-Reply-To: <19596152.post@talk.nabble.com>

```

I just thought that I would add that the reason is a bug in the 1.5.4.3
version that I am using which is the ubuntu 8.04 repository version.
According to some developers, the current version should fix this issue.


mwolfe38 wrote:
> 
> I'm working on a project by myself and using git mostly just to learn
> about it.
> In my project I have several directories I want to have git ignore. One of
> them being
> cache/ and the other log/
> I've added them to the .gitignore file which I have in the initial
> directory of the repository
> The contents of my gitignore are:
> 
> .settings
> .cache
> cache/
> log/
> .project
> 
> However, if I do 
> git add .
> It will add the files from cache and log anyways.
> I know git add . will add anything that hasn't been added but shouldn't it
> ignore files in .gitignore?
> If not, what is the point, I would just ignore them manually anyways. 
> The main reason i like doing git add .
> is because i'm using symfony php framework which makes good use of scripts
> which generates lots if initial files for you and thus adding one at a
> time would be a pain.
> 
> Any idea what might be going on here?  I thought maybe I had added those
> directories before putting them in .gitignore so i used git rm -r to
> remove them but they still show back up with doing git add .
> 
> Thanks in advance
> 

-- 
View this message in context: http://www.nabble.com/ignoring-files-directories-in-git-tp19596152p19599905.html
Sent from the git mailing list archive at Nabble.com.

```

## Boaz Harrosh, 2008-09-22 07:37

Subject: Re: ignoring files/directories in git
Message-ID: <48D74B1C.6020408@panasas.com>
URL: https://gitlist.dev/e/48D74B1C.6020408%40panasas.com
In-Reply-To: <19599905.post@talk.nabble.com>

```
mwolfe38 wrote:
> I just thought that I would add that the reason is a bug in the 1.5.4.3
> version that I am using which is the ubuntu 8.04 repository version.
> According to some developers, the current version should fix this issue.
> 
> 
[Please don't top-post]

I have 1.6.0.1 I compiled here, and it has the same problem. So it is
a very recent fix

> mwolfe38 wrote:
>> I'm working on a project by myself and using git mostly just to learn
>> about it.
>> In my project I have several directories I want to have git ignore. One of
>> them being
>> cache/ and the other log/
>> I've added them to the .gitignore file which I have in the initial
>> directory of the repository
>> The contents of my gitignore are:
>>
>> .settings
>> .cache
>> cache/
>> log/
>> .project
>>
>> However, if I do 
>> git add .
>> It will add the files from cache and log anyways.
>> I know git add . will add anything that hasn't been added but shouldn't it
>> ignore files in .gitignore?
>> If not, what is the point, I would just ignore them manually anyways. 
>> The main reason i like doing git add .
>> is because i'm using symfony php framework which makes good use of scripts
>> which generates lots if initial files for you and thus adding one at a
>> time would be a pain.
>>
>> Any idea what might be going on here?  I thought maybe I had added those
>> directories before putting them in .gitignore so i used git rm -r to
>> remove them but they still show back up with doing git add .
>>
>> Thanks in advance
>>
> 

Boaz

```

## Dmitry Potapov, 2008-09-22 08:52

Subject: Re: ignoring files/directories in git
Message-ID: <20080922085200.GI21650@dpotapov.dyndns.org>
URL: https://gitlist.dev/e/20080922085200.GI21650%40dpotapov.dyndns.org
In-Reply-To: <48D74B1C.6020408@panasas.com>

```
On Mon, Sep 22, 2008 at 10:37:00AM +0300, Boaz Harrosh wrote:
> 
> I have 1.6.0.1 I compiled here, and it has the same problem. So it is
> a very recent fix

I certainly tested 1.6.0.1 and does not have this problem, and it was
fixed a long time ago:

===
commit d6b8fc303b389b026f2bf9918f6f83041488989b
Author: Junio C Hamano <gitster@pobox.com>
Date:   Thu Jan 31 01:17:48 2008 -0800

    gitignore(5): Allow "foo/" in ignore list to match directory "foo"

    A pattern "foo/" in the exclude list did not match directory
    "foo", but a pattern "foo" did.  This attempts to extend the
    exclude mechanism so that it would while not matching a regular
    file or a symbolic link "foo".  In order to differentiate a
    directory and non directory, this passes down the type of path
    being checked to excluded() function.

    A downside is that the recursive directory walk may need to run
    lstat(2) more often on systems whose "struct dirent" do not give
    the type of the entry; earlier it did not have to do so for an
    excluded path, but we now need to figure out if a path is a
    directory before deciding to exclude it.  This is especially bad
    because an idea similar to the earlier CE_UPTODATE optimization
    to reduce number of lstat(2) calls would by definition not apply
    to the codepaths involved, as (1) directories will not be
    registered in the index, and (2) excluded paths will not be in
    the index anyway.
===

The patch is included in 1.5.5.

Dmitry

```

## Boaz Harrosh, 2008-09-22 10:41

Subject: Re: ignoring files/directories in git
Message-ID: <48D77643.1090908@panasas.com>
URL: https://gitlist.dev/e/48D77643.1090908%40panasas.com
In-Reply-To: <20080922085200.GI21650@dpotapov.dyndns.org>

```
Dmitry Potapov wrote:
> On Mon, Sep 22, 2008 at 10:37:00AM +0300, Boaz Harrosh wrote:
>> I have 1.6.0.1 I compiled here, and it has the same problem. So it is
>> a very recent fix
> 
> I certainly tested 1.6.0.1 and does not have this problem, and it was
> fixed a long time ago:
> 
> ===
> commit d6b8fc303b389b026f2bf9918f6f83041488989b
> Author: Junio C Hamano <gitster@pobox.com>
> Date:   Thu Jan 31 01:17:48 2008 -0800
> 
>     gitignore(5): Allow "foo/" in ignore list to match directory "foo"
> 
>     A pattern "foo/" in the exclude list did not match directory
>     "foo", but a pattern "foo" did.  This attempts to extend the
>     exclude mechanism so that it would while not matching a regular
>     file or a symbolic link "foo".  In order to differentiate a
>     directory and non directory, this passes down the type of path
>     being checked to excluded() function.
> 
>     A downside is that the recursive directory walk may need to run
>     lstat(2) more often on systems whose "struct dirent" do not give
>     the type of the entry; earlier it did not have to do so for an
>     excluded path, but we now need to figure out if a path is a
>     directory before deciding to exclude it.  This is especially bad
>     because an idea similar to the earlier CE_UPTODATE optimization
>     to reduce number of lstat(2) calls would by definition not apply
>     to the codepaths involved, as (1) directories will not be
>     registered in the index, and (2) excluded paths will not be in
>     the index anyway.
> ===
> 
> The patch is included in 1.5.5.
> 
> Dmitry
> --

Ok I found it. Regular subdirectories it works as you said,
but soft-link to a folder does not. Sorry for the noise i didn't
realize that in my test it was a simlink and not a full directory.

Please don't fix it if it will hurt performance, I'm happy with
current solution as it is. Just maybe a small addition to the
.gitignore documentation perhaps.

Boaz

```

## Andreas Ericsson, 2008-09-22 11:53

Subject: Re: ignoring files/directories in git
Message-ID: <48D78749.3030509@op5.se>
URL: https://gitlist.dev/e/48D78749.3030509%40op5.se
In-Reply-To: <48D77643.1090908@panasas.com>

```
Boaz Harrosh wrote:
> Dmitry Potapov wrote:
>> On Mon, Sep 22, 2008 at 10:37:00AM +0300, Boaz Harrosh wrote:
>>> I have 1.6.0.1 I compiled here, and it has the same problem. So it is
>>> a very recent fix
>> I certainly tested 1.6.0.1 and does not have this problem, and it was
>> fixed a long time ago:
>>
>> ===
>> commit d6b8fc303b389b026f2bf9918f6f83041488989b
>> Author: Junio C Hamano <gitster@pobox.com>
>> Date:   Thu Jan 31 01:17:48 2008 -0800
>>
>>     gitignore(5): Allow "foo/" in ignore list to match directory "foo"
>>
>>     A pattern "foo/" in the exclude list did not match directory
>>     "foo", but a pattern "foo" did.  This attempts to extend the
>>     exclude mechanism so that it would while not matching a regular
>>     file or a symbolic link "foo".  In order to differentiate a
>>     directory and non directory, this passes down the type of path
>>     being checked to excluded() function.
>>
>>     A downside is that the recursive directory walk may need to run
>>     lstat(2) more often on systems whose "struct dirent" do not give
>>     the type of the entry; earlier it did not have to do so for an
>>     excluded path, but we now need to figure out if a path is a
>>     directory before deciding to exclude it.  This is especially bad
>>     because an idea similar to the earlier CE_UPTODATE optimization
>>     to reduce number of lstat(2) calls would by definition not apply
>>     to the codepaths involved, as (1) directories will not be
>>     registered in the index, and (2) excluded paths will not be in
>>     the index anyway.
>> ===
>>
>> The patch is included in 1.5.5.
>>
>> Dmitry
>> --
> 
> Ok I found it. Regular subdirectories it works as you said,
> but soft-link to a folder does not. Sorry for the noise i didn't
> realize that in my test it was a simlink and not a full directory.
> 
> Please don't fix it if it will hurt performance, I'm happy with
> current solution as it is. Just maybe a small addition to the
> .gitignore documentation perhaps.
> 

It wouldn't hurt performance (noticeably) to change the lstat()
call to a stat() call. It's slightly more work for the kernel,
but assuming you don't have tens of thousands of symlinks it
really won't make a difference. I'm not sure what other things
would break from using stat() instead of lstat() in the exclude
matching code though, so it's not so simple as just replacing
it.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

```

## Dmitry Potapov, 2008-09-22 12:19

Subject: Re: ignoring files/directories in git
Message-ID: <20080922121920.GL21650@dpotapov.dyndns.org>
URL: https://gitlist.dev/e/20080922121920.GL21650%40dpotapov.dyndns.org
In-Reply-To: <48D77643.1090908@panasas.com>

```
On Mon, Sep 22, 2008 at 01:41:07PM +0300, Boaz Harrosh wrote:
> 
> Ok I found it. Regular subdirectories it works as you said,
> but soft-link to a folder does not.

Why should it? Git does not follow symbolic links regardless whether
they point to files or directories. In fact, Git does extra checks to
avoid something like: symlink-to-dir/normal-file to be added as a
normal file. There was some discussion about it a couple months ago
("Not going beyond symbolic links").


Dmitry

```

## Tim Harper, 2008-09-22 18:47

Subject: Re: ignoring files/directories in git
Message-ID: <74FEF67B-4F2F-46D6-9679-97C2C19829F5@gmail.com>
URL: https://gitlist.dev/e/74FEF67B-4F2F-46D6-9679-97C2C19829F5%40gmail.com
In-Reply-To: <19596620.post@talk.nabble.com>

```
On Sep 21, 2008, at 11:42 AM, mwolfe38 wrote:

>
> Fixed, by removing the trailing / in the names it will then ignore  
> all files
> in that directory,
> so now i just have
> cache
> log
> instead of
> cache/ and log/

FYI, you might try this instead:
/cache
/log

It's more specific, and if you had a file like "/lib/adapters/log/ 
rotater.rb", it wouldn't be ignored, whereas it would without the  
leading slashes.

Tim

```
