1

Already tried doing git rm --cached dir/file and it did not work. It only works with the VSCode interface(the source control extension).

I'll add a file to .gitignore

git add . 
git commit -m "trying to make .gitignore work"
git push

And no success...

I already visited all the other duplicates of this one on Stackoverflow.

I am using WSL (Windows Subsystem for Linux) on VScode.

The file remains on my git repo even if its marked on gitignore...

The file name on VScode interface shows up a little gray indicating that .gitignore worked...

1 Answers1

1

git rm --cached dir/file should work, provided you do a commit and a push.

Note that the --cached option means the file remains on your disk.
And that it is removed (and ignored) only for this new commits (and the future ones), not the past commits.

Also check if, locally, the .gitignore rule applies with:

git check-ignore -v -- dir/file

No output means: it is not ignored.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you so much for your feedback. I tested that. You were right. There is a folder named node_modules which is correctly ignored. So I sent git check-ignore -v -- node_modules and it sent the output correctly, but not on the case mentioned. It's strange because using the extensions it worked good. I mean, a file goes to github and then after that i .gitignoreit, it goes away from the git repo(using the extension). But when using the command line the file remains on the repo. As if the interface uses more command lines than doing it manually... Does this makes any sense?? – Augusto Camargo May 02 '22 at 02:26
  • Also I must mention that the folder i'm trying to ignore has a complicated name.... beucase i'ts on windows by WSL... The relative path goes like this: CUsersCUsersE5262012CORESAppDataRoamingnpm-cache\node-sass\7.0.0\linux-x64-93_binding.node Now i kinda feel like I should have mentioned this before... lol – Augusto Camargo May 02 '22 at 02:27
  • 1
    @AugustoCamargo That looks like an absolute path. But if it is a relative path, use `--` after `git rm`: see https://stackoverflow.com/a/60213170/6309 – VonC May 02 '22 at 07:05