Wizard Wizard - 3 months ago 13
Git Question

Git ignore all files in directory but not directory

Now I was added in .gitignore

image/cache/*


Now git ignore all cache directory and I can't add this directory to git. Question is how to ignor image/cache/ files but, not directory ?

Answer

While the previous answer is pretty correct, this might be helpful:

You can specify a subdirectory of an ignored directory to not be ignored. eg: Ignore cache, but not 'excluded' in cache:

!image/cache
images/cache/*
!images/cache/excluded

You can also force add ignored files using:

git add path/to/file --force

But as previously stated, this only works on files, not directories.