2016-04-29 36 views
1

我在~/Users/Tony/.gitignore_global中創建了一個.gitignore_global文件,該文件也是存儲.gitconfig的路徑。即使gitconfig指定絕對路徑,我的gitignore_global仍無法正常工作

這是什麼.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文件不能正常工作。這個.DS_Store文件仍然被git檢測到。
我已經嘗試過像「git rm --cached .DS_Store」這樣的評論,並嘗試了其他在Stack Overflow上找到的解決方案,但是git仍在檢測.DS_Store文件。

回答

0

要確認你的全局gitignore是考慮到:

  • 確保你讓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確認這是在新的回購庫中工作,這意味着當前元素在現有回購庫中進行跟蹤。
例如:

git rm --cached -r .DS_Store 

相反,OP Tony Ong增加in the comments

我花了周圍有關於解決問題 「現有回購」。
我去複製回購內容到temp文件夾,刪除回購內容,提交/推回購,將內容從臨時文件夾複製到回購,再次提交/推送。
這是一個繁瑣的過程,但它的工作原理,gitignore_global現在正在爲現有的回購工作。
當機會出現時,我會嘗試「git rm --cached -r .DS_Store」。

+0

我做了一個 「混帳配置 - 顯示,起源-l | grep的excludesfile」 和終端還給我 - 文件:在/ usr /本地/ GIT中的/ etc/gitconfig \t core.excludesfile =〜/的.gitignore - 文件:/Users/Tony/.gitconfig core.excludesfile =/Users/Tony/.gitignore_global下面有一個涉及「excludesfile」,這是否意味着它會覆蓋我的? –

+0

@TonyOng這是一個好的開始。現在你可以做一些測試。 – VonC

+0

我做了一些測試,但是.gitignore_global不起作用。我完成了你的第一點和第三點。不太明白第2點,但仍然運行命令並粘貼結果。嘗試運行點4,但它不工作。 –

相關問題