0

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

(I'm on a Mac)

timeSmith
  • 553
  • 1
  • 8
  • 16
  • 3
    https://git-scm.com/docs/gitignore ? – xlecoustillier May 03 '19 at 12:46
  • Yeah, but what about once they are already in there? – timeSmith May 03 '19 at 12:48
  • https://stackoverflow.com/questions/7927230/remove-directory-from-remote-repository-after-adding-them-to-gitignore – xlecoustillier May 03 '19 at 12:50
  • If it's _your_ project _you_ control it. Don't give write access to people you don't trust. Require users to submit pull requests and review them. If they contain `.iml` files ask the contributors to remove them before merging. – ChrisGPT was on strike May 03 '19 at 12:51
  • @xlecoustillier That's fine for one file. These are loads of them. I don't want to have to do this one at a time! Obviously I got as far as your responses with my pre question googling. – timeSmith May 03 '19 at 12:52
  • @Chris that's fine if I know it could be a problem before starting the project. Apparently there is some dispute about if .iml files should be included in version control. I had no idea. – timeSmith May 03 '19 at 12:54
  • @timeSmith And that would have been a delight if you had specified that right from the start, as we can't really know that, you know. – xlecoustillier May 03 '19 at 12:54
  • Just use wildcards : https://stackoverflow.com/questions/9529354/git-rm-several-files – xlecoustillier May 03 '19 at 12:55
  • 1
    @timeSmith, don't assume that things are "obvious". If you don't _tell us_ what you've already tried, or give us _details_ about your problem, we can't help very well. Be as clear as possible. Ideally, you should provide a [mcve]. Please read [ask]. – ChrisGPT was on strike May 03 '19 at 12:55
  • @Chris I think that most people on stack overflow make a habit of doing a fair amount of searching before posting a question. I have never seen a list of all the things a person has already discovered included in their question. One time I tried that, because the subject (Apache server-side rewrites) seemed particularly prone to being downvoted. I got downvoted quickly in that case with no comment or explanation. So the extra effort involved in chronicling the history of the pursuit seems useless at best. – timeSmith May 03 '19 at 13:00
  • 1
    @timeSmith, this question (a) doesn't show any research effort and (b) is unclear. Again, _don't assume things_. The [ask] page isn't something I came up with; it's _the official Stack Overflow guide_. Being open to feedback and responsive is a good mindset to have when asking questions here. The rules are designed to help all users, including yourself. Defensiveness rarely helps. – ChrisGPT was on strike May 03 '19 at 13:06
  • @Chris I'm sorry, I'm really doing what I can. I did "Pretend you're talking to a busy colleague." IRL I'm usually quite verbose, so I work very hard on that one here on stack overflow. There is no code involved here, and the documents you posted talk a lot about code. After reading the documentation you referenced I have added the word "existing" and "I'm on a Mac" which I think now satisfies these requirements. Any additional help would be appreciated. – timeSmith May 03 '19 at 13:15
  • @xlecoustillier I'm sorry if I seemed abrasive. Chris suggested that I was not "being open to feedback." I'm not sure how I was supposed to respond, unless the downvotes were to suggest that I should delete my question. But I am truly sorry if my responses were somehow inappropriate. And now that someone has attempted to answer the question I cannot delete it. Fortunately I have found a solution. – timeSmith May 03 '19 at 13:28
  • @timeSmith No problem. According to the site's guidelines, people are supposed to make some research beforehand, so I get why you thought we'd assume you did. The thing is that most of the time, people asking this kind of question didn't, like at all. I don't really know what you should do regarding this question, but even if it's incomplete as Chris said, now it has relevant answers, so even if it gets cloased eventually, it now can be useful to future readers. So maybe I wouldn't bother and just leave it be. – xlecoustillier May 03 '19 at 14:33

2 Answers2

3

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?

timeSmith
  • 553
  • 1
  • 8
  • 16
2

git rm supports wildcards (and globs). So you could do

git rm -r 'src/*.iml'

and be done (obviously, substitute whatever folder the iml files are in for 'src')

Pascal S
  • 121
  • 1
  • 4