From: Junio C Hamano <gitster@pobox.com>
To: Brent Goodrick <bgoodr@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: How do I qualify paths in the .gitignore file w.r.t. the repo root directory?
Date: Mon, 23 Feb 2009 23:06:42 -0800 [thread overview]
Message-ID: <7v1vtomhz1.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <e38bce640902232247t63a37f63x9f403fbda0744cfd@mail.gmail.com> (Brent Goodrick's message of "Mon, 23 Feb 2009 22:47:13 -0800")
Brent Goodrick <bgoodr@gmail.com> writes:
> Say I have these files and directories [2]:
>
> /home/smart_tator/misc_files/.gitignore
> /home/smart_tator/misc_files/foo/
> /home/smart_tator/misc_files/bar/
> /home/smart_tator/misc_files/bar/baz/foo/
> /home/smart_tator/misc_files/bar/baz/real/
>
> then I do:
>
> cd /home/smart_tator/misc_files/; git init
>
> and say I have this line in that .gitignore file:
>
> foo/
>
> And then I naively execute:
>
> git add bar/
>
> then the bar/baz/real/ is added, but these are dutifully ignored:
>
> /home/smart_tator/misc_files/foo/
> /home/smart_tator/misc_files/bar/baz/foo/
I think you are looking for "/foo/". From Documentation/gitignore.txt:
- If the pattern ends with a slash, it is removed for the
purpose of the following description, but it would only find
a match with a directory. In other words, `foo/` will match a
directory `foo` and paths underneath it, but will not match a
regular file or a symbolic link `foo` (this is consistent
with the way how pathspec works in general in git).
With this rule, (1) the trailing slash in your "foo/" tells git to match
only with directories, but (2) it behaves as if you said "foo" for all the
other rules.
With "/foo/", you tell git to match only with a directory, and it is as if
you said "/foo".
- If the pattern does not contain a slash '/', git treats it as
a shell glob pattern and checks for a match against the
pathname without leading directories.
Your "foo/" now behaves the same way as "foo" behaves. You are telling
git to match directory foo anywhere in the tree. "/foo/" (now behaving
the same way as "/foo") does not satisfy this criteria so we would skip
this rule.
- Otherwise, git treats the pattern as a shell glob suitable
for consumption by fnmatch(3) with the FNM_PATHNAME flag:
wildcards in the pattern will not match a / in the pathname.
For example, "Documentation/\*.html" matches
"Documentation/git.html" but not
"Documentation/ppc/ppc.html". A leading slash matches the
beginning of the pathname; for example, "/*.c" matches
"cat-file.c" but not "mozilla-sha1/sha1.c".
Your "foo/" does not survive to this rule, but "/foo/" does. It now
behaves as "/foo" and its leading slash makes it match the beginning.
next prev parent reply other threads:[~2009-02-24 7:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-24 6:47 How do I qualify paths in the .gitignore file w.r.t. the repo root directory? Brent Goodrick
2009-02-24 7:06 ` Junio C Hamano [this message]
2009-02-24 9:07 ` Sitaram Chamarty
2009-02-24 17:33 ` Junio C Hamano
2009-02-24 18:31 ` Sitaram Chamarty
2009-02-25 3:31 ` Sitaram Chamarty
2009-02-25 8:36 ` Junio C Hamano
2009-02-25 11:17 ` Sitaram Chamarty
2009-02-25 21:25 ` Junio C Hamano
2009-02-26 0:45 ` Björn Steinbrink
2009-02-26 1:23 ` Sitaram Chamarty
2009-02-26 3:48 ` Sitaram Chamarty
2009-02-26 17:04 ` Junio C Hamano
2009-02-25 1:14 ` Brent Goodrick
2009-02-25 4:01 ` Sitaram Chamarty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v1vtomhz1.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=bgoodr@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox