git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Documentation: enhance gitignore whitelist example

From
Johannes Sixt <j6t@kdbg.org>
Date
Apr 5, 2011, 21:15 UTC
Message-ID
<201104052315.54375.j6t@kdbg.org>
In-Reply-To
<20110405194005.GA32427@elie>
On Dienstag, 5. April 2011, Jonathan Nieder wrote:
Show 9 quoted lines
> Eric Blake wrote:
> > @@ -70,7 +70,9 @@ PATTERN FORMAT
> >   - An optional prefix '!' which negates the pattern; any
> >     matching file excluded by a previous pattern will become
> >     included again.  If a negated pattern matches, this will
> > -   override lower precedence patterns sources.
> > +   override lower precedence patterns sources.  However, a
> > +   file negation does not override a path that has already
> > +   been excluded by a directory match.

I don't think this is the right place to explain this caveat. Here we describe the format and behavior of the patterns in a rather formal manner.

Show 7 quoted lines
> > @@ -87,7 +89,8 @@ PATTERN FORMAT
> >
> >   - 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.
> > +   wildcards in the pattern will not match a / in the pathname,
> > +   and do not ignore files with a leading . in the pathname.
I don't think this is correct. * matches .gitignore. I tried it.
Show 20 quoted lines
> > @@ -116,8 +119,11 @@ EXAMPLES
> >      [...]
> >      # Untracked files:
> >      [...]
> > +    #       Documentation/build
> >      #       Documentation/foo.html
> >      #       Documentation/gitignore.html
> > +    #       build/log
> > +    #       build/.file
> >      #       file.o
> >      #       lib.a
> >      #       src/internal.o
> > @@ -125,6 +131,10 @@ EXAMPLES
> >      $ cat .git/info/exclude
> >      # ignore objects and archives, anywhere in the tree.
> >      *.[oa]
> > +    # ignore files in the immediate child directory build,
> > +    /build/*
> > +    # except for the log.
> > +    !/build/log
Doesn't this example give the false impression that you could do
	/foo/*
	!/foo/bar/baz
and have foo/bar/baz not ignored? But it is still ignored.
I propose a paragraph like this in the NOTES section:

--- 8< --- When a directory is ignored, it is not possible to un-ignore a single file somewhere in the directory using another pattern. E.g., with the patterns

-------------- /build/ !/build/tests/results --------------

the file "build/tests/results" is still ignored because when a directory is ignored, its contents are never investigated. In a situation where a few exceptions in an otherwise ignored hierarchy are needed, the recommended procedure is to specify to ignore the root of the hierarchy and then to 'git add -f' the exceptional files. Subsequent changes to the files will not be ignored. --- 8< ---

-- Hannes
Previous: Jonathan NiederNext: Eric Blake
Message 3 of 9 in “Documentation: enhance gitignore whitelist example”
  1. Documentation: enhance gitignore whitelist exampleEric Blake, Apr 5, 2011
  2. Jonathan NiederApr 5, 2011
  3. Johannes SixtApr 5, 2011
  4. Eric BlakeApr 5, 2011
  5. Jonathan NiederApr 5, 2011
  6. Eric BlakeApr 5, 2011
  7. Junio C HamanoApr 5, 2011
  8. Junio C HamanoApr 5, 2011
  9. Junio C HamanoApr 5, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.