18

I want to ignore the dist folder. So when there is a change in the dist folder, it doesn't appear in the commit

In the .gitignore file, there had exist /dist like this :

.DS_Store
node_modules
/dist

But why when there are changes it still appears?

How can I solve this problem?

3
  • 1
    You should add trailing slash instead dist/ Did you already commit this folder ?
    – Hurobaki
    Jan 2, 2020 at 10:21
  • @Hurobaki It does not work. I have committed this folder before
    – moses toh
    Jan 2, 2020 at 10:31
  • 1
    You have to ˋgit rm -r dist ˋ to tell Git that you don’t want to track it anymore
    – Hurobaki
    Jan 2, 2020 at 10:32

2 Answers 2

58

With Git if you commit a file or folder, Git will continue to track it even if you put it inside your .gitignore. Because .gitignore just prevent untracked files from being added.

To stop tracking you have to remove it from Git index

git rm -r --cached <folder> // git rm -r --cached dist

It will keep the folder on your local but it will not being tracked anymore.

For folder in .gitignore the correct format is dist/ with trailing slash

1
  • Is there any way for it to persist? I have to do it literally every time I make a new build
    – Jojko
    Jul 19 at 10:27
8

Check the format

.DS_Store
node_modules
dist/
2
  • 1
    It does not works
    – moses toh
    Jan 2, 2020 at 10:32
  • 2
    It worked for me, thanks Aug 10, 2020 at 17:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.