尽管在.gitignore中,.DS_Store仍然以git状态出现

Max*_*kov 10 git gitignore

$ 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")
Run Code Online (Sandbox Code Playgroud)

现在.gitignore和状态消息中有更多不相关的文件,但.gitignore本身未被修改,此版本已提交.

我该如何解决这个问题?

jub*_*0bs 16

.DS_Storegit status尽管身处其中,仍然会出现.gitignore

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

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

.gitignore 本身未修改,此版本已提交.

.gitignore您可能已经提交的文件的任何版本都不会确定要忽略的文件列表.相反,在任何给定时间,Git都使用.gitignore工作树中的文件(如果有的话).

我该如何解决这个问题?

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

git rm --cached -- <path_to_the_.DS_Store-file>
Run Code Online (Sandbox Code Playgroud)

由于该--cached标志,有问题的.DS_Store文件不会从您的工作树中删除,但它不会包含在您的后续提交中,从那时起它应该被正确忽略.


Von*_*onC 12

确保.DS_Store不在缓存中:

git rm --cached -- Assets/Sprites/.DS_Store
Run Code Online (Sandbox Code Playgroud)