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

Re: How do I stop git enumerating my working directory

From
Brian Gernhardt <benji@silverinsanity.com>
Date
Jul 1, 2008, 19:01 UTC
Message-ID
<F90E06B1-CCD3-4A36-8838-22BEC59DFBF3@silverinsanity.com>
In-Reply-To
<486A53CC.4020803@glidos.net>
On Jul 1, 2008, at 11:57 AM, Paul Gardiner wrote:
Show 6 quoted lines
> I don't think I can make .gitignore files do the job, because
> it seems that you can set up to ignore a whole directory,
> and then partially countermand that by placing a .gitignore
> file (containing ! commands) inside the directory. That
> makes me think that ignoring doesn't prevent the
> enumeration.

That's where you're wrong. You can't get git to pay attention to anything inside an ignored directory using the .gitignore files. Once you ignore a directory, git stops looking at it completely. You can force git to look at a file inside an ignored directory by adding it directly, though. Git will pay attention to files you add for changes, but won't pay any attention to other files around it.

See the log below for what I mean:
$ mkdir temp
$ cd temp
$ git init
Initialized empty Git repository in /Users/brian/dev/temp/.git/
$ cat > .gitignore
ignoredir/
$ mkdir ignoredir
$ touch A
$ touch ignoredir/B
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
#       A
nothing added to commit but untracked files present (use "git add" to  
track)
$ cat > ignoredir/.gitignore
!B
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
#       A
nothing added to commit but untracked files present (use "git add" to  
track)
$ git add ignoredir/B
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file: ignoredir/B
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
#       A
$ git commit -m "A"
Created initial commit 36ade7a: A
  0 files changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 ignoredir/B
$ echo new > ignoredir/B
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#
#       modified:   ignoredir/B
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
#       A
no changes added to commit (use "git add" and/or "git commit -a")
Previous: Paul GardinerNext: Paul Gardiner
Message 4 of 5 in “How do I stop git enumerating my working directory”
  1. Paul GardinerJul 1, 2008
  2. Matthieu MoyJul 1, 2008
  3. Paul GardinerJul 2, 2008
  4. Brian GernhardtJul 1, 2008
  5. Paul GardinerJul 2, 2008

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.