3

I've referred to many related posts here and none of them work -- my public/images folder just not greying out like my node_modules folder does in my VS Code. The following is my folder structure:

project-folder
  |--.gitignore
  |--node_modules
  |--public
  |----images

So my .gitignore file is at the same level at my public folder. I saw the node_modules is being ignored (and greyed out) in the .gitignore file like this:

node_modules/

So I tried:

public/images/

but no luck. I also tried all of the following but none turn the images folder into grey:

 1. /public/images/
 2. /public/images
 3. public/images
 4. public/images/
 5. images
 6. images/

I also tried creating another .gitignore file under the public folder and follow the same way my node_modules is being ignored but still not working: images/. I heard that the git rm --cached may sometimes remove files from file system, so I dare not try it. Can someone give me a better advice for this? Thanks!

Antonio Ooi
  • 1,601
  • 1
  • 18
  • 32
  • 2
    You need to remove the files from the cache first as it has already been added to the repo. Or else just adding your directory to gitignore won’t work as it only works for for file that hasn’t been added. – LalitaCode May 24 '20 at 06:30
  • Did you tried `public/` – chirag soni May 24 '20 at 06:30
  • @chiragsoni : No, I want to keep my `public` folder. It some other folders and files that I need, e.g. `*.js`, `*.css` etc. I just want to ignore `images` folder. – Antonio Ooi May 24 '20 at 06:33
  • try with `/images` and let me know – chirag soni May 24 '20 at 06:34
  • Still the same. – Antonio Ooi May 24 '20 at 06:37
  • If your `.gitignore` is at `public` folder then you can use `/images/` to ignore the `public/images` folder. Also make sure you don't have `.gitignore` inside `public/images` folder. – Harish ST May 24 '20 at 06:44
  • @AntonioOoi Did it worked?? – chirag soni May 24 '20 at 06:53
  • @HarishST : Still the same not working. @chiragsoni : Already answered you earlier, not working. @LalitaCode : `git rm -r --cached images` works perfectly by running the command at the `public` directory level. No files have been removed from the file system, only the git index. Thanks! – Antonio Ooi May 24 '20 at 07:36
  • Create a `.gitignore` file inside image folder and add `*` to it. Check whether this works or not – Harish ST May 24 '20 at 07:37
  • @1615903 : Yes, but in the beginners' perspective like me, they may not even know that the files or folders that previously tracked have to be **"forgotten** and they just want the git not to track the files or folders by turning them into **grey color** in VS Code. I feel that it's good to keep this question so that people who are at the same knowledge level as me can find the question right for them. I appreciate your offer for the same answer though. Thank you. – Antonio Ooi May 25 '20 at 06:04
  • Marking a question as duplicate does not remove it, it just places a banner on top pointing future visitors to the other question. – 1615903 May 25 '20 at 06:49
  • Fine, then I'll answer 'Yes' to your question, but in my opinion, unless the question title does not serve different perspective and almost identical, otherwise it's good to leave the diverse perspectives of questions here and lead the solution seekers to the best, clearest, and most insightful answer, else similar "duplications" may just come back again and again due to different perspectives and scenarios. Also, it's unwise to change the question to almost close to the answer -- this is expert's perspective, not beginners' perspective. Thank you. – Antonio Ooi May 25 '20 at 07:17

1 Answers1

5

Solved the problem by issuing git rm -r --cached images at the public directory level. No physical files have been removed from the file system except the git index. The working pattern in the .gitignore file at the project root folder is:

public/images/

After issuing the above command, my images folder under public has been greyed out in my VS Code. Thanks to @LalitaCode for giving me the courage to try git rm --cached and thanks to those who were trying to help as well!

Antonio Ooi
  • 1,601
  • 1
  • 18
  • 32