7

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

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

.gitignore 模式应该是什么?

4

2 回答 2

4

AFAIK 空间没有得到特殊处理;既没有 Pro Git 也gitignore(5)没有fnmatch(3)提到它们。无论如何,第一个模式*.mode1v3就足够了;不带斜线的模式应用于所有子目录。如果您想要特定子目录的其他忽略模式,只需.gitignore在该目录中放置一个专用的。

于 2010-09-09T10:28:32.310 回答
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".
于 2010-09-09T10:38:06.737 回答