12

I want to create repository for my Magento project. There are lots of folders and files in root directory and I change time to time only one folder: app/code/local/

Everything else I want to ignore. But.. can't. My .gitignore file:

*
!app/code/local/
!app/code/local/*

Then when I try to add folder to repo I get an error:

git add app/code/local/Mds/

The following paths are ignored by one of your .gitignore files:
app
Use -f if you really want to add them.
fatal: no files added

Can anyone please help with this?

Kendall Hopkins
  • 43,213
  • 17
  • 66
  • 89
user718085
  • 123
  • 1
  • 4

3 Answers3

17

Try below to ignore like you need:

/*
!/app/
/app/*
!/app/code/
/app/code/*
!/app/code/local/

The following discussion was helpful: http://git.661346.n2.nabble.com/negated-list-in-gitignore-no-fun-td1675067.html , especially the following from Linus:

That's by design. You've chosen to ignore those directories; they match "*" themselves. Thus, 'git add .' doesn't descend into them looking for files.

So basically, for each level you have to go in, unignore that folder, and ignore contents within that folder.

user487772
  • 8,800
  • 5
  • 47
  • 72
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • I cant believe i does not work. I even create the new folder under app/code/local but the error is the same... – user718085 Apr 21 '11 at 19:33
  • you must be doing something different. After my edit I realized my answer is now same as @Nick so two of us cannot be wrong :) . And I tested it out in a dummy repo! – manojlds Apr 21 '11 at 20:09
  • Pal it is working =)) Thank you very much. How did you get it) – user718085 Apr 22 '11 at 11:05
  • Like in my editted response, Linus's response in the link I had given helped me figure out how Git is handling it. – manojlds Apr 22 '11 at 11:06
0

According to the documentation:

"It is not possible to re-include a file if a parent directory of that file is excluded."

For example, if you had already been working with the repository and told Git to ignore the parent directory, made some commits, and then went back and tried to allow some sub-directory of the excluded directory, it will not include that sub directory even if your .gitignore file is correct. To get around this, you need to force add it (with the -f flag):

git add -f {file}

Once this has been done, subsequent changes will be tracked.

Kyle Falconer
  • 8,302
  • 6
  • 48
  • 68
0

Is this .gitignore in the root of the repo?

Try this:

/*
!/app/code/local
Nick Veys
  • 23,458
  • 4
  • 47
  • 64