Android stuido项目中有些文件是不需要提交到Git管理的。比如
local.properties
,xxx.iml
等文件都是每个开发者独有的一些配置。JDKB版本,SDK位置都各不一样。每个人都提交很明显会有冲突问题,最好的方式就是不加入git管理
1.在项目根目录创建.gitignore文件
该文件用与编写需要过滤的文件
2.编写gitignore文件
常规用法
.gradle
/local.properties
/.idea
.DS_Store
/build
*.iml
/captures
3.更详细的用法
在github用一个专门为各个平台提供的gitignore的写法
传送门:https://github.com/github/gitignore
Android.gitignore内容预览
# Built application files
*.apk
*.ap_
# Files for the ART/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
.idea/workspace.xml
.idea/libraries
# Keystore files
*.jks
最后补充
如果已经将上述文件都加入了git管理,你会发现即使已经添加.gitignore文件后,git仍然会将上述文件加入管理。此时你需要先删除这些文件(可先备份好),在提交给git仓库。在将刚才删除文件取回即可。