Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git is ignoring a file in a subdirectory

Tags:

git

gitignore

I have a .gitignore file that looks like this:

*
!/src
!/resources
!/.gitignore
!/package.json
!/tsconfig.json
!/README.md

I added a file to a subdirectory in the src folder src/config/mongo.ts. However, when I try to add the file it doesn't get added:

git add -A

I have tried modifying the second line to each of the following:

!/src/
!/src/*
!/src/**/*

However it still doesn't add the file.

I have also tried adding the file directly:

git add src/config/mongo.ts

But I get the following message:

The following paths are ignored by one of your .gitignore files: src/config/mongo.ts

git status only shows that the .gitignore file has been changed. Not sure what to do to get this working.

I would like to:

  • First exclude everything *
  • Then include everything in the src directory (and its subdirectories)
  • Then include everything in the resources directory (and its subdirectories)
  • Then include the listed root files
like image 347
Get Off My Lawn Avatar asked Oct 22 '25 15:10

Get Off My Lawn


1 Answers

This one is a tricky one, took me forever to figure out when I originally ran into it.

You just need to soften the initial exclusion slightly:

/* # instead of just *
like image 96
LightBender Avatar answered Oct 25 '25 04:10

LightBender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!