4

In my .gitignore file, I was ignoring a directory like this:

var

Then I realized I want to track var/package and all its contents. So, I've added that exclusion to gitignore. I've tried many combinations, but have settled on the following for what seems to be logical, especially from other discussions here.

!var/
var/*
!var/package
!var/package/
!var/package/*

But whenever new files are written to var/package, they are not detected. They are added if I --force them specifically, but not through usual procedures such as git add .

Is there a command I need to be issuing to reset .gitignore to now finally pick up the new gitignore instructions? Am I missing something?

Community
  • 1
  • 1
Joe Fletcher
  • 2,133
  • 4
  • 28
  • 33

1 Answers1

8

Remove anything about var from .gitignore. Create a var/.gitignore with the contents:

/*
!/package

You will obviously need to git add -f var/.gitignore but after that all should be well.

another option is, in your top level .gitignore, say:

/var/*
!/var/package

If either do not work, please type find . -name .gitignore | xargs egrep . and cat .git/info/exclude and let us know what it returns.

Seth Robertson
  • 30,608
  • 7
  • 64
  • 57
  • 1
    Thanks, Seth! Neither of those originally worked, which led me to your troubleshooting "find" step, which made me realize the problem. I was using a catchall .gitignore from GitHub and something in there caused this. I removed all the stuff except for my own ignores and then both methods you mentioned worked. – Joe Fletcher Jul 19 '12 at 16:33
  • @Seth what's the difference between with and without the `/` before the `var` – toolchainX Jan 22 '13 at 08:54
  • 5
    @toolchainX: Leading / means that the path is rooted at the current directory. "/var" means ignore the file/directory in the current currently named "var". "var" means ignore any file/directory named "var" in this directory or any child directory. And to be complete "var/" means ignore any directory named "var" in this or any child directory. "/var/" does what you might hopefully suspect. – Seth Robertson Jan 23 '13 at 02:16