7

Iv'e added:

*.iml 

to all of the gitignore files in my project. They are still being tracked, even after committing the .gitignore.

Magnus Bäck
  • 11,381
  • 3
  • 47
  • 59
JY2k
  • 2,879
  • 1
  • 31
  • 60

2 Answers2

26

The safe option is to remove the iml file from your staging index.

git rm --cached <path to iml file>

git will track the files sometimes even if you added the file which shouldn't be tracked in .gitignore

In that case you should remove the cache first then add all.

Important : Before, commit or stash your current changes

$ git rm -r --cached .
$ git add .
$ git commit -m "file tracking - changed"
Deniz
  • 12,332
  • 10
  • 44
  • 62
  • git rm -f -r --cached . – konmik Nov 07 '15 at 18:18
  • 2
    This answer should be may break things in a code base and hence should not be here, or the author should add a warning. – amar Aug 29 '17 at 08:50
  • Future readers: don't be afraid of this answer: It does **not** require a later commit where all-project files are added again, polluting the git history. After all the files did not change in between, so this answer really suggests the right thing. – spawn Sep 10 '22 at 09:12
  • @spawn yes it does, this answer is not stable. – backward forward Dec 26 '22 at 20:43
0

When you added them one time, they will keep tracked!

You have to retrieve all commits till the one where you commited the .iml files.

Here is a good post on SF about reseting commits in git: How to revert Git repository to a previous commit?

Community
  • 1
  • 1
Rene M.
  • 2,660
  • 15
  • 24
  • 1
    This answer would be more useful if you linked to documentation and/or previous Stackoverflow answers to this FAQ. – Magnus Bäck Apr 01 '15 at 08:39