Roly's Blog

Whatever will be, will be, the future's not ours to see.

0%

Android-Studio中-gitignore的配置

如果你使用git 作版本控制工具,那么你可以轻松的使用android studio / Intellij IDEA 的.gitignore 插件来生成一份可以将这些文件排除在外的.gitignore 过滤清单。

Android Studio 项目目录结构

在项目目录下找到.gitignore文件(一般有两个地方存在该文件:一是根目录下,一是app目录下), 在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以通过配置.gitignore文件让Git不跟踪配置的文件。

Android-Studio中-gitignore的配置1

其中:

  • .gradle 是gradle 运行以后生成的缓存文件夹。
  • .idea 是android studio / Intellij IDEA 工程打开以后生成的工作环境配置文件夹。
  • app 文件夹是你的application module,其中包含你的源码。
  • build 文件夹为编译时的缓存文件夹,每次运行时都会生成,同时你在运行了gradle clean 的任务以后它会被删除清理掉。
  • gradle 文件夹中包含的是gradle-wrapper.jar 文件,通过配置其中的gradle-wrapper.properties 中的distributionUrl 可以给你的项目指定需要使用的gradle 版本。
  • .gitignore 文件为git 版本控制的忽略清单。
  • gradle.build 为project 全局的配置。
  • gradle.properties 为 gradle 的参数配置。
  • *.iml 文件为Android Studio / Intellij IDEA 为每一个module 生成的配置文件
  • gradlew gradlew.bat 是gradle 任务的脚本命令。
  • local.properties 中配置个人电脑环境中的配置,这不能提供给别人使用。
  • settings.gradle 文件中可指定project 目录中的任何一个文件夹为gradle 的module

Android 开发 .gitignore 的配置

如果你使用git 作版本控制工具,那么你可以轻松的使用android studio / Intellij IDEA 的.gitignore 插件来生成一份可以将这些文件排除在外的.gitignore 过滤清单。这样在你使用git 分发代码时,这些不必要的文件将不会被提交到git server 中去。

.gitignore插件

Android-Studio中-gitignore的配置1

打开项目目录中的.gitignore,然后使用快捷键Ctrl+N打开Generate

Android-Studio中-gitignore的配置1

自定义的.gitignore模板

Android-Studio中-gitignore的配置1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
###Android###
# 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

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Keystore files
*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

###macOS###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

###Linux###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

###Windows###
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk
###IntelliJ###
*.iml
*.ipr
*.iws
.idea/
app/libs/

.gitignore配置不生效的解决办法

1
2
3
git rm -r --cached .
git add .
git commit -m "update .gitignore"

就是先把本地缓存删除(改变成未track状态),然后再提交。

其他.gitignore的配置

GitHub 有一个十分详细的针对数十种项目及语言的 .gitignore 文件列表,你可以在 https://github.com/github/gitignore 找到它。各种配置文件,只需要组合一下就可以使用了。

参考文献

[1] https://www.zhihu.com/question/33048493

[2] http://blog.csdn.net/watermusicyes/article/details/50348967

[3] https://git-scm.com/book/zh/v2/Git-基础-记录每次更新到仓库