From: Jeff King <peff@peff.net>
To: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
Cc: "alf.clement@gmail.com" <alf.clement@gmail.com>,
"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: .gitignore issue
Date: Wed, 21 Jan 2026 16:03:12 -0500 [thread overview]
Message-ID: <20260121210312.GA723458@coredump.intra.peff.net> (raw)
In-Reply-To: <SL2P216MB1885CE309BDBA65860D8762FA296A@SL2P216MB1885.KORP216.PROD.OUTLOOK.COM>
On Wed, Jan 21, 2026 at 06:51:02PM +0000, Pushkar Singh wrote:
> This is expected behavior.
> When a directory matches an ignore rule, Git stops descending into it entirely. The pattern
>
> backup_STOCKS*/
>
> matches directories starting with backup_STOCKS, and once Git prunes traversal at that level, similarly prefixed paths can disappear from git status, which is why backups/ no longer shows up.
>
> This isn’t a bug, but a result of how ignore patterns and directory pruning work.
I found this explanation confusing: surely we would never match
"backups/" itself via a pattern like "backup_STOCKS*". And I'm not sure
what you mean by "similarly prefixed paths".
But what I suspect is happening here (and what you were trying to get
at) is that Git will not report an empty directory as untracked. And one
that consists only of ignored files is considered empty.
So a simpler example:
git init
mkdir subdir
git status
At this point "git status" will report nothing, because there are no
files at all.
If we add a file:
echo foo >subdir/file
git status
Now "subdir/" is untracked (unless you use --untracked-files=all, in
which case we actually list "subdir/file" itself).
And if we ignore it like this:
echo subdir/file >.gitignore
git status
Now subdir/ is no longer reported. And we get the same effect with an
un-anchored top-level pattern, which also matches in subdirectories:
echo file >.gitignore
git status
We can't know for certain this is what's going on because Alf didn't
show us what's in the backups/ directory, but one imagines it is also
full of backup_STOCKS_* directories.
> If you want to ignore only those directories and nothing else, anchoring the pattern helps:
>
> /backup_STOCKS_*/
>
> You can also verify which rule is responsible with:
>
> git check-ignore -v backups/
So yes, both of these are very good advice.
-Peff
next prev parent reply other threads:[~2026-01-21 21:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 18:51 .gitignore issue Pushkar Singh
2026-01-21 21:03 ` Jeff King [this message]
2026-01-21 21:09 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2026-01-21 18:32 Alf Clement
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=20260121210312.GA723458@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=alf.clement@gmail.com \
--cc=git@vger.kernel.org \
--cc=pushkarkumarsingh1970@gmail.com \
/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