2014-09-06 45 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

相關問題