ignoring files/directories in git

12 messages, 6 authors, 2016-06-15 · open the first message on its own page

ignoring files/directories in git

From: mwolfe38 <hidden>
Date: 2016-06-15 22:45:23

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.

Re: ignoring files/directories in git

From: Boaz Harrosh <hidden>
Date: 2016-06-15 22:45:23

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

Re: ignoring files/directories in git

From: mwolfe38 <hidden>
Date: 2016-06-15 22:45:23

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.

Re: ignoring files/directories in git

From: Dmitry Potapov <hidden>
Date: 2016-06-15 22:45:23

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

Re: ignoring files/directories in git

From: mwolfe38 <hidden>
Date: 2016-06-15 22:45:23

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.

Re: ignoring files/directories in git

From: Boaz Harrosh <hidden>
Date: 2016-06-15 22:45:23

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:
quoted
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

Re: ignoring files/directories in git

From: Dmitry Potapov <hidden>
Date: 2016-06-15 22:45:23

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 [off-list ref]
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

Re: ignoring files/directories in git

From: Boaz Harrosh <hidden>
Date: 2016-06-15 22:45:23

Dmitry Potapov wrote:
On Mon, Sep 22, 2008 at 10:37:00AM +0300, Boaz Harrosh wrote:
quoted
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 [off-list ref]
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

Re: ignoring files/directories in git

From: Andreas Ericsson <hidden>
Date: 2016-06-15 22:45:23

Boaz Harrosh wrote:
Dmitry Potapov wrote:
quoted
On Mon, Sep 22, 2008 at 10:37:00AM +0300, Boaz Harrosh wrote:
quoted
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 [off-list ref]
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

Re: ignoring files/directories in git

From: Dmitry Potapov <hidden>
Date: 2016-06-15 22:45:23

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

Re: ignoring files/directories in git

From: Alex Riesen <hidden>
Date: 2016-06-15 22:45:23

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?

Re: ignoring files/directories in git

From: Tim Harper <hidden>
Date: 2016-06-15 22:45:23

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help