Vivek V Dwivedi
Vivek V Dwivedi

Reputation: 2615

ignore a particular folder only in .gitignore but allow other folders with same name to be checked in

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.

Upvotes: 11

Views: 4588

Answers (3)

IsozWorld
IsozWorld

Reputation: 59

Inside your project

$ git rm --cached /c/projects/yourApp/dist -r

Upvotes: -1

Alex028502
Alex028502

Reputation: 3814

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

/dist

Upvotes: 2

Vampire
Vampire

Reputation: 38649

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.

Upvotes: 21

Related Questions