Android Studio Git .gitignore vs Project > Settings > Version Control > Ignored Files

62,304

Solution 1

Ok to answer my own question. To go back to using .gitignore, do the following:

  1. Go to Settings > Version Control > Ignored Files and remove all ignored files. Hit Apply.
  2. Still in Settings > Version Control change the type of version control from Git to none. Hit Apply.
  3. Delete the project's .git directory created previously.
  4. Create the following .gitignore file in the root directory of your project: https://stackoverflow.com/a/21049338/459095
  5. VCS > Enable Version Control... to Re-enable Git.
  6. Then right click on the project root and select Git > Add to add the entire project.

Doing the above will utilize the .gitignore file instead of Settings > Version Control > Ignored Files to commit the right files.

Solution 2

For me the process was a little easier:

  1. In Android Studio: Settings > Version Control > Ignored Files > Remove all ignored files > Apply
  2. Backup .gitignore. Create an empty new .gitignore. (in the root folder)
  3. Restart Android Studio!
  4. Fill up the new .gitignore with the old one. Don't forget to commit the change .gitignore + related ignored/deleted files!

No re-enable VCS required! I'm working with a GitRepo, which is extremely inconvient to do re-enabling VCS. The steps helped.

Solution 3

Using command line, this becomes easy :

> git status

On branch master

No commits yet

Untracked files: (use "git add ..." to include in what will be committed)

    .gitignore
    .idea/
    app/
    build.gradle
    gradle.properties
    gradle/
    gradlew
    gradlew.bat
    settings.gradle

nothing added to commit but untracked files present (use "git add" to track)

git add *

That's it, if you check again you'll see that your files are now added as files to checkin :

git status

On branch master

No commits yet

Changes to be committed: (use "git rm --cached ..." to unstage)

    new file:   .gitignore
    new file:   .idea/caches/build_file_checksums.ser
    new file:   .idea/codeStyles/Project.xml
    ....
Share:
62,304
AutoM8R
Author by

AutoM8R

I command a chihuahua army and make Android apps in my basement - http://goo.gl/ludism

Updated on December 02, 2020

Comments

  • AutoM8R
    AutoM8R over 3 years

    I am somewhat confused, I noticed that upon setting up my first Git repository in Android Studio all of the correct files to ignore were automatically added to the Project's Settings under Settings > Version Control > Ignored Files.

    This appeared to be magic, I never told it what to ignore. Moreover, there is no .gitignore file in any directory of my project as I'm used to creating.

    This being said, I can't get my second project to automatically add ignored files, and really, I just want to use the simple .gitignore method.

    Does anyone know how to override Android Studio's ignored files list and simply use a .gitignore instead? I'd like the ease of copying my .gitignore to all other projects I make, it does not appear you can copy Settings > Version Control > Ignored Files.

    Thank you for commenting on how I can just use .gitignore.

  • Sanyam Jain
    Sanyam Jain over 8 years
    Project registered as a Git root, but no Git repositories were found there.
  • DJphy
    DJphy about 8 years
    still my project does not look into the the .gitignore file; when clicking commit its considering even the files under build to commit
  • Frank
    Frank almost 8 years
    this ** up my project. make sure you backup before you try. The above answer from Tim Long solved my problem after I reverted to my backup.