在项目的根目录(跟 .git 文件夹所在目录同层)建立 .gitignore 文件,在里面声明即可。

配置语法

  1. 以斜杠“/”开头表示目录;
  2. 以星号“*”通配多个字符;
  3. 以问号“?”通配单个字符
  4. 以方括号“[]”包含单个字符的匹配列表;
  5. 以叹号“!”表示不忽略(跟踪)匹配到的文件或目录。

git 对于 .gitignore 配置文件是按行从上到下进行规则匹配的

如果之前文件已提交过,则需要先清除原文件: git rm *.dll 这样.

另一种方法

修改git的全局设置,把忽略名单用于所有项目: 首先,建立一个.gitignore_global文件;

git config --global core.excludesfile .gitignore_global 

栗子

Github 给出的 Android 开发中使用的.gitignore模板

# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# Intellij
*.iml
# Keystore files
*.jks

参考

https://github.com/github/gitignore/blob/master/Android.gitignore

https://git-scm.com/docs/gitignore

https://www.jianshu.com/p/ea6341224e89

https://blog.csdn.net/u011475134/article/details/71521725

-= 完 =-

Like this post? Share on:


doobom Avatar doobom is write a bug.
Comments

So what do you think? Did I miss something? Is any part unclear? Leave your comments below.

comments powered by Disqus

Keep Reading


Published

Category

git

Tags

Stay in Touch

Get New Release Alert