.gitignore not ignoring!

As a developer that took over a project there are some issues you never had before. One of them is this one.

While coding for a new feature I wanted to commit my small task to github. One of the changes was .idea/workspace.xml. I thought… wait a min… this should be in the .gitignore file. I was surprised the previous developer didn’t do this at the start of the project. Until I noticed he did added it to the .gitignore file.

The confusion started and I checked every .gitignore file since this is a multi-module project. But still everything was set up correctly. I went to Stackoverflow and within a minute I found this:

https://stackoverflow.com/questions/32384473/gitignore-not-ignoring-idea-path

Quote of the year:

.gitignore only ignores newly added (untracked) files.

I checked Github and there was indeed a workspace.xml pushed to the project. I followed the command listed in Stackoverflow. But you should never just copy-paste code without knowing what it does. So I looked it up.

Command

git rm --cached -r .idea

git-rm – Remove files from the working tree and from the index

–cached – Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

-r – Allow recursive removal when a leading directory name is given.

Seemed legit, executed it and the workspace.xml disappeared from my git changes. I’m a happy developer yet again.

Add a Comment

Your email address will not be published. Required fields are marked *