Copying Settings from 1 project to another: the "After"

I have 2 different projects for 2 different clients, say P1 and P2, located at totally different locations in the FS.

After making a lot of changes in the Settings of P1 (Inspections handling, syntax highlighting etc...) I thought it would be a good idea to reflect all these Settings changes on P2, without having the hassle of repeating the Settings operations.

So I followed an answer from SO or here (don't recall exactly) that tells "Just copy the .idea dir from P1 to P2".

And so did I, which works fine except for one thing:
- after working on P2, I close P2 then re-open P1, but I have to reopen all the files that I worked on P1 previously (the history seems gone, no file in the Editor Tabs)
- and similarly, after working on P1, I close P1 then re-open P2, but I have to reopen all the files that I worked on P2 previously (same "blank" tabs)

Meaning, opening P1 after P2, or P2 after P1, no file is opened from the previous session anymore. 

Is there some kind of absolute path in a .idea file that tells the history location, thus P1 & P2 would have the same...?
What can I change to avoid the problem?

Thanks

(Using PS 2021.1.2, latest stable)

 

0

Hi there,

Well, that "just copy files over" is no longer 100% valid. At very least for some files. Used to work -- used it myself in the past (was also giving such advice/answer on SO myself).

The worskpace.xml is the most important file here.

1. worskpace.xml has a reference to tasks / changelist  that has a unique id. Look for ```<component name="TaskManager">``` node. Not sure how important that is though, especially if you use any VCS.

2. Most importantly the worskpace.xml file now contains only part of the settings now: the one that can be more-or-less shared/moved between computers. The second part for about 2+ years now is stored separately and this IDE is used as a file name there.

So, look for ```<component name="ProjectId" id="XXXXX" />``` node.

The machine/user-specific workspace settings will be stored in ```IDE-wide-config\workspace\XXXXX.xml``` file (e.g. on Windows for 2021.1 version that would be ```C:\Users\USERNAME\AppData\Roaming\JetBrains\PhpStorm2021.1\workspace\XXXXXX.xml```)

Since you are using the same "machine-specific workspace" file by 2 projects then certain settings will likely be lost when used by another project (since the files in one project may not necessarily be present in another).

I have not tried that myself, but this should work:

  1. Close IDE
  2. Change the Project ID for P2. I do not know how it's generated, but try changing 1 or 2 letters there -- should be OK. Save.
  3. Not sure if tasks/changelist ID needs to be updated as well (if it would be me I would just delete the whole node: the IDE will make a new one).
  4. Go to the machine-specific workspaces folder and make a copy of the corresponding file -- name it the same as new Project ID for P2.

In theory this might be enough. On first opening you may still loose the same settings for one of the projects just like before though but subsequent runs should work OK.

 

P.S. Instead of doing that (copying the whole .idea folder) I would suggest to set the 2nd project up from the scratch and then copy individual files cross from .idea -- most of them can be copied just fine (as they can be shared with a team/in VCS). For certain things (like Run/Debug Configs, custom Scopes etc) use "Shared" option whenever possible -- each entry then will be saved as a separate config file instead of be stored in workspace.xml.

1

Thanks Andriy. Great support.

Based on your answer, this is what I did, if that can help someone else.

I'm on Linux and the global settings are now in  ~/.config/JetBrains/PhpStorm2021.1 (they used to be in ~/.PhpStorm201x.y).

In there, `workspace`, I found the real ID for P2 (P2_ID.xml), then went to the .idea of P2 and edited there workspace.xml to replace 

<component name="ProjectId" id="P1_ID" />

which came from my previous blind copy, to

<component name="ProjectId" id="P2_ID" />

and everything seems fine now :)

Thanks again.

0

请先登录再写评论。