I still can't get a .gitignore file that can help my code versioned in git for an Android project, if I modify a class or something very simple, changes are made to unnecessary files such as tests.
I am attaching my .gitignore as well.
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
# 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
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries
# Keystore files
*.jks
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
# Google Services (e.g. APIs or Firebase)
google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
Thanks.
Just because you add the .gitignore file to the directory doesn't mean it's going to ignore it like that. You have to run the following commands so that gitignore recognizes the files that should not be tracked. Remember to commit the files you currently have or else you will lose the changes to those files
Check the documentation , where it specifies:
Therefore, what is defined inside
.gitignore
applies for untracked files, in your case the files I see mainly are the ones inside directories/build
already marked for tracking.To take the changes made in the .gitignore do the following:
Commit pending changes and remove modified files from the index:
save changes:
and perform a commit:
Reviewing your file
.gitignore
, I can suggest some changes:*.iml
change**/*.iml
to to search all directories for files with an .iml extension.gradle
by.gradle/
correctly specifies a directory.If you specify
/build
, you don't have to specify the files*.dex
and*.class
, since they are inside this directory, the same for thebin/
gen/
(in android es/generated
) andout/
(in android es/outputs
) directories, you don't need to specify them.Documentation https://git-scm.com/docs/gitignore
Your problem seems to be that the sample-core/build/ folder is being versioned
To fix this, in addition to the file
.gitnore
you have in the root of your project, you should add an.gitignore
additional file inside your sample-core folder . The file should have the following content:As an additional fact, when you create a new project with Android Studio, the IDE automatically generates these two files
.gitignore
: one in the root of the project and another inside the module. Here more information about the project structure in Android.