Search code examples
gitgitignore

.gitignore un-ignore .cc files


I have a .gitignore file in which I ignore everything, and then un-ignore specific files and directories. However, one part of it doesn't seem to work.

/*

!.gitignore
!Makefile
!include/
!src/
!test/*.cc

**.swp

New *.cc files in the test directory don't appear in git status.


Solution

  • The /* rule causes the test directory to be ignored, so git never descends into it at all. Therefore your !test/*.cc rule has no effect.

    You need a sequence of alternating and overlapping rules like this: ignore everything, then un-ignore test, then ignore everything under test, then un-ignore the .cc files within test.

    /*
    !test
    test/*
    !test/*.cc