这是我的.gitignore文件的内容,它位于我的存储库的根目录下:
# grails stuff to ignore
target
*.iml
*.ipr
.idea
*.log
*.swp # vi swap files
.DS_Store # OS X Finder cache files
# cocoapods stuff to ignore
Pods
Podfile.lock
我的项目根目录中的
.DS_Store
文件被正确忽略,但git状态给出:$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
ios/.DS_Store
nothing added to commit but untracked files present (use "git add" to track)
为什么
ios/.DS_Store
不被忽略?在OSX10.9.2上工作,使用苹果提供的Git版本:“Gitversion1.8.5.2(Apple Git-48)”。
最佳答案
好吧,我认为这是因为忽略规则中有额外的空格,因为您刚才添加的注释,也因为它们的模式不匹配。验证时间:git version 1.8.3.2
,Ubuntu 13.10
.gitignore
中的以下条目可以正常工作(没有任何额外空间)
.DS_Store
而这两项都不起作用(在规则之后留有空间)
*.DS_Store # OS X Finder cache files
.DS_Store # OS X Finder cache files
我的猜测是,你的
PROJECT_DIR/.DS_Store
已经签入回购协议,因此不会出现在git status
中,你确定你的PROJECT_DIR/.DS_Store
不是回购协议的一部分吗?执行
git log .DS_Store
并查看是否抛出了任何提交。如果是,使用工作中的第一个忽略规则,并删除Excng
.DS_Store
git rm --cached .DS_Store
git commit -m "msg"
编辑
您以错误的格式输入注释,它们必须放在文件的开头/忽略规则。Check this。
我用comment-
*.swp
验证了您的另一个忽略规则,但它也不起作用。从git-scm page on gitignore
gitignore文件中的每一行都指定一个模式。当决定是否忽略一个路径时,git通常检查来自多个源的git ignore模式,从最高到最低的优先顺序如下(在一个优先级别内,最后一个匹配的模式决定结果)