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

Re: Why does git track directory listed in .gitignore/".git/info/exclude"?

From
APAdam Piatyszek <ediap@users.sourceforge.net>
Date
Jan 31, 2008, 07:05 UTC
Message-ID
<47A1733E.9040103@users.sourceforge.net>
In-Reply-To
<7vprvjgi9v.fsf@gitster.siamese.dyndns.org>
Hi Junio,
* Junio C Hamano [30 I 2008 21:39]:
Show 15 quoted lines
> When you say "foo", you mean "I want either 'foo' that is a
> non-directory, or everything under 'foo' if that is a
> directory".  When you say "foo/", you are saying "I do not want
> 'foo' if it is a non-directory.  I want everything under 'foo'
> if and only if that is a directory".  Compare:
> 
> 	git ls-files -s Makefile/
>         git ls-files -s Makefile
> 
> The first one is silent, and the latter answers.  On the other
> hand, for a directory, both of these give you the same:
> 
> 	git ls-files Documentation/
>         git ls-files Documentation
> 

As you said above both "Documentation/" and "Documentation" match the existing tracked directory named "Documentation". That is how ls-files works and it is the only sane way. The problem is that I expect that directory entries ending with "/" in .gitignore and .git/info/exclude files are treated in a similar way, i.e. they are being _ignored_ with all the stuff in them, in the same way as directory entries without the ending slash. Unfortunately this is not the case. See this example:

ediap@lespaul ~/tmp $ mkdir repo && cd repo
ediap@lespaul ~/tmp/repo $ git init
Initialized empty Git repository in .git/
ediap@lespaul ~/tmp/repo $ touch a.txt
ediap@lespaul ~/tmp/repo $ git add a.txt
ediap@lespaul ~/tmp/repo $ git commit -m "a file"
Created initial commit 1712595: a file
  0 files changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 a.txt
ediap@lespaul ~/tmp/repo $ mkdir d
ediap@lespaul ~/tmp/repo $ touch d/b.txt
ediap@lespaul ~/tmp/repo $ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       d/
nothing added to commit but untracked files present (use "git add" to track)
ediap@lespaul ~/tmp/repo $ echo "d/" > .gitignore
ediap@lespaul ~/tmp/repo $ git add .gitignore
ediap@lespaul ~/tmp/repo $ git commit -m "ignore"
Created commit 29ebf4d: ignore
  1 files changed, 1 insertions(+), 0 deletions(-)
  create mode 100644 .gitignore
ediap@lespaul ~/tmp/repo $ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       d/
nothing added to commit but untracked files present (use "git add" to track)
But:
ediap@lespaul ~/tmp/repo $ echo "d" > .gitignore
ediap@lespaul ~/tmp/repo $ git add .gitignore
ediap@lespaul ~/tmp/repo $ git commit --amend -m "ignore"
Created commit 43198d4: ignore
  1 files changed, 1 insertions(+), 0 deletions(-)
  create mode 100644 .gitignore
ediap@lespaul ~/tmp/repo $ git status
# On branch master
nothing to commit (working directory clean)

I hope you now understand what I was trying to express in my previous email. :-)

BR, /Adam

-- 
.:.  Adam Piatyszek (ediap)  .:.....................................:.
.:.  ediap@users.sourceforge.net  .:................................:.
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 20 in “Why does git track directory listed in .gitignore/".git/info/exclude"?”
  1. pradeep singh rautelaJan 23, 2008
  2. pradeep singh rautelaJan 23, 2008
  3. Linus TorvaldsJan 23, 2008
  4. pradeep singh rautelaJan 24, 2008
  5. Adam PiatyszekJan 30, 2008
  6. Junio C HamanoJan 30, 2008
  7. Junio C HamanoJan 30, 2008
  8. Adam PiatyszekJan 31, 2008
  9. *Re: Why does git track directory listed in .gitignore/".git/info/exclude"?Junio C Hamano, Jan 31, 2008
  10. gitignore(5): Allow "foo/" in ignore list to match directory "foo"Junio C Hamano, Jan 31, 2008
  11. Jeff KingJan 31, 2008
  12. Junio C HamanoJan 31, 2008
  13. Jeff KingJan 31, 2008
  14. Johannes SchindelinJan 31, 2008
  15. pradeep singh rautelaJan 31, 2008
  16. Junio C HamanoJan 31, 2008
  17. Adam PiatyszekJan 31, 2008
  18. Andreas EricssonFeb 1, 2008
  19. Adam PiatyszekJan 31, 2008
  20. Wayne DavisonJan 23, 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.