32

I am having issues with the .iml files generated by Android Studio. On a Gradle sync, they are regenerated meaning I then have to do a commit even if nothing has changed. I just want to make these files untracked.

I have tried the following things.

  • Added *.iml to my project's .gitignore file as well as each module's .gitignore. I have tried both *.iml and **/*.iml
  • Used git rm --cached app/app.iml when they appear in the staged files list. Even after doing this and committing it, they appear as staged again later on.
  • As suggested here I added it to the Ignored Files in Settings under version control
2
  • /*/build/app.iml, .iml,.iml . Tried adding both to .gitingnore file? Commented Mar 2, 2016 at 15:09
  • @StuStirling Did you manage to solve this, if yes, how you did it? Commented Sep 3, 2018 at 14:17

3 Answers 3

45

You have the right steps, but you need to organize them

  1. git rm --cached <all_your_iml_files> to remove all of them from the remote repository.

    Alternatively you can do a simple command to delete all the *.iml files like git ls-files | grep "\.iml$" | xargs git rm --cached

  2. Commit that change using git commit -m "msg" and after that, you can see all your *.iml files as untracked files.

  3. Add *.iml to your .gitignore file and commit it in a separate commit or in the same previous commit.
Sign up to request clarification or add additional context in comments.

6 Comments

I have done this multiple times. In fact I do this everytime they reappear but they are always re-staged
I just tried those steps on my terminal and they are working. Is the problem IDE related?
I believe it's when gradle runs a sync, it regenerates the .iml files and stages them in GIT regardless of steps I have taken to prevent it
It can't stage them if they are not in the remote repository and added to the .gitignore at the same time. It must edit the .gitignore to do so.
I just removed all my .iml files using git rm --cached, committed, pushed it to the remote repository's branch and then did a gradle sync and the .iml files were once again added to the staging...
|
12

cd into project directory, git checkout and pull master branch

cd /home/your_user/project_directory
git checkout master
git pull origin master

edit .gitignore file to insert *.iml

git rm --cached **/*.iml
git commit -a -m "rm all *.iml, update .gitignore"
git push origin master

I was working on another maven & Java git project using Idea IDE and it seems to add *.iml in many of the child directories.

The glob syntax **/*.iml will cover all iml files in all directories within the current working directory.

Comments

0

I was having the same issue. What I tried at first was to add **/.iml in my .gitignore but all .iml files showed up in untracked files.

I changed **/.iml into *.iml and it worked and the files disappeared from untracked files.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.