您的位置 首页 php

PHPstorm打开多项目(非子目录)管理多个git仓库

前言

PHPstorm是一个非常优秀的开发工具,开发效率惊人,但是也有一些缺点,比如:内存占用过高、一个窗口只能打开一个项目,虽然可以设置子文件夹,但是子目录的git管理只能用一个。今天介绍一个如果一个窗口显示多个项目,并且同时管理多个git仓库,互相不影响。

多开项目

目录结构

在同一个目录创建两个项目目录

生成配置文件

用IDE分别打开 test1 test2 文件夹

然后在该目录生成 test1\.idea 的目录,这里有IDE生成的项目配置文件

配置多项目

1.打开 webroot\test1\.idea\modules.xml 原文件

 <?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/.idea/test1.iml" filepath="$PROJECT_DIR$/.idea/test1.iml" />
    </modules>
  </component>
</project>
  

改为

 <?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/.idea/test1.iml" filepath="$PROJECT_DIR$/.idea/test1.iml" />
      <module fileurl="file://$PROJECT_DIR$/../test2/.idea/test2.iml" filepath="$PROJECT_DIR$/../test2/.idea/test2.iml" />
    </modules>
  </component>
</project>
  

说明:

 
/**
* 每个 <module fileurl="" filepath=" /> 相当于一个项目
* fileurl 和 filepath 就是项目的配置文件路径(指向:项目目录\.idea\项目名称.imx)
* $PROJECT_DIR$ : 表示当前项目的目录(webroot\test1)
* 第二个目录路径是 webroot\test2 
* 所以,第二个项目的路径要写成:file://$PROJECT_DIR$/../test2/.idea/test2.iml
**/  

然后用IDE打开 test1 文件夹,就会发现 test2 文件,也出现在项目中,并且目录与 test1 同级,而不是在 test1 目录下.

  1. 开 file->settings->directories 可以看到的确是平级目录,而非子目录。


一个窗口管理多个git项目

激活IDE的vcs

  1. 初始化git仓库
 cd test1
git init
cd test2
git init  
  1. 生成vcs.xml文件

在IDE中打开项目文件夹 test1 ,右键新建一个文件,IDE 会提示添加到git暂存,点击 “确定”,然后会在 test1\.idea 生成文件 vcs.xml

配置git

  1. 打开 test1\.idea\vcs.xml 原文如下:
 <?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="VcsDirectoryMappings">
    <mapping directory="$PROJECT_DIR$" vcs="Git" />  </component>
</project>
  

修改为:

 <?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="VcsDirectoryMappings">
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$/../test2" vcs="Git" />
  </component>
</project>
  

说明:

 /**
* 每个 <mapping directory="$PROJECT_DIR$" vcs="Git" /> 就是一个git仓库
* 其中 directory:仓库根目录;
* $PROJECT_DIR$项目根目录
* 路径与前面的 modules.xml配置相似,要用相对路径。
* 第二个git仓库路径就是:$PROJECT_DIR$/../test2
**/  

结果展示:

  1. 可以看到在两个目录里添加文件,都会显示git状态颜色

  1. Ctrl + k 可以分别提交git

最后 : 如果需要配置更多的项目和git仓库管理,按照上面的方法依次操作即可.

文章来源:智云一二三科技

文章标题:PHPstorm打开多项目(非子目录)管理多个git仓库

文章地址:https://www.zhihuclub.com/149988.shtml

关于作者: 智云科技

热门文章

网站地图