LD
Change your colour scheme

TIL: Including subfiles of ignored directories

Published:

Okay that title is a bit of a mess. Here’s the problem, you have a directory that looks like this:

- app.ts
- scripts
- file.sh
- anotherfile.sh
- build.js
- node_modules

Previously I didn’t want to upload anything in scripts, however now I’ve added build.js and I would like that uploaded.

My .ignore looks like this right now:

node_modules
scripts/

I initially thought that just adding an exception for the file would work:

node_modules
scripts/
!scripts/build.js

But nope! That doesn’t work. At first I thought it was to do with specificity, but reordering had no effect either.

It turns out, what I actually needed was:

node_modules
scripts/*
!scripts/
!scripts/build.js

This means I exclude everything inside the scripts directory, but it still allows me to explicitly include my build.js file.

About the author

My face

I'm Lewis Dale, a software engineer and web developer based in the UK. I write about writing software, silly projects, and cycling. A lot of cycling. Too much, maybe.

Responses