0

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.

SU3
  • 5,064
  • 3
  • 35
  • 66

1 Answers1

2

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
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
  • I guess a directory doesn't come along for the ride with the pattern that can't be matched without it. – SU3 Jun 23 '17 at 09:39