2010-09-09 4 views
7

Tôi đang cố gắng thêm một số mẫu vào tệp .gitignore của mình để bỏ qua các tệp * .mode1v3 và * .pbxuser được tạo bởi Xcode. Tuy nhiên, tên ứng dụng của tôi có một khoảng trống trong đó, vì vậy các tệp tôi muốn bỏ qua nằm trong thư mục Foo Bar.xcodeproj/. Việc thêm các biến thể của các mẫu này dường như không hoạt động:git bỏ qua các thư mục có dấu cách trên Mac OS X

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

Mẫu .gitignore là gì?

Trả lời

3

Không gian AFAIK không được xử lý đặc biệt; cả Pro Git lẫn gitignore(5) cũng không phải fnmatch(3) đều đề cập đến chúng. Dù sao, mẫu đầu tiên *.mode1v3 là hoàn toàn đủ; các mẫu không có dấu gạch chéo được áp dụng cho tất cả các thư mục con. Nếu bạn muốn thêm patters bỏ qua cho một thư mục con cụ thể, chỉ cần đặt một .gitignore dành riêng trong thư mục đó.

+0

Bạn nói đúng. Tôi đã có một thời điểm mới, nơi tôi mong đợi các tập tin cam kết sẽ bị bỏ qua chỉ đơn giản bởi đức hạnh được ở trong .gitignore. Vì họ đã đăng ký, không phải vậy. Điều này xóa nó cho tôi: http://www.gitready.com/beginner/2009/03/06/ignoring-doesnt-remove-a-file.html – pmc255

2

Bạn đã thử thoát bất kỳ dấu cách nào trong tên thư mục hoặc tệp có dấu gạch chéo ngược không?

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

Ngoài ra, những tệp này đã được theo dõi bởi git chưa? Từ 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. 

Ngoài ra, sau đây là một số mẫu được thảo luận trong 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".