0

When I first created my project, I pushed it without adding the node_modules, bin, and obj folders to the gitignore file. Now, after adding them to the gitignore, I'm trying to delete those folders.

Originally, I simply added the folders to the gitignore, and hoped that after pushing, they'd be gone. That obviously didn't work, so I tried the one command I kept finding on every site; git rm -r --cached node_modules.

I ran this command from the root of my project, the solution folder, and even the git folder itself, and in all of them it gave me the same response: fatal: pathspec 'node_modules' did not match any files.

Here's my current gitignore file:

# compiled output
/dist
/dist-server
/tmp
/out-tsc

# dependencies
/node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db

# rm
obj
bin
node_modules

I've probably made some minor, dumb mistake, and in my defense I really haven't worked with git much yet at all..

Thank you for your time and help ^^'

Edit: Someone assumed this post had the answer to my question and closed my question, unfortunately it doesn't, as it's a completely different question.

Edit 2: domiSchenk found a post that actually contains the command I needed and with which I was able to delete my folders worked.

S. L.
  • 31
  • 6
  • You need to pay attention where you put your `.gitignore` file and where the ignored items reside in relation with it. You can have multiple `.gitignore` files in multiple (nested) directories for more granular control over what is ignored in which directory, but you can also get by with using only one, usually in the root folder of your project (the same folder that contains the `.git` folder). – Octavian Mărculescu Apr 25 '23 at 09:50
  • The command you mentioned in the question should be executed in the same folder that contains `node_modules` folder. When you type `dir` in your console (assuming windows - powershell or cmd) you should see the `node_modules` folder in the results list. – Octavian Mărculescu Apr 25 '23 at 09:53
  • @OctavianMărculescu thank you for the tips, I just checked and the gitignore file is in the correct location in relation with the folders, and I was at the correct location in the terminal as well, yet the command still didn't work. – S. L. Apr 25 '23 at 14:05
  • @OctavianMărculescu also, how do I reopen my question? The post linked doesn't have the answers to my question :I – S. L. Apr 25 '23 at 14:09
  • here is a correct link to this problem: https://stackoverflow.com/questions/13541615/how-to-remove-files-that-are-listed-in-the-gitignore-but-still-on-the-repositor – domiSchenk Apr 26 '23 at 12:11

0 Answers0