2014-09-06 54 views
8
$ cat .gitignore 

# OSX 
*/.DS_Store 
.DS_Store 
.DS_Store? 
._* 
.Spotlight-V100 
.Trashes 
Icon? 
ehthumbs.db 
Thumbs.db 

$ git status 
On branch develop 
Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

    modified: Assets/Sprites/.DS_Store 

no changes added to commit (use "git add" and/or "git commit -a") 

是有在的.gitignore和状态信息的更多不相关的文件的权利,但它本身的.gitignore没有被修改,这个版本被提交。.DS_Store仍然出现在git的地位,尽管在的.gitignore

我该如何解决这个问题?

+0

[Git diff不会忽略.gitignore中的指定文件]的可能重复(http://stackoverflow.com/questions/17820056/git-diff-doesnt-ignore-specified-files-in-gitignore) – 2014-09-06 13:33:38

回答

8

确保.DS_Store不在缓存:

git rm --cached -- Assets/Sprites/.DS_Store 
10

.DS_Store仍然出现在git status尽管.gitignore

.DS_Store文件被列为输出修改后的文件是git status,这意味着它目前正在被Git跟踪。但是,Git不会忽略当前正在跟踪的文件,无论它是否在您的.gitignore文件中列出。

你是如何得到这种状况的?您必须无意中开始跟踪.DS_Store文件之前在您的.gitignore中添加.DS_Store条目。

.gitignore本身没有被修改,这个版本被提交。

要忽略的文件列表不是由您可能已承诺的.gitignore文件的任何版本决定的,因为您似乎相信。 相反,在任何时候,Git都会使用工作树中的.gitignore文件(如果有的话)。

我该如何解决这个问题?

你需要告诉Git的停止跟踪该.DS_Store文件,通过运行

git rm --cached -- <path_to_the_.DS_Store-file> 

因为--cached标志的,有问题的.DS_Store文件将不会从你的工作树移除,但它会不是将被包含在您的后续提交中,并且从此之后应该适当忽略它。

+0

I没有'--',而只是文件路径 'git rm --cached。/ DS_Store',它仍然有效。 '--'做了什么? – ahnbizcad 2015-07-03 05:13:44

+0

@ahnbizcad请参阅http://stackoverflow.com/questions/22750028/in-git-what-does-dash-dash-mean?lq=1 – Jubobs 2015-07-03 07:45:37

+0

' - '确保事情顺利进行......(例如,如果您的文件名称以' - '字符开头) – ahnbizcad 2015-07-04 09:20:18

相关问题