0

I have the following configuration in my .gitignore file.

.idea/*
!.idea/inspectionProfiles/Teamcity.xml
!.idea/scopes/teamcity.xml
!.idea/runConfigurations/Watch_Sass_files.xml

It should be ignoring all the files in the .idea directory with 3 exceptions. It doesn't allow me to git add them. I have run git check-ignore on them and that's the message

.gitignore:59:/.idea/* .idea/runConfigurations/Watch_Sass_files.xml

I have even implemented @Matiss suggestion in https://stackoverflow.com/a/14731573/9559251

It seems that you can make a directory exception but not file exceptions e.g. !.idea/runConfigurations/

LazioTibijczyk
  • 1,701
  • 21
  • 48

2 Answers2

3

This should work — unignoring directories ignored with *:

.idea/*
!.idea/inspectionProfiles/
!.idea/inspectionProfiles/Teamcity.xml
!.idea/scopes/
!.idea/scopes/teamcity.xml
!.idea/runConfigurations/
!.idea/runConfigurations/Watch_Sass_files.xml

Could be simplified as (unignore all directories):

.idea/*
!.idea/*/
!.idea/inspectionProfiles/Teamcity.xml
!.idea/scopes/teamcity.xml
!.idea/runConfigurations/Watch_Sass_files.xml
phd
  • 82,685
  • 13
  • 120
  • 165
  • What if I only wanted to make exception to a single configuration file and not the whole directory. Would it work this way? – LazioTibijczyk Jan 30 '20 at 08:48
  • 1
    Initial `.idea/*` ignores all files. `!.idea/inspectionProfiles/` (or `!.idea/*/`) unignores directories but doesn't unignore files so files under `.idea/` are still ignored. Git doesn't track directories, it only track files. So there is nothing to worry. – phd Jan 30 '20 at 11:33
  • 1
    Another approach would be to ignore everything `.idea/*` and force-add a single file: `git add --force .idea/scopes/teamcity.xml`. Tracked files are never ignored even if ignore patterns match. `.gitignore` only ignores untracked files. – phd Jan 30 '20 at 11:34
0

Odds are there's something else going on in your .gitignore that whatever you're using to view and edit it isn't showing you. Trailing white space (including bad line separators), weird character set, something.

Try xxd -g8 -c32 .gitignore (or use your hex dumper of choice, that's mine) and look for differences between what your editor shows you and the per-byte decode.

jthill
  • 55,082
  • 5
  • 77
  • 137