Our current git setup works on a whitelist basis, so everything is ignored by default, and we then include directories as needed. This worked fine for a new repository, but is starting to cause issues now that we have a bunch of tracked/untracked files.
Here's an example of our .gitignore:
*
!/example.txt
!/example2.txt
I'm now trying to add a file to git that exists in ignored folder a, the file's path is: /a/b/c/file.txt. My question is, how can I go about not ignoring this file, but ignoring everything else in the /a folder?
So far I've found that adding this to the .gitignore works:
!/a/
!/a/b/
!/a/b/c/
!/a/b/c/file.txt
However, it just seems a bit messy. I originally thought that I'd be able to get away with just having !/a/b/c/file.txt in the .gitignore, but that doesn't seem to work for some reason?
Also for reference, I'm having to run git rm --cached -r . and git add . to get .gitignore changes to take effect.
Any help would be much appreciated - thanks!
I think you need to add
!*/. This whitelists directories. Here is a sample ignore..Other options is to blacklist everything in the directory and whitelist the one file