0

让 Git 全局性的忽略 .DS_Store

 3 years ago
source link: https://mednoter.com/gitignore-global.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

让 Git 全局性的忽略 .DS_Store

Mac 中每个目录都会有个文件叫.DS_Store, 用于存储当前文件夹的一些 Meta 信息。每次提交代码时,我都要在代码仓库的 .gitignore 中显式的声明忽略这类文件。有没有一劳永逸的方法可以让 git 全局忽略这种类型的文件?

按照以下两步就可实现

  1. 创建 ~/.gitignore_global 文件,把需要全局忽略的文件类型塞到这个文件里。

     # .gitignore_global
     ####################################
     ######## OS generated files ########
     ####################################
     .DS_Store
     .DS_Store?
     *.swp
     ._*
     .Spotlight-V100
     .Trashes
     Icon?
     ehthumbs.db
     Thumbs.db
     ####################################
     ############# Packages #############
     ####################################
     *.7z
     *.dmg
     *.gz
     *.iso
     *.jar
     *.rar
     *.tar
     *.zip
    
  2. 在 ~/.gitconfig 中引入 .gitignore_global

这是我的.gitconfig 文件:

[user]
	name = Your Name
	email = Your email
[push]
	default = matching
[core]
	excludesfile = ~/.gitignore_global

搞定了!不管 .DS_Store .swp .zip 在哪个目录下,这种文件都会被 Git 自动忽略。

demo

吕小荣
22 March 2015

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK