StuStirling
StuStirling

Reputation: 16211

Remove .iml Files From GIT for Good

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.

Upvotes: 31

Views: 35020

Answers (2)

Ahmed Hegazy
Ahmed Hegazy

Reputation: 12615

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.

Upvotes: 44

James T.
James T.

Reputation: 978

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.

Upvotes: 11

Related Questions