0

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...

thebjorn
  • 26,297
  • 11
  • 96
  • 138
  • 1
    Possible duplicate of [Will git-rm --cached delete another user's working tree files when they pull](https://stackoverflow.com/questions/3318637/will-git-rm-cached-delete-another-users-working-tree-files-when-they-pull) – phd Jul 25 '19 at 21:23
  • https://stackoverflow.com/search?q=%5Bgit-rm%5D+other+users – phd Jul 25 '19 at 21:23
  • @phd that answers the comment about `git rm --cached ..` doing the right thing for other developers (no), but it it doesn't answer my _question_ "is there a way of diong this in git?" (like there is in svn..) – thebjorn Jul 25 '19 at 21:27
  • @phd the only related answer I found in that search was https://stackoverflow.com/questions/2604625/git-how-to-remove-file-from-index-without-deleting-files-from-any-repository/2612663#2612663 which I would interpret as "no it's not possible". Did I understand that correctly? – thebjorn Jul 25 '19 at 21:34
  • I would remove all IDE related files from the sources. If you absolutely need to share those files with your colleagues through git, you should clean the files from any personal data, put/move them into a different folder in your source tree (something like `devsupport/IDEs/idea/...`) and notify the team they should backup their local copies before update. Certainly after removing the files, you should add them into `.gitignore` to avoid similar incidents in future – user3159253 Jul 25 '19 at 21:40
  • @user3159253 the question initially had a PyCharm tag, since PyCharm requires the files be located in a folder named `.idea` in the root of the project. The project files contain inspection profiles, run configurations, etc. that take a considerable amount of time to set up. It's therefore imperative that the project files can be shared, but since JetBrains (makers of PyCharm) has no sensible guidance on which files will contain local paths this is a hit-and-miss operation. – thebjorn Jul 25 '19 at 21:47
  • Can you rename the file? Git decides what files its tracking based on what is already committed in `HEAD`. Whether or not new files are candidates for tracking is decided locally by the index and `.gitignore`. So, AFAIK, there's no way to untrack a file universally except to remove it from the repository. Devs can use ` `git update-index --assume-unchanged .idea/myproject.iml` but that only applies locally. – Schwern Jul 25 '19 at 22:51
  • 1
    @thebjorn Yes, not possible. – phd Jul 25 '19 at 23:06

1 Answers1

2

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.

user3159253
  • 16,836
  • 3
  • 30
  • 56
  • Thanks for the workflow. We potentially have 100+ repositories (not all have been transferred to gitlab yet), so probably not a workable solution for us - but I'm sure others might find it useful. The `.idea/` folder is a holy mess right now and we're hoping JetBrains will get to https://youtrack.jetbrains.com/issue/IDEA-90785 sometime soon... – thebjorn Jul 25 '19 at 23:17
  • @thebjorn "We potentially have 100+ repositories" So we do. In such a case a script that makes a merge is a must. In fact, since there're _many_ repositories, the need for a proper automation outweights the difficulty of its creation. Waiting for JetBrains to solve your problem is indeed another option, but I doubt it's a viable option :-) – user3159253 Jul 26 '19 at 00:33