2012-06-12 49 views
0

我讀過關於將.DS_Store添加到.gitignore文件中的人,但我使用Git 1.7.6做了一個快速測試,我不確定這甚至是必需的。你怎麼看?.gitignore中的.DS_Store:不必要?

[email protected]:~$ mkdir test 
[email protected]:~$ cd test/ 
[email protected]:~/test$ git init 
Initialized empty Git repository in /Users/johndoe/test/.git/ 
[email protected]:~/test$ touch foo.txt 
[email protected]:~/test$ touch .DS_Store 
[email protected]:~/test$ touch bar.txt 
[email protected]:~/test$ touch .DS_Store2 
[email protected]:~/test$ git status 
# On branch master 
# 
# Initial commit 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# .DS_Store2 
# bar.txt 
# foo.txt 
nothing added to commit but untracked files present (use "git add" to track) 
[email protected]:~/test$ git config -l 
user.name=John Doe 
[email protected] 
color.ui=true 
core.editor=mate -w 
core.repositoryformatversion=0 
core.filemode=true 
core.bare=false 
core.logallrefupdates=true 
core.ignorecase=true 
+0

什麼是.DS_Store2參考?如果它是一個項目類型,你可以考慮爲它添加一個額外的標籤。 – 2012-06-12 00:14:31

+0

只需將.DS_Store添加到您的全局gitignore文件中,這樣您就不需要混淆各個存儲庫。如果您使用Emacs或Vi,則同樣適用於*〜,#*#。 –

+0

@Michael我只是說明我沒有什麼時髦的東西,那是隱藏來自Git的隱藏文件。我想我可以使用「.hidden」而不是「.DS_Store2」。 – Nick

回答

1

我做了遞歸的grep通過GIT中的整個源代碼,並沒有看到除了在GIT桂目錄的的.gitignore爲「.DS_Store」的任何參考。

這意味着git不會自動忽略該文件(除非它在git的MacOS版本或類似奇怪的東西中特別修補)。

可能是它忽略了它的原因可能是你在全局忽略它。

+0

謝謝你這麼做!我99%肯定我從未親自將它添加到我的全球忽略中。我猜'git config -l'會顯示它,如果是這樣的話。我使用[this](http://code.google.com/p/git-osx-installer)安裝了Git。任何其他想法? – Nick

+0

我對它進行了更多的研究,發現[here](http://code.google.com/p/git-osx-installer/wiki/BuildYourOwn)執行了以下代碼片段:'sudo sh -c「 echo .DS_Store >>/usr/local/git/share/git-core/templates/info/exclude「'。因此,無論何時運行'git init',該文件都會被複制到新的存儲庫的「.git/info/exclude」文件中。我想這沒問題,因爲根據[本頁](https://help.github.com/articles/ignoring-files),「這種方法可以用於本地生成的文件,你不希望其他用戶生成「(如非Mac用戶)。再次感謝! – Nick