工具文章Android开发Git

Git中.gitignore的配置语法

2016-04-12  本文已影响13547人  wavever

在日常的开发中,当我们需要将一个项目提交到Git时,并不是所有的文件都需要提交,比如一些自动生成的文件,这时候就可以使用.gitignore来忽略一些不需要提交的文件,本文着重介绍一下.gitignore的配置语法。

创建

以Android开发为例,Android Studio默认会生成一个.gitignore文件,而当使用Eclipse时,我们需要在提交Git之前,需要自己创建一个.gitignore文件,由于Windows下创建文件必须键入文件名,而要创建的.gitignore是没有文件名的,所以我们可以使用move命令来实现,打开Git Bash ,使用mv gitignore .gitignore,然后可以编辑器编辑这个文件。

生成的.gitgnore

语法规范

# 忽略 .a 文件
*.a
# 但否定忽略 lib.a, 尽管已经在前面忽略了 .a 文件
!lib.a
# 仅在当前目录下忽略 TODO 文件, 但不包括子目录下的 subdir/TODO
/TODO
# 忽略 build/ 文件夹下的所有文件
build/
# 忽略 doc/notes.txt, 不包括 doc/server/arch.txt
doc/*.txt
# 忽略所有的 .pdf 文件 在 doc/ directory 下的
doc/**/*.pdf

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

参考

gitignore collection on github
The Ignoring Files chapter of the Pro Git book.

上一篇 下一篇

猜你喜欢

热点阅读