Skip to contentSkip to conversation

ignoring files/directories in git

DISCUSSION mwolfe38 6 participants 12 messages Jun 15, 2016

lore
Share & tools
lore

mwolfe38

author
#0 lore raw

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

Signature · 2 lines
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.
author
#1 lore raw

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/

Quoted 33 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

Signature · 2 lines
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.
#2 lore raw
Quoted 8 lines · 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

author
#3 lore raw
In reply to mwolfe38

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.

Quoted 33 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

Signature · 2 lines
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.
#4 lore raw
Quoted 5 lines · 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

Quoted 27 lines
Quoted 26 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.

Quoted 7 lines
Quoted 6 lines

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

#5 lore raw
Quoted 3 lines · Boaz Harrosh

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 <[email protected]>
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

#6 lore raw
Quoted 33 lines · Dmitry Potapov
Quoted 2 lines · Boaz Harrosh

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 <[email protected]>
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.
===

Quoted 4 lines

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

#7 lore raw
Quoted 3 lines · Boaz Harrosh

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

#8 lore raw
In reply to Boaz Harrosh
Quoted 38 lines · Boaz Harrosh
Quoted 32 lines · Dmitry Potapov
Quoted 2 lines · Boaz Harrosh

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 <[email protected]>
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.
===

Quoted 4 lines

The patch is included in 1.5.5.

Dmitry
--

Quoted 8 lines

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.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#9 lore raw
In reply to mwolfe38

mwolfe38, Sun, Sep 21, 2008 18:54:01 +0200:

Quoted 13 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

Quoted 5 lines

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?

#10 lore raw
In reply to mwolfe38
Quoted 11 lines · 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

Quoted 5 lines

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

#11 lore raw
In reply to mwolfe38
Quoted 9 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:

Quoted 4 lines

.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.

Quoted 13 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.

Quoted 5 lines

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