.gitignore每個文件夾和子文件夾中的所有.DS_Store文件

本文翻譯自:.gitignore all the .DS_Store files in every folder and subfolder

I've added .DS_Store to the .gitignore file, but it seems that it is only ignoring .DS_Store in the root directory, not in every folder and subfolder. 我已將.DS_Store添加到.gitignore文件中,但似乎它只忽略根目錄中的.DS_Store,而不是每個文件夾和子文件夾。

How do I fix this? 我該如何解決?


#1樓

參考:https://stackoom.com/question/1FAzK/gitignore每個文件夾和子文件夾中的所有-DS-Store文件


#2樓

I think the problem you're having is that in some earlier commit, you've accidentally added .DS_Store files to the repository. 我認爲你遇到的問題是,在一些早期的提交中,你不小心將.DS_Store文件添加到了存儲庫。 Of course, once a file is tracked in your repository, it will continue to be tracked even if it matches an entry in an applicable .gitignore file. 當然,一旦在您的存儲庫中跟蹤文件,即使它與適用的.gitignore文件中的條目匹配,它也將繼續被跟蹤。

You have to manually remove the .DS_Store files that were added to your repository. 您必須手動刪除已添加到存儲庫的.DS_Store文件。 You can use git rm --cached .DS_Store . 你可以使用git rm --cached .DS_Store Once removed, git should ignore it. 刪除後,git應該忽略它。 You should only need the following line in your root .gitignore file: .DS_Store . 您應該只需要根.gitignore文件中的以下行: .DS_Store Don't forget the period! 不要忘記這個時期!

git rm --cached .DS_Store removes only .DS_Store from the current directory. git rm --cached .DS_Store僅從當前目錄中刪除.DS_Store You can use find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch 你可以使用find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch to remove all .DS_Stores from the repository. find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch從存儲庫中刪除所有.DS_Stores

Felt tip: since you probably never want to include .DS_Store files, make a global rule. 感覺提示:因爲您可能永遠不想包含.DS_Store文件,所以制定全局規則。 First, make a global .gitignore file somewhere, eg echo .DS_Store >> ~/.gitignore_global . 首先,在某處創建一個全局.gitignore文件,例如echo .DS_Store >> ~/.gitignore_global Now tell git to use it for all repositories: git config --global core.excludesfile ~/.gitignore_global . 現在告訴git將它用於所有存儲庫: git config --global core.excludesfile ~/.gitignore_global

This page helped me answer your question: https://help.github.com/articles/ignoring-files 這個頁面幫助我回答了你的問題: https//help.github.com/articles/ignoring-files


#3樓

You can also add the --cached flag to auco's answer to maintain local .DS_store files, as Edward Newell mentioned in his original answer. 您還可以將--cached標誌添加到auco的答案中以維護本地.DS_store文件,正如Edward Newell在其原始答案中提到的那樣。 The modified command looks like this: find . -name .DS_Store -print0 | xargs -0 git rm --cached --ignore-unmatch 修改後的命令如下所示: find . -name .DS_Store -print0 | xargs -0 git rm --cached --ignore-unmatch find . -name .DS_Store -print0 | xargs -0 git rm --cached --ignore-unmatch find . -name .DS_Store -print0 | xargs -0 git rm --cached --ignore-unmatch ..cheers and thanks! find . -name .DS_Store -print0 | xargs -0 git rm --cached --ignore-unmatch unmatch ..cheers,謝謝!


#4樓

Add **/.DS_Store into .gitignore for the sub directory **/.DS_Store添加到子目錄的.gitignore


If .DS_Store already committed: 如果.DS_Store已經提交:

find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch

To ignore them in all repository: (sometimes it named ._.DS_Store ) 要在所有存儲庫中忽略它們:(有時它命名爲._.DS_Store

echo ".DS_Store" >> ~/.gitignore_global
echo "._.DS_Store" >> ~/.gitignore_global
echo "**/.DS_Store" >> ~/.gitignore_global
echo "**/._.DS_Store" >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global

#5樓

Add *.DS_Store to your .gitignore file. *.DS_Store添加到.gitignore文件中。 That works for me perfectly 這完全適合我


#6樓

Your .gitignore file should look like this: 您的.gitignore文件應如下所示:

# Ignore Mac DS_Store files
.DS_Store

As long as you don't include a slash, it is matched against the file name in all directories. 只要不包含斜槓,它就會與所有目錄中的文件名匹配。 (from here ) (從這裏

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章