Search code examples
gitgitignore

.gitignore file is not ignoring a certain file


This is my .gitignore page

.DS_Store
node_modules
/dist


# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

#dbconnector
dbconnector.js

And it isn't ignoring the dbconnector.js file who is on that specific location

I already tryed this three lines as replacement for dbconnector.js but it doesn't worked

server/dbconnector.js
./server/dbconnector.js
**/dbconnector.js

Solution

  • Watch for spurious characters in and around the filename in .gitignore. Do not forget to add newline after the name.

    If the file is already tracked, use git rm --cached server/dbconnector.js (precise pathname for each file). (See also this answer and around there.)

    I suppose other files are well git-ignored, so there is no need for a test with a new file, like echo hello >> hello; echo hello >> .gitignore; git status. Thought it does not hurt to take the test.