git 忽略 Mac OS X 上带有空格的目录

发布于 2024-09-18 05:38:25 字数 303 浏览 5 评论 0原文

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

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

.gitignore 模式应该是什么?

I'm trying to add some patterns to my .gitignore file to ignore *.mode1v3 and *.pbxuser files generated by Xcode. However, my app name has a space in it, so the files I want to ignore are in the Foo Bar.xcodeproj/ directory. Adding variants of these patterns don't seem to work:

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

What should the .gitignore patterns be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放我走吧 2024-09-25 05:38:25

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

AFAIK spaces aren't treated specially; neither Pro Git nor gitignore(5) nor fnmatch(3) mentions them. Anyway the first pattern *.mode1v3 is totally sufficient; patterns without slashes are applied to all subdirectories. If you want additional ignore patters for a specific subdirectory, just place a dedicated .gitignore in that directory.

遇见了你 2024-09-25 05:38:25

您是否尝试过使用反斜杠转义文件夹或文件名中的任何空格?

*.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".

Have you tried escaping any spaces in the folder or file names with backslashes?

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

Also, are these files already being tracked by git? From 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.

Additionally, here are some of the patterns discussed in 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".
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文