在Mac OS X上,针对带有空格的目录的git ignore

7

我正在尝试向我的.gitignore文件中添加一些模式,以忽略Xcode生成的*.mode1v3和*.pbxuser文件。然而,我的应用程序名称中有一个空格,所以我想要忽略的文件位于Foo Bar.xcodeproj/目录中。添加这些模式的变体似乎不起作用:

*.mode1v3
Foo Bar.xcodeproj/
Foo Bar.xcodeproj/*.mode1v3
Foo Bar.xcodeproj/username.mode1v3

应该使用什么样的.gitignore模式?

2个回答

4
据我所知,空格并没有特殊的处理方式;无论是《Pro Git》、《gitignore(5)》还是《fnmatch(3)》都没有提到它们。不过,第一个模式*.mode1v3已经足够了;没有斜杠的模式将应用于所有子目录。如果您想要针对特定子目录添加额外的忽略模式,请在该目录中放置一个专用的.gitignore文件即可。

你说得对。我有一个新手时刻,我期望被列入.gitignore的文件会被忽略掉。但是因为它们已经被检查过了,所以并不是这样的情况。这篇文章帮助我搞清楚了:http://www.gitready.com/beginner/2009/03/06/ignoring-doesnt-remove-a-file.html - pmc255

2

你尝试过使用反斜杠转义文件夹或文件名中的空格吗?

*.mode1v3
Foo\ Bar.xcodeproj/
Foo\ Bar.xcodeproj/*.mode1v3
Foo\ Bar.xcodeproj/username.mode1v3

此外,这些文件是否已被Git跟踪?根据man gitignore的说明:
A gitignore file specifies intentionally untracked files that git should ignore.
Note that all the gitignore files really concern only files that are not already
tracked by git; in order to ignore uncommitted changes in already tracked files,
please refer to the git update-index --assume-unchanged documentation.

此外,在man gitignore中讨论了一些模式:

o   If the pattern ends with a slash, it is removed for the purpose of the
    following description, but it would only find a match with a directory. In
    other words, foo/ will match a directory foo and paths underneath it, but will
    not match a regular file or a symbolic link foo (this is consistent with the
    way how pathspec works in general in git).

o   If the pattern does not contain a slash /, git treats it as a shell glob
    pattern and checks for a match against the pathname relative to the location of
    the .gitignore file (relative to the toplevel of the work tree if not from a
    .gitignore file).

o   Otherwise, git treats the pattern as a shell glob suitable for consumption by
    fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match
    a / in the pathname. For example, "Documentation/*.html" matches
    "Documentation/git.html" but not "Documentation/ppc/ppc.html" or
    "tools/perf/Documentation/perf.html".

o   A leading slash matches the beginning of the pathname. For example, "/*.c"
    matches "cat-file.c" but not "mozilla-sha1/sha1.c".

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接