3

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
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338

2 Answers2

3

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 *
LightBender
  • 4,046
  • 1
  • 15
  • 31
2

src folder and its subdirectories are being ignored by git

if you want to add specific file. try

git add --force <file-path>

or try these lines in gitignore

/*
!/src
/src/*
!/resources
!/.gitignore
!/package.json
!/tsconfig.json
!/README.md
!/src/config
Anurag Meena
  • 166
  • 2
  • 4