9

I want to ignore a dist folder at top level of my project, but then I have another dist folder inside my project for my styles, which I want to keep. So keeping a dist in .gitignore causes both of them to be ignored. What is the correct way to handle this.

Vivek V Dwivedi
  • 2,510
  • 2
  • 28
  • 39
  • Possible duplicate of [How to exclude file only from root folder in Git](https://stackoverflow.com/questions/3637660/how-to-exclude-file-only-from-root-folder-in-git) – timolawl May 24 '17 at 10:26

3 Answers3

20

If you have dist in your ignore file, all files and folders named dist in the same directory as the ignore file and in all subdirectories recursively are ignored.

If you have dist/ in your ignore file, all folders but not files named dist in the same directory as the ignore file and in all subdirectories recursively are ignored.

If you have /dist in your ignore file, all files and folders named dist in the same directory as the ignore file but not in any subdirectories are ignored.

If you have /dist/ in your ignore file, the folder but not file named dist in the same directory as the ignore file but not in any subdirectories are ignored.

So change dist to /dist/ in your root folder .gitignore and you will be fine.

Alternatively if you can also force-add files in a dist folder, because as soon as a file is tracked, .gitignore is not effective anymore as it is only applied on untracked files.

Vampire
  • 35,631
  • 4
  • 76
  • 102
2

put a slash at the start in your .gitignore file to only ignore the one in that folder

/dist
Vampire
  • 35,631
  • 4
  • 76
  • 102
Alex028502
  • 3,486
  • 2
  • 23
  • 50
-1

Inside your project

$ git rm --cached /c/projects/yourApp/dist -r
IsozWorld
  • 59
  • 4
  • 1
    Hello! This question already has an accepted answer. Before looking at answered questions, please consider looking at [unanswered ones](https://stackoverflow.com/questions?tab=Unanswered) first. If you do, however, have something to add to an answered question, please consider reading other answers thoroughly. – PajLe Jun 08 '20 at 01:46