7

My .gitignore file reads as follows:

build/
glucosia.xcodeproj/
!glucosia.xcodeproj/project.pbxproj
core-plot/framework/build
core-plot/framework/CorePlot-CocoaTouch.xcodeproj/
!core-plot/framework/CorePlot-CocoaTouch.xcodeproj/project.pbxproj
.DS_Store
Classes/.DS_Store

Strangely, glucosia.xcodeproj/project.pbxproj is not ignored, as I would expect.

But, core-plot/framework/CorePlot-CocoaTouch.xcodeproj/project.pbxproj is still being ignored.

Any ideas?

Thanks!

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Jacko
  • 12,665
  • 18
  • 75
  • 126
  • 1
    Is `glucosia.xcodeproj/project.pbxproj` by any chance already part of the repository? – Alan Haggai Alavi Feb 04 '10 at 03:34
  • 1
    glucosia.xcodeproj/project.pbxproj is already tracked, but core-plot/framework/CorePlot-CocoaTouch.xcodeproj/project.pbxproj is not. My solution is to add the second file to the repo. So, it seems that the ! notation only applies to tracked files. This wasn't clear from the docs – Jacko Feb 13 '10 at 02:02

2 Answers2

6

As mentioned in the gitignore man page:

A gitignore file specifies intentionally untracked files that git should ignore

If glucosia.xcodeproj/project.pbxproj (as suggested by Alan in the comments) is already tracked, you need to remove it from the cache, and then the gitingore directive will take effect.

git rm --cached glucosia.xcodeproj/project.pbxproj

If the file was already committed, see this SO answer (git commit --amend to remove it from the latest commit)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
5

I had the same problem, but a different solution. If you ignore a directory but not a file within it, it will not work. You have to ignore a directory's files.

This doesn't work:

conf/
!conf/config.json.orig

This will work:

conf/*
!conf/config.json.orig
Brad
  • 159,648
  • 54
  • 349
  • 530
  • I've got a similar issue but the directory I'm ignoring has several layers in it and the file I want to un-ignore is a few layers deep. My .gitignore looks something like this: src/sys !src/sys/lib/perl5/myLib.pm – schultzter Nov 28 '13 at 05:07