thebjorn
thebjorn

Reputation: 27351

Adding a single tracked file to .gitignore without deleting it?

I've just discovered that my .idea/myproject.iml file, which is checked in, contains a local path. I therefore need to add it to .gitignore and make git not track it anymore.

I (and everyone else) would like to keep our local version of .idea/myproject.iml since it is correct locally.

I was initially considering git rm --cached .idea/myproject.iml, but that is not a solution since it will delete the file from every other developer. Is this possible in git?

I noticed that tortoise-svn has an "unversion and add to ignore list" command, while tortoise-git has a "delete and add to ignore list", which makes me think that it is not possible...

Upvotes: 1

Views: 85

Answers (1)

user3159253
user3159253

Reputation: 17455

Since comments are hard to format, let's switch to the answer mode, although it's not really an answer, just an extended advise.

since PyCharm requires the files be located in a folder named .idea in the root of the project.

Indeed. The whole idea is to share (templates of) IDE-related files via a place other than their regular location and .ignore any unintended changes in actual IDE settings.

That is the whole workflow should look like this:

  1. create a backup copy of your actual IDE settings
  2. put cleared versions of IDE settings into a dedicated subfolder within source tree
  3. remove them from their regular location(s)
  4. add appropriate .gitignore entries
  5. make a commit with settings templates, added to a subfolder, settings removed from the source tree and updated .gitignore
  6. restore the settings from the backup. Now git will ignore all further changes in the files.
  7. notify all team members about the change of the policy to commit IDE settings and the need to backup their local settings before the update.
  8. In future, when one needs to to share a new piece of IDE stuff with colleagues, she has to copy chunks from her regular IDE settings to appropriate settings templates.

The workflow may seem cumbersome, but it looks like you don't have an other option to accomplish the task. On the one hand you don't have a full control over contents of IDE-managed files and can't simply delegate the right to make shareable changes to the IDE (some local stuff can accidently leak as it's happenned already). On the other hand it's really boring and error-prone to force team members to control it manually on every commit.

Perhaps you can create some supporting scripts to merge changes from settings templates to the regular settings. IDEA uses XML files for its settings so the task of merging changes from a template to a file looks pretty doable.

Upvotes: 2

Related Questions