I have a .gitignore
file in root directory
# Ignore everything in this directory
*
# Except this file
!.gitignore
!portal
!app.js
!node_modules
!README.md
All exceptions are working except for portal
. I added portal
later to this file (It wasn't there from the beginning). But git add .
doesn't add that folder and its content. What is the problem?
CodePudding user response:
Git ignore patterns are recursive by default, so *
matches not just files in the root directory, but also files in subdirectories. To have rules apply only to the current directory you'll want to prepend /
.
# Ignore everything in this directory
/*
# Except this file
!/.gitignore
!/portal
!/app.js
!/node_modules
!/README.md
Tip: git check-ignore
is a handy tool to have on hand when you're having trouble with your .gitignore
rules. It can tell you what files are being excluded and, with the -v
option, the origin of the exclusion rules.