Why are these files not ignored by git?
Asked Answered
D

2

7

My .gitignore file contains these lines :

 xcuserdata/**/*
 !xcuserdata/**/xcschemes/*

But the following file is still tracked /MyApp/MyApp.xcodeproj/xcuserdata/colas.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist

Why is it so? How can I fix that?

PS: If I had MyApp.xcodeproj/xcuserdata/colas.xcuserdatad/xcdebugger, the files are ignored. But I don't understand why it does not ignore them without this "hack".


EDIT 1

Contrary to what is said in one of the answer, the pattern

 xcuserdata/**/*
 !xcuserdata/**/xcschemes/*

works !!! I mean, the files under /xcschemes are tracked.

See also the post Git ignore file for Xcode projects, where I get this .gitignore file.

EDIT 2

My Git version is 1.8.3.4 (Apple Git-47).

EDIT 3

When I git check-ignore this file, here is what I get

  fatal: Not a git repository (or any of the parent directories): .git

But the fact is that a parent directory is a git directory...

EDIT 4

When I git check-ignore --no-index -- this file, here is what I get

[MT] PluginLoading: Required plug-in compatibility UUID 37B30044-3B14-46BA-ABAA-F01000C27B63 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/XcodeSnippetsHelper.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2014-02-10 10:03:50.856 xcodebuild[1496:d07] XcodeColors: load (v10.1)
2014-02-10 10:03:50.859 xcodebuild[1496:d07] XcodeColors: pluginDidLoad:
fatal: Not a git repository (or any of the parent directories): .git

EDIT 4bis

From the root folder :

  • if I don't use the no-index option, there is no reply to git check-ignore.

  • if I use the no-index option: I get the error error: unknown option 'no-index'...

Strange ;-!

Daffi answered 8/2, 2014 at 8:3 Comment(4)
What git version are you using?Eous
ok, I know there were some recent fixes around '**' pattern, so it would be interesting to see if the issue persists with a 1.8.5.x version.Eous
Can you try a git check-ignore --no-index -- yourFile? It can be used to diagnose which paths that should have been ignored have been mistakenly added to the index.Eous
Adn try to use git check-ignore (with or without the --no-index option) from the root folder of your git repo, with the full path of the file: cd /MyApp/MyApp.xcodeproj ; git check-ignore -- xcuserdata/colas.xcuserdatad/xcdebugger/Breakpoints.xcbkptlistEous
E
6

First, you can do a git check-ignore (git 1.8.3.3+) to see what rule is ignoring your file (assuming it wasn't in the index in the first place)

Second, read ".gitignore exclude folder but include specific subfolder":

It is not possible to re-include a file if a parent directory of that file is excluded. (*)
(*: unless certain conditions are met in git 2.8+, see below)
Git doesn't list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

So the file of xcschemes wouldn't be un-ignored anyway.
You needed to ignore parent folder per parent folder.
But a better approach is to ignores files only, and then exclude the folder:

xcuserdata/**
!xcuserdata/**/
!xcuserdata/**/xcschemes/**

Remember:

You need to exclude folders from the gitignore rules before being able to exclude files.


Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

However:

The directory part in the re-include rules must be literal (i.e. no wildcards)

So that wouldn't have worked here anyway.

Eous answered 8/2, 2014 at 8:13 Comment(3)
I tried to change to your suggestion. The file still appears in SourceTree as "not tracked"... Thanks for your help!! I also did the git check-ignore (see my edit).Daffi
I tried from the root folder, and with the no-index option. The results are different. If you have any clue of what's going on...Daffi
@Daffi regarding the error message with the --no-index option, is it possible your version of Git is a bit too old to support it? Because it was introduced in 1.8.5 only.Eous
G
0

Adding file names to .gitignore helps prevent you from adding the files unintentionally. If you do something like git add . to add a folder full of files to the repository, the files (or filetypes) ignored in .gitignore will not be added. They would have to be added by using the -f flag with the git add command. It will not change anything if the files are already tracked.

You can stop tracking the files by using the answer to the question: Remove a file from a Git repository without deleting it from the local filesystem

edit: After rereading the question a few more times, I think you may be having roughly the same issue that was addressed in this answer: .gitignore - ignore any 'bin' directory

Gilolo answered 8/2, 2014 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.