Search code examples
gitandroid-studiogitignore

How can I Remove .iml files from a Git repository?


How can I keep everyone's .iml files out of an existing git project?

(I'm on a Mac)


Solution

  • remove all existing offenders:

    find . -name "*.iml" -print0 | xargs -0 git rm -f --ignore-unmatch
    

    then add *.iml .gitignore:

    echo *.iml >> .gitignore
    git add .gitignore
    

    and commit the change:

    git commit -m '.iml banished!'
    

    It's also possible to do this all at once:

    find . -name "*.iml" -print0 | xargs -0 git rm -f --ignore-unmatch; echo *.iml >> .gitignore; git add .gitignore; git commit -m '.iml banished!'
    

    Answer modified from benzado and Chris Redford's excellent answer https://stackoverflow.com/a/107921/2570689 to How can I Remove .DS_Store files from a Git repository?