2

I've added a several entries as below to my .gitignore

.env
.env.production
.env.staging
.env.uat

Now what I'm confused is it doesn't seem to be taking effect, both visually on VS Code nor when I run git status, it doesn't list all the files that I'm expecting to be removed/deleted? I must've missed something obvious but I couldn't spot it

enter image description here

Visual on VS Code as below:

enter image description here

Yushin
  • 1,684
  • 3
  • 20
  • 36
Isaac
  • 12,042
  • 16
  • 52
  • 116
  • Show the corresponding `git status` you're having problems with. `.gitignore` does not remove anything, it just removes them as long as they are unstaged/untracked from `git status`. – zerkms Jul 11 '19 at 02:52
  • @Zaya yes I've tried `*.env` as well as `.env*` – Isaac Jul 11 '19 at 02:54
  • @zerkms: Do have a look on updated question – Isaac Jul 11 '19 at 02:54
  • 1
    your screenshot looks okay, what's your problem again? – zerkms Jul 11 '19 at 02:54
  • @zerkms: From VS Code, I'm expecting if the entry added to `.gitignore`, VSCode will show a light grey on the file as shown above screenshot. At the same time, unstaged changes I'm expecting several of these file being listed as deleted right? – Isaac Jul 11 '19 at 02:57
  • Or actually i understood wrongly? – Isaac Jul 11 '19 at 02:58
  • "several of these file being listed as deleted right?" --- nope, `.gitignore` does not delete anything, it just would ignore them from `git status` if you have not tracked/staged them before. As long as a file is tracked - `.gitignore` does not affect it in any way. – zerkms Jul 11 '19 at 02:59

1 Answers1

7

From VS Code, I'm expecting if the entry added to .gitignore, VSCode will show a light grey on the file as shown above screenshot.

No: you need to remove them from Git first:

git rm --cached -- .env;      
git rm --cached -- .env.*                
               

Then the .gitignore would take effect, and VSCode would reflect the new state of those files.

Kampouse
  • 9
  • 4
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Indeed after running the code it's reflecting correctly. I was confused coz I tried on other files was reflecting immediately, but not this 4 files – Isaac Jul 11 '19 at 07:17
  • @Isaac if those "other files" were not tet added to Git index, then VSCode would reflect their new ignored states immediately. – VonC Jul 11 '19 at 07:48