How to unignore some files or dirs in git?
Posted on In Software, TutorialI set up rules to ignore all files under git by adding a .gitignore like
*
But how to unignore some files or dirs in git? For example unignore all files under
./bin/tool1/
under the git repository.
You can use patterns with ! as the prefix to “unignore” files. From gitignore man page:
An optional prefix “!” which negates the pattern; any matching file excluded by a previous pattern will become included again.
Please note that it is not possible to re-include a file if a parent directory of that file is excluded because Git doesn’t list excluded directories for performance reasons. So all the parent directories of the unignored files should be unignored too.
For the above example, the .ignore file could be
* !/bin /bin/* !/bin/tool1 !/bin/tool1/*