The gitignore that ate a source file
CI failed with this:
error during build:
Could not resolve "./lib/router.svelte" from "src/App.svelte"
The file existed. It was on disk, 140 lines, finished, and imported from five places. The commit that broke the build even described it in its message. But the file wasn't in that commit. It had never been committed at all.
The .gitignore had eaten it, and every check on the author's machine
agreed that everything was fine.
A forgotten file is a loud bug. You notice it in the diff, or at the
push, or when someone asks where it is. This was the quiet kind: the
file was excluded, and the tool that would have told us was the tool
that had been told not to look. git status was clean because the
file was ignored. That's the whole problem in one sentence.
A pattern older than the problem
The project was a small guide site with a couple of thousand
database-backed pages: a Python backend, a Svelte frontend and deploy
config, all in one repo. Its .gitignore came from GitHub's stock Python
template on the repo's first day. The template has a block for
old-style Python packaging:
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
Those are build artifacts of a setup.py-era project. When distutils
builds, it drops output into lib/, parts/, var/ and wheels/
at the project root, next to setup.py. The template assumes that
flat layout, and its patterns are written the flat way, with no leading
slash.
In a gitignore, that choice has a precise meaning. A pattern whose only
slash is the trailing one, like lib/, matches a directory of that name
at any depth. The template means "the lib/ that distutils makes at
the root". What it says is "every directory named lib/, anywhere,
forever".
This repo was not flat. It had backend/, frontend/ and sys/ at the
top. None of the template's assumptions held, and nothing complained,
because an ignore pattern that matches nothing costs nothing. The line
sat there, wrong from the start, for 345 days: a landmine with no
foot traffic, waiting for someone to create a lib/ folder anywhere
below the root.
In August 2026, someone did. The frontend needed a router, and the
router went in frontend/src/lib/, because that's where Svelte projects
keep shared code. The pattern reached down three levels and took it.
The morning it bit
The commit that added the router described it in detail: about 140
lines, covering what nine routes need. The file wasn't in the commit.
git add -A had skipped it without a warning, because it was ignored.
The message described work the tree didn't contain.
An unrelated change, pushed right behind it, inherited the broken build, because CI builds the frontend and the frontend imported the missing file.
CI runs on a machine that has no copy of anyone's working tree. It tried the build and said the only true thing anyone heard all morning: the module isn't there.
Eight minutes after the first bad commit, the router was committed and the pattern fixed. That speed is what CI is for. The failure showed up on the only kind of machine that could see it, which is any machine that isn't yours.
But put the two numbers side by side: 345 days armed, 8 minutes to detect. Fast detection didn't defuse anything. What defused it was reading the pattern and asking what it meant. That could have happened on any of those 345 days, and never did, because the pattern never produced a single signal.
There's an irony in what got swallowed. The router was itself a fix for
an invisibility bug. It replaced a hash-mode router, whose URLs
(/#/blocks/stone) never send a path to the server, so to a search
crawler the site's ~2,265 database-backed pages were all one URL. The
router made those pages visible to the outside world. The gitignore made
the router invisible to version control. One morning, two invisibility
bugs, and one was hiding the fix for the other.
What the silence was made of
Three local signals, all green, all green for the same reason:
git add -Askips ignored files without a word. To git that isn't an error. It's the instruction. Staging is the one step where a human might notice a file is missing, and it was the step that had been told the file didn't exist.- The local build worked. The file was on disk. Vite resolved
./lib/router.svelteagainst the working tree and never asked where it came from. Every local build passed because of the exact state that wasn't being shared. git statuswas clean. This is the irony the whole thing rests on.git statusexists to point out files you haven't added, and it stayed quiet because.gitignoretold it to. The safety check wasn't bypassed. It was configured. "Works on my machine" is usually an excuse. Here it was the literal mechanism: the working tree was the machine-specific state, and nothing outside it could see the file.
The two commands that name it
git check-ignore -v takes a path and tells you which rule ignores it:
file, line number and pattern.
$ git check-ignore -v frontend/src/lib/router.svelte.ts
.gitignore:13:lib/ frontend/src/lib/router.svelte.ts
That one line is the whole diagnosis. Not just "this file is ignored",
but the line number of the rule doing it, which points straight at the
bare lib/ and the template it came from. Without -v you get the path
and a shrug. With it, you get the line to fix.
git status --ignored is the periodic audit. It lists everything being
excluded, so the ignore set becomes something you look at rather than
something you assume:
$ git status --ignored --porcelain | grep '^!!'
.ruff_cache/
backend/.venv/
backend/__pycache__/
frontend/dist/
frontend/node_modules/
...
Most of that list is the rules working as intended. The value is that a source file hiding among the caches and virtualenvs becomes visible: one glance at an explicit list, instead of an absence you have to reason your way to.
Then, after the fix, the sweep: run the old patterns against every path in the tree, and count.
One match out of 68 tracked paths. The sweep is what turns "we fixed the one we noticed" into "there was only the one". That's the difference between an anecdote and a measurement.
The fix, and what it deliberately didn't fix
The fix anchors six of those patterns to the root with a leading slash:
/lib/
/lib64/
/parts/
/sdist/
/var/
/wheels/
It leaves dist/ unanchored on purpose, because frontend/dist is a
build artifact and should stay ignored. That asymmetry is the sign the
fix was read rather than pasted. Anchoring the whole block would have
been one sed away, and it would have quietly un-ignored the frontend's
build output, trading one silent exclusion for another. A comment on the
block now explains all of this, so the next person to read line 13
doesn't have to work it out again.
The template's patterns weren't wrong in general. They were written for a layout this repo doesn't have, and gitignore's matching rules turned "wrong for this layout" into "matches folders three levels deep" without anyone deciding anything.
That's why ignore rules are worth treating as code. They run on every
git add, their scope is part of their meaning, and they fail silently
by design. A pattern is an assertion about your tree. This one described
a flat Python project, in a repo that wasn't one, for 345 days.
The short version
- When CI can't find a file you can see, run
git check-ignore -von it before anything else. - Every so often, run
git status --ignoredand actually read the list. lib/means everylib/folder, at any depth./lib/means only the one next to the.gitignore. Anchor anything that should only match at the root.- When a check is green, ask one question: is it quiet because everything is fine, or because something told it to be?
Three notes on failures whose only signature is silence:
- Five ways to fail without an error message: five bugs, one fix, and not one error message between them.
- The gitignore that ate a source file (this note): the silence that was manufactured. The tool that would warn you is the one told not to look.
- The carriage return that breaks the deploy, not the diff: the invisible byte, harmless or fatal depending on who reads it.