Android Studio项目的.gitignore应该是什么?

本文翻译自:What should be in my .gitignore for an Android Studio project?

What files should be in my .gitignore for an Android Studio project? Android Studio项目的.gitignore文件中应该包含哪些文件?

I've seen several examples that all include .iml but IntelliJ docs say that .iml must be included in your source control. 我已经看到了几个都包含.iml示例,但是IntelliJ文档说.iml必须包含在源代码控件中。


#1楼

参考:https://stackoom.com/question/18E1I/Android-Studio项目的-gitignore应该是什么


#2楼

Basically any file that is automatically regenerated. 基本上是任何自动重新生成的文件。

A good test is to clone your repo and see if Android Studio is able to interpret and run your project immediately (generating what is missing). 一个很好的测试是克隆您的仓库,看看Android Studio是否能够立即解释和运行您的项目(生成丢失的内容)。
If not, find what is missing, and make sure it isn't ignored, but added to the repo. 如果不是,请查找缺少的内容,并确保忽略它,而是将其添加到存储库中。

That being said, you can take example on existing .gitignore files, like the Android one . 话虽如此,您可以在现有的.gitignore文件上举个例子,例如Android one

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# Eclipse project files
.classpath
.project

# Proguard folder generated by Eclipse
proguard/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/

#3楼

I use this .gitignore. 我使用这个.gitignore。 I found it at: http://th4t.net/android-studio-gitignore.html 我在以下位置找到了它: http : //th4t.net/android-studio-gitignore.html

*.iml
*.iws
*.ipr
.idea/
.gradle/
local.properties

*/build/

*~
*.swp

#4楼

In the case of Android Studio, the only files that are required to be saved in version control are the files required to build the application from the command line using gradle. 对于Android Studio,唯一需要保存在版本控制中的文件是使用gradle从命令行构建应用程序所需的文件。 So you can ignore: 因此,您可以忽略:

  • *.iml * .iml
  • .idea 。理念
  • build 建立

However, if you save any IDE settings, such as custom code style settings, they get saved in the .idea folder. 但是,如果保存任何IDE设置(例如自定义代码样式设置),它们将保存在.idea文件夹中。 If you want those changes in version control, then you'd save the IDEA files as well (*.iml and .idea). 如果要在版本控制中进行这些更改,则还需要保存IDEA文件(* .iml和.idea)。


#5楼

Depends on how your project format is maintained: 取决于项目格式的维护方式:

You have two options: 您有两种选择:

  1. Directory-based format (You will have a .idea folder which contains the project specific files) 基于目录的格式(您将拥有一个.idea文件夹,其中包含项目特定的文件)
  2. File-based format (configuration files are .iws and .ipr ) 基于文件的格式(配置文件为.iws.ipr

Ref: http://www.jetbrains.com/idea/webhelp/project.html 参考: http : //www.jetbrains.com/idea/webhelp/project.html

Files committed to version control depends on the above: 提交到版本控制的文件取决于以上内容:

  1. Include .idea folder to version control, exclude workspace.xml and tasks.xml 包括.idea文件夹以进行版本控制,排除workspace.xmltasks.xml
  2. Version control .ipr file and all the .iml module files, exclude the .iws file as it stores user specific settings. 版本控制.ipr文件和所有.iml模块文件不包括.iws文件,因为它存储了用户特定的设置。

Ref: https://intellij-support.jetbrains.com/entries/23393067 参考: https : //intellij-support.jetbrains.com/entries/23393067


#6楼

My advise would be also to not ignore the .idea folder. 我的建议是不要忽略.idea文件夹。

I've imported a Git-based Eclipse project to Android Studio and that went fine. 我已将基于Git的Eclipse项目导入Android Studio,一切正常。 Later, I wanted to import this project with Git (like the first time) to another machine with Android Studio, but that didn't worked. 后来,我想将此项目与Git一起导入(与第一次一样)到具有Android Studio的另一台计算机上,但这没有用。 Android Studio did load all the files but wasn't able to "see" the project as a project. Android Studio确实加载了所有文件,但无法将项目“视为”项目。 I only could open Git-files. 我只能打开Git文件。

While importing the project for the first time (from Eclipse to Android Studio) my old .gitignore was overwritten and the new one looked like this: 首次导入项目(从Eclipse到Android Studio)时,我的旧.gitignore被覆盖,新的.gitignore如下所示:

  • .idea/.name .idea / .name
  • .idea/compiler.xml .idea / compiler.xml
  • .idea/copyright/profiles_settings.xml .idea / copyright / profiles_settings.xml
  • .idea/encodings.xml .idea / encodings.xml
  • .idea/libraries/libs.xml .idea / libraries / libs.xml
  • .idea/misc.xml .idea / misc.xml
  • .idea/modules.xml .idea / modules.xml
  • .idea/scopes/scope_settings.xml .idea / scopes / scope_settings.xml
  • .idea/vcs.xml .idea / vcs.xml
  • .idea/workspace.xml .idea / workspace.xml

So, I tried to use an empty gitignore and now it worked. 因此,我尝试使用空的gitignore,现在它可以了。 The other Android Studio could load the files and the Project. 另一个Android Studio可以加载文件和项目。 I guess some files are not important (profiles_settings.xml) for Git and importing but I am just happy it worked. 我猜有些文件对于Git和导入并不重要(profiles_settings.xml) ,但我很高兴它能起作用。

发布了0 篇原创文章 · 获赞 136 · 访问量 83万+

猜你喜欢

转载自blog.csdn.net/xfxf996/article/details/105262975