即使 gitconfig 指定了绝对路径,我的 gitignore_global 也无法正常工作

My gitignore_global is not working even though gitconfig specify the absolute path

我在~/Users/Tony/.gitignore_global中创建了一个.gitignore_global文件,也是.gitconfig的存放路径

这是.gitconfig里面的内容:

[core]
    excludesfile = ~/.gitignore_global

这是.gitignore_global里面的内容:

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# CocoaPods #
#############
Pods

# SVN #
#######
*.svn
.svn/*

# Xcode #
#########
build/
DerivedData
profile
xcuserdata
!default.mode1v3
!default.mode2v3
!default.pbxuser
!default.perspectivev3
*.mode1
*.mode1v3
*.mode2v3
*.moved-aside
*~.nib
*.pbxuser
*.perspective
*.perspectivev3
*.swp
*.xccheckout

我不明白为什么 .gitignore_global 文件不起作用。 git 仍在检测 .DS_Store 个文件。
我已经尝试过像“git rm --cached .DS_Store”这样的评论,并尝试了在 Stack Overflow 上找到的其他解决方案,但是 git 仍在检测 .DS_Store 文件。

为确保您的全局 git忽略被考虑在内:

  • 确保你有 git 2.8+
  • 做一个 git config --show-origin -l|grep excludesfile 看看你的规则是否存在(如果它下面有一个涉及 excludesfile,它会覆盖你的)。
  • 尝试在 excludefile 的全局配置中放置完整路径:/home/<user>/.gitignore_global 而不是“~”。
  • 执行 git check-ignore -v -- path/to/.DS_Store 以查看是否显示任何忽略规则。

由于 OP 确认这在新的 repo 中有效,这意味着在现有的 repo 中跟踪了当前元素。
例如:

git rm --cached -r .DS_Store

相反,OP Tony Ong adds :

I took a round about to solve the problem with regards to "existing repo".
I went to copy the content in the repo to a temp folder, delete the content in the repo, commit/push the repo, copy the content from temp folder to repo, commit/ push again.
It is a tedious process but it works, gitignore_global is now working for existing repo.
I will try "git rm --cached -r .DS_Store" when the opportunity arise.