有效的全局 .gitignore 步骤不会在 Mac OS 上生效

Valid global .gitignore steps won't take effect on Mac OS

我正在尝试在 Mac OS 上设置全局 gitignore 文件,但由于某些原因它没有生效。当我在 Linux OS 上重复相同的步骤时,一切正常。下面是我所做的步骤。谁能指出我遗漏了什么?

注意:我之前提交过.idea文件,这跟它有关系吗?以防万一我也尝试添加 .idea.idea/*

步骤

MacBook-Pro:~ bc$ echo $HOME
/Users/bc
MacBook-Pro:~ bc$ git config --get core.excludesfile
/Users/bc/.gitignore_global
MacBook-Pro:~ bc$ cat .gitignore_global
*~
.DS_Store
.idea/
MacBook-Pro:~ bc$ git config --global core.excludesfile /Users/bc/.gitignore_global

项目

MacBook-Pro:Project bc$ git branch
* develop
  master
MacBook-Pro:Project bc$ 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:   .idea/workspace.xml

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

Git 的忽略(无论是本地的还是全局的)仅适用于尚未添加到索引中的文件。一旦文件成为存储库的一部分,git 将继续跟踪对其的更改,无论当前的忽略列表如何。您需要使用

从索引中删除文件
git rm --cached .idea/workspace.xml

或者,您可以使用

告诉git继续跟踪文件但忽略本地更改
git update-index --assume-unchanged .idea/workspace.xml