threads / discuss / 15613

ignoring files/directories in git

Subject: ignoring files/directories in git

## tl;dr

12 messages between Sep 21, 2008 and Sep 22, 2008.

replies: 11people: 6as markdown or json

mwolfe38· Sep 21, 2008, 16:54 UTC · lore

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· Sep 21, 2008, 17:19 UTC · re: mwolfe38 · lore

Re: ignoring files/directories in git

mwolfe38 wrote:
Show 13 quoted lines
> 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.

Show 18 quoted lines
> .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· Sep 21, 2008, 17:20 UTC · re: mwolfe38 · lore

Re: ignoring files/directories in git

mwolfe38, Sun, Sep 21, 2008 18:54:01 +0200:
Show 18 quoted lines
> 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· Sep 21, 2008, 17:42 UTC · re: mwolfe38 · lore

Re: ignoring files/directories in git

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:
Show 33 quoted lines
> 
> 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.
Tim Harper· Sep 22, 2008, 18:47 UTC · re: mwolfe38 · lore

Re: ignoring files/directories in git

On Sep 21, 2008, at 11:42 AM, mwolfe38 wrote:
Show 9 quoted lines
>
> 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
Dmitry Potapov· Sep 21, 2008, 17:42 UTC · re: mwolfe38 · lore

Re: ignoring files/directories in git

On Sun, Sep 21, 2008 at 09:54:38AM -0700, mwolfe38 wrote:
Show 16 quoted lines
> 
> 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· Sep 22, 2008, 00:06 UTC · re: mwolfe38 · lore

Re: ignoring files/directories in git

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:
Show 33 quoted lines
> 
> 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· Sep 22, 2008, 07:37 UTC · re: mwolfe38 · lore

Re: ignoring files/directories in git

mwolfe38 wrote:
Show 5 quoted lines
> 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

Show 34 quoted lines
> 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· Sep 22, 2008, 08:52 UTC · re: Boaz Harrosh · lore

Re: ignoring files/directories in git

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· Sep 22, 2008, 10:41 UTC · re: Dmitry Potapov · lore

Re: ignoring files/directories in git

Dmitry Potapov wrote:
Show 37 quoted lines
> 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· Sep 22, 2008, 11:53 UTC · re: Boaz Harrosh · lore

Re: ignoring files/directories in git

Boaz Harrosh wrote:
Show 46 quoted lines
> 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· Sep 22, 2008, 12:19 UTC · re: Boaz Harrosh · lore

Re: ignoring files/directories in git

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

← back to recent threads