2010-09-09 42 views
7

我試圖在我的.gitignore文件中添加一些模式來忽略由Xcode生成的* .mode1v3和* .pbxuser文件。但是,我的應用名稱中有一個空格,所以我想忽略的文件位於Foo Bar.xcodeproj/目錄中。添加這些模式的變體似乎不起作用:git忽略在Mac OS X上有空格的目錄

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

.gitignore模式應該是什麼?

回答

3

AFAIK空間沒有專門處理; Pro Git和gitignore(5)fnmatch(3)都沒有提到它們。無論如何,第一種模式*.mode1v3是完全足夠的;沒有斜槓的模式應用於所有子目錄。如果您需要特定子目錄的其他忽略模式,只需在該目錄中放置專用的.gitignore

+0

你說得對。我有一個新手時刻,我期望提交的文件僅僅因爲在.gitignore而被忽略。由於他們已經簽入,情況並非如此。這爲我清除它:http://www.gitready.com/beginner/2009/03/06/ignoring-doesnt-remove-a-file.html – pmc255 2010-09-09 10:43:28

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