我正在尝试在 Mac OS 上设置全局 gitignore 文件,但由于某种原因它没有生效。当我在 Linux 操作系统上重复相同的步骤时,一切正常。下面是我所做的步骤。谁能指出我遗漏了什么?
注意:我之前提交了 .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
关于git - 有效的全局 .gitignore 步骤不会在 Mac OS 上生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29928669/