【问题标题】:Android-Studio (Git): *.iml file always gets committed, why?Android-Studio (Git):*.iml 文件总是被提交,为什么?
【发布时间】:2016-11-01 11:59:27
【问题描述】:

我正在使用 Android-Studio 开发应用程序。为了对我的代码进行版本控制,我正在使用 GitLab。因此,我创建了以下 .gitignore 文件以避免提交所有内容:

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# built native files (uncomment if you build your own)
# *.o
# *.so

# generated files
bin/
gen/

# Ignore gradle files
.gradle/
build/

# Crashlytics configuations
com_crashlytics_export_strings.xml

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

# Proguard folder generated by Eclipse
proguard/

# Signing files
.signing/

# Eclipse Metadata
.metadata/

# Mac OS X clutter
*.DS_Store

# Windows clutter
Thumbs.db

# Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067)
.idea/workspace.xml
.idea/libraries/
.idea/tasks.xml
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/vcs.xml
.idea/datasources.xml
.idea/dataSources.ids
*.iml

build/intermediates/dex-cache/cache.xml

.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

但是,每当我尝试commit-changes 时,提交都会包含build folder.iml file(在附图中突出显示),即使它们在.gitignore 文件中说明。

如何让 Android-studio 忽略这些文件和文件夹?!

【问题讨论】:

    标签: android git gitignore


    【解决方案1】:

    要让 Intellij IDEA(以及扩展名为 Android Studio)完全忽略文件和文件夹,请在 Editor -> File Types -> Ignore Files and Folders 中使用以下内容:

    来自https://www.jetbrains.com/help/idea/2016.2/file-types.html

    忽略文件和文件夹:在此文本框中,指定文件和文件夹 您希望 IntelliJ IDEA 忽略的文件夹。此类文件和 文件夹将被完全排除在任何类型的处理之外。经过 默认列表包括临时文件,相关的服务文件 版本控制系统等

    【讨论】:

      【解决方案2】:

      试试这个

      首先提交所有未完成的代码更改,然后运行以下命令:

      git rm -r --cached .

      这会从索引(暂存区)中删除所有更改的文件,然后只需 运行:

      git 添加。

      提交:

      git commit -m ".gitignore 正在工作"

      完整答案here

      【讨论】:

        猜你喜欢
        • 2015-08-24
        • 2015-01-11
        • 1970-01-01
        • 1970-01-01
        • 2015-05-20
        • 1970-01-01
        • 2013-10-20
        • 2014-11-23
        • 2020-11-21
        相关资源
        最近更新 更多