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

Re: Git ignore help

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 22, 2015, 03:33 UTC
Message-ID
<CAPig+cRU38sNHRsn=8=60wPO_AoQt-zn1dicFHwjG0OK-9tecQ@mail.gmail.com>
In-Reply-To
<47F.3lxhK.7IviRa5Gutr.1L2}X3@seznam.cz>
On Fri, Mar 20, 2015 at 6:36 AM,  <mdconf@seznam.cz> wrote:
Show 26 quoted lines
> I am trying to setup my git ignore (resp. .git/info/exclude) so that I exclude
>  all directories and files except the content of directories that I
> specifically include (incl. anything within them recursively).
>
> I set the .git/info/exclude with the following content:
>
> ========
> # Exclude everything
> /*
> # Except the below that we include
> !/db/data/load/base/bootstraponly
> !/db/data/load/base/safetoload
> !/db/ddl
> !/labels
> !/reports/usrint
> !/scripts
> !/src/cmdsrc/usrint
> ========
>
> However it does not do what I anticipated. It indeed excludes everything but
> the include part does not work - it only works for !/labels and !/scripts
> directories (i.e. the first level directories). All other are still ignored -
> so when I create file /db/data/load/base/bootstraponly/somefile.txt git still
> ignores it...
>
> Any idea what I am doing wrong?

The fourth bullet point of the "Pattern Format" section of the gitignore man page has this to say, which explains the behavior you're seeing:

    An optional prefix "!" which negates the pattern; any matching
    file excluded by a previous pattern will become included again.
    It is not possible to re-include a file if a parent directory of
    that file is excluded. Git doesn’t list excluded directories for
    performance reasons, so any patterns on contained files have no
    effect, no matter where they are defined.
Previous: mdconf@seznam.czNext: Duy Nguyen
Message 2 of 9 in “Git ignore help”
  1. mdconf@seznam.czMar 20, 2015
  2. Eric SunshineMar 22, 2015
  3. Duy NguyenMar 24, 2015
  4. Eric SunshineMar 24, 2015
  5. Duy NguyenMar 24, 2015
  6. mdconf@seznam.czMar 24, 2015
  7. Duy NguyenMar 24, 2015
  8. Eric SunshineMar 24, 2015
  9. Junio C HamanoMar 24, 2015

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.