http://isunxu.xyz/android/commit-what-to-github-in-as/
Fri Dec 11, 2015
在知乎上看到的提问,原问题链接: http://www.zhihu.com/question/37910193
当我们上传用AS写的Android代码时,上传没必要的代码不仅浪费空间,有时还会引起项目共同合作人员在提交代码时的冲突,那么究竟什么代码该上传,什么代码不该上传呢?
查阅相关资料:
- http://www.jetbrains.com/idea/help/project.html
- http://qiita.com/amanoiverse/items/71b7dccf992b33930c35
- http://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-an-android-studio-project
- https://gist.github.com/iainconnor/8605514
- https://github.com/drakeet/Meizhi/blob/master/.gitignore
- https://github.com/JakeWharton/butterknife/blob/master/.gitignore
- https://github.com/bboyfeiyu/Colorful/blob/master/.gitignore
找了一些资料后,每个给出的答案都不一样,我把上面的答案总结后融合了一下添加到平常在在本地练习的 .gitignore 文件中,并上传到Github上然后down下来重新导入,发现导入没有任何异常,运行顺利.
融合后的 .gitignore :
# IntelliJ IDEA
.idea
*.iml
*.ipr
*.iws
# Gradle
.gradle
gradlew.bat
build
# Local configuration file (sdk path, etc)
local.properties
reports
/captures
jacoco.exec
# Mac system files
.DS_Store
# Built application files
*.apk
*.ap_
# Android Studio captures folder
/captures
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
out
lib
# Eclipse project files
.classpath
.project
.settings/
eclipsebin
.metadata/
# Proguard folder generated by Eclipse
proguard/
#NDK
obj/
jniLibs
上传到GitHub后的项目预览:
不需要额外的配置即可导入运行,那么这个融合的了 .gitignore 就是可行的.
回过头再来看Android Studio中的 .gitignore,发现有绿色的代码,也有灰色的代码,当把鼠标移过去也会有不一样的提示.
有这种提示的就是文件已经包含在其他的文件夹中,可以删除这些文件.
有这种提示的就是工程中不包含这种文件,没必要申明在 *.gitignore*文件中,也可删除.
那么我们删除了上述这种文件后, *.gitignore*马上就变得清爽起来.
# IntelliJ IDEA
.idea
*.iml
# Gradle
.gradle
build
# Local configuration file (sdk path, etc)
local.properties
# Mac system files
.DS_Store
为了科学严谨性,再次上传包含这份 .gitignore 的代码到GitHub中,结构跟上面的图显示是一样的.
再次down下来导入AS,运行依旧顺利.
总结:
-
我们当然可以把融合后比较多的代码模板复制到自己的 *.gitignore*文件中,这样会容错率高,有助于防止多传一些没必要的东西.
-
也可以根据自己代码的实际情况根据提示,决定究竟该上传些什么代码,但应该大于等于上面最后这段代码.(如项目中用到了NDK,就可以加上/obj)
-
总之就是提供给大家一种思路,才疏学浅,还请大家多多提意见给我.
-
最后,祝好:)
Fri Dec 11, 2015
在知乎上看到的提问,原问题链接: http://www.zhihu.com/question/37910193
当我们上传用AS写的Android代码时,上传没必要的代码不仅浪费空间,有时还会引起项目共同合作人员在提交代码时的冲突,那么究竟什么代码该上传,什么代码不该上传呢?
查阅相关资料:
- http://www.jetbrains.com/idea/help/project.html
- http://qiita.com/amanoiverse/items/71b7dccf992b33930c35
- http://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-an-android-studio-project
- https://gist.github.com/iainconnor/8605514
- https://github.com/drakeet/Meizhi/blob/master/.gitignore
- https://github.com/JakeWharton/butterknife/blob/master/.gitignore
- https://github.com/bboyfeiyu/Colorful/blob/master/.gitignore
找了一些资料后,每个给出的答案都不一样,我把上面的答案总结后融合了一下添加到平常在在本地练习的 .gitignore 文件中,并上传到Github上然后down下来重新导入,发现导入没有任何异常,运行顺利.
融合后的 .gitignore :
# IntelliJ IDEA
.idea
*.iml
*.ipr
*.iws
# Gradle
.gradle
gradlew.bat
build
# Local configuration file (sdk path, etc)
local.properties
reports
/captures
jacoco.exec
# Mac system files
.DS_Store
# Built application files
*.apk
*.ap_
# Android Studio captures folder
/captures
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
out
lib
# Eclipse project files
.classpath
.project
.settings/
eclipsebin
.metadata/
# Proguard folder generated by Eclipse
proguard/
#NDK
obj/
jniLibs
上传到GitHub后的项目预览:
不需要额外的配置即可导入运行,那么这个融合的了 .gitignore 就是可行的.
回过头再来看Android Studio中的 .gitignore,发现有绿色的代码,也有灰色的代码,当把鼠标移过去也会有不一样的提示.
有这种提示的就是文件已经包含在其他的文件夹中,可以删除这些文件.
有这种提示的就是工程中不包含这种文件,没必要申明在 *.gitignore*文件中,也可删除.
那么我们删除了上述这种文件后, *.gitignore*马上就变得清爽起来.
# IntelliJ IDEA
.idea
*.iml
# Gradle
.gradle
build
# Local configuration file (sdk path, etc)
local.properties
# Mac system files
.DS_Store
为了科学严谨性,再次上传包含这份 .gitignore 的代码到GitHub中,结构跟上面的图显示是一样的.
再次down下来导入AS,运行依旧顺利.
总结:
-
我们当然可以把融合后比较多的代码模板复制到自己的 *.gitignore*文件中,这样会容错率高,有助于防止多传一些没必要的东西.
-
也可以根据自己代码的实际情况根据提示,决定究竟该上传些什么代码,但应该大于等于上面最后这段代码.(如项目中用到了NDK,就可以加上/obj)
-
总之就是提供给大家一种思路,才疏学浅,还请大家多多提意见给我.
-
最后,祝好:)