天天看點

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.xml

    tasks.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)

,但我很高興它能起作用。