简体   繁体   English

如何在 Intellij Idea 12 中重命名/移动项目?

[英]How to rename / move a project in Intellij Idea 12?

As stated here one can change the name of a project.正如此处所述您可以更改项目的名称。 However, it only changes the name of the project and it will not change the folder structure.但是,它只会更改项目的名称,而不会更改文件夹结构。

As an example if your project is called sample1 and it resides ~/user1/development/IdeaProjects/sample1, the folder location won't be changed to ~/user1/development/IdeaProjects/sample2 if one changes the project name to sample2.例如,如果您的项目名为 sample1 并且它位于 ~/user1/development/IdeaProjects/sample1,则如果将项目名称更改为 sample2,文件夹位置将不会更改为 ~/user1/development/IdeaProjects/sample2。

It seems that one has to right click on the project (after following the instructions to rename the Project), then choose Refactor -> Move to relocate project to the new location.似乎必须右键单击项目(按照说明重命名项目后),然后选择 Refactor -> Move 将项目重新定位到新位置。 I didn't find any solution to rename and move a project at once.我没有找到任何可以立即重命名和移动项目的解决方案。

  1. Right click on project, then Refactor -> Rename... (shift+F6), set desired name右键单击项目,然后重构 -> 重命名... (shift+F6),设置所需的名称
  2. Close IntelliJ关闭 IntelliJ
  3. Rename directory in your filesystem to your desired name将文件系统中的目录重命名为您想要的名称
  4. In startup dialog select Open (or File -> Open ... in main window)在启动对话框中选择Open (或File -> Open ... 在主窗口中)
  5. Please select renamed project directory请选择重命名的项目目录

Enjoy, it work's for me!享受,它对我有用!

  1. Close IntelliJ关闭 IntelliJ
  2. Rename the folder in Explorer (Windows) / Finder (OSX)重命名资源管理器 (Windows) / Finder (OSX) 中的文件夹
  3. Open IntelliJ打开 IntelliJ
  4. Import Project from Dialog, or File -> Import Project从对话框或文件导入项目 -> 导入项目
  5. Select the folder with the new name选择具有新名称的文件夹
  6. Follow the dialogues关注对话

If it is a gradle project, instead of renaming it using Refactor->Rename :如果它是一个 gradle 项目,而不是使用Refactor->Rename 重命名它:

  • set the rootProject.name variable in the settings.gradle file to the new project name.settings.gradle文件中的rootProject.name变量设置为新项目名称。
  • reimport the project.重新导入项目。 Hit the 'Refresh all Gradle Projects' button in the Gradle Tool Window.点击 Gradle 工具窗口中的“刷新所有 Gradle 项目”按钮。

Then follow steps 2 to 5 in @Dawid's answer .然后按照@Dawid 的回答中的步骤 2 到 5 进行操作。

To remove the old project from IntelliJ's list of managed projects:从 IntelliJ 的托管项目列表中删除旧项目:

  • select File->Open Recent->Manage Projects..选择文件->打开最近的->管理项目..
  • click the 'x' next to the old project name单击旧项目名称旁边的“x”
  1. Go to File then Project Structure转到File然后是Project Structure
  2. Under Project Settings -> Project make sure that you change the project name.Project Settings -> Project确保更改项目名称。
  3. Then under Project Settings -> Modules change the name there as well.然后在Project Settings -> Modules更改名称。
  4. Restart Intellij重启 Intellij
  5. Use your File Explorer to confirm that the project/modules have been renamed.使用文件资源管理器确认项目/模块已重命名。

After renaming the project folder of a Kotlin project in IntelliJ, using the Import Project option as suggested in the other answers created module related problems for me.在 IntelliJ 中重命名 Kotlin 项目的项目文件夹后,使用其他答案中建议的导入项目选项为我创建了与模块相关的问题。 I was not able to select Main class in the Run dialogue.我无法在 Run 对话框中选择 Main 类。 To solve this, I used Create New Project option.为了解决这个问题,我使用了Create New Project选项。 It doesn't delete your project files.它不会删除您的项目文件。

So to rename the folder, first create a copy of your project for safety and then follow these steps:因此,要重命名文件夹,请先创建项目的副本以确保安全,然后按照以下步骤操作:

  1. Close IntelliJ.关闭 IntelliJ。
  2. Go to file explorer and manually rename the folder.转到文件资源管理器并手动重命名文件夹。
  3. Open IntelliJ.打开 IntelliJ。
  4. Choose the option Create New Project选择选项Create New Project
  5. Select your desired language/framework eg Kotlin , click Next选择你想要的语言/框架,例如Kotlin ,点击Next
  6. For Project Name , specify your desired project name.对于Project Name ,指定所需的项目名称。 Maybe same as folder name.可能与文件夹名称相同。
  7. For Project Location , choose the folder that you manually renamed .对于Project Location选择您手动重命名的文件夹
  8. Click Finish , IntelliJ will ask if you want to overwrite .idea and .iml files.单击Finish ,IntelliJ 会询问您是否要覆盖.idea.iml文件。 Click Yes for both.两者都单击Yes

Hope that helps.希望有帮助。

For JetBrains v. 2019.2 (September 2019):对于 JetBrains v. 2019.2 (2019 年 9 月):

To move project directory without changing it's name:要移动项目目录而不更改其名称:

  1. Press Alt+1 to open project structureAlt+1打开项目结构

    • Right click on project directory右键单击项目目录
    • Go to File -> Refactor -> Move directory转到文件 -> 重构 -> 移动目录

    OR要么

    • Left click on project directory左键单击项目目录
    • Press F6F6

    Specify target parent directory and hit OK.指定目标父目录并点击确定。

To rename project directory:重命名项目目录:

  1. Press Alt+1 to open project structureAlt+1打开项目结构

    • Right click on project directory右键单击项目目录
    • Go to File -> Refactor -> Rename...转到文件 -> 重构 -> 重命名...

    OR要么

    • Left click on project directory左键单击项目目录
    • Press Shift+F6Shift+F6
  2. Select Rename directory (actually it's already selected) and hit OK.选择重命名目录(实际上它已经被选中)并点击确定。

  3. Specify new directory name.指定新目录名称。

If you need both to move project directory and to change it's name, then do the steps one after another.如果您需要移动项目目录并更改其名称,请一个接一个地执行这些步骤。

After you've done renaming/moving, close the project and remove it from the recent projects list (it became non-functional and you won't need it anymore there).完成重命名/移动后,关闭项目并将其从最近的项目列表中删除(它变得不起作用,您将不再需要它)。

Then hit "Open" and find the project directory at it's new location.然后点击“打开”并在新位置找到项目目录。 Now you have your project directory moved!现在你已经移动了你的项目目录!

The last two steps should be done with a command like Edit project or something like that, where you can directly specify project directory, but as there is no such command, you need to remove project and reopen it at it's new location instead.最后两个步骤应该使用像 Edit project 或类似的命令来完成,您可以在其中直接指定项目目录,但由于没有这样的命令,您需要删除项目并在新位置重新打开它。

单击您要移动的项目文件,然后按 F6

Close IntelliJ 
Rename the folder in Explorer (Windows) / Finder
(OSX)   
Open IntelliJ Import Project from Dialog, or File -> Import
Project     
Select the folder with the new name 
further additional steps might be required if you see your module named
as  new_modulename[parent module/old module name],
then update   
settings.gradle with new name  and reimport

A work-arround for this, if you get an error when click "projectPackage" -> Refactor -> Move, is to close Intellij, move the folder manually, and then in:对此的解决方法是,如果在单击“projectPackage”-> 重构-> 移动时出现错误,请关闭 Intellij,手动移动文件夹,然后在:

C:\\Users\\user.name\\ .IntelliJIdea2019.1\\config\\options C:\\Users\\user.name\\ .IntelliJIdea2019.1\\config\\options

edit the file recentProjects.xml like this, with you new path, save and close, re-open jetbrains ide and it's done.像这样编辑文件recentProjects.xml,使用新路径,保存并关闭,重新打开jetbrains ide,就完成了。

配置文件

Well, I have figured this out and I will write down a step by step guide to how to rename the project directory linked to a GitHub repo.好吧,我已经弄清楚了,我将写下有关如何重命名链接到 GitHub 存储库的项目目录的分步指南。

Situation:情况:

  • Windows 10视窗 10
  • IntelliJ project is linked with a GitHub repo IntelliJ 项目与 GitHub 存储库相关联
  • I want to rename the GitHub repo and the project directory name and keep all my work the same.我想重命名 GitHub 存储库和项目目录名称,并使我的所有工作保持不变。

Solution:解决方案:

  1. rename the repo on GitHub, make sure pages is still working with the new name重命名 GitHub 上的 repo,确保页面仍在使用新名称
  2. rename the project from IntelliJ by (right-click on the parent directory -> refactor -> rename)从 IntelliJ 重命名项目(右键单击父目录 -> 重构 -> 重命名)
  3. rename the directory from IntelliJ by (right-click on the parent directory -> open module settings -> project)重命名 IntelliJ 中的目录(右键单击父目录 -> 打开模块设置 -> 项目)
    3.1. 3.1. update "project name"更新“项目名称”
    3.2. 3.2. update project compiler output更新项目编译器输出
  4. rename the GitHub remote repo from IntelliJ by (VCS -> git -> remotes)通过 (VCS -> git -> remotes) 从 IntelliJ 重命名 GitHub 远程存储库
  5. close IntelliJ关闭 IntelliJ
  6. open System Explorer打开系统资源管理器
    6.1. 6.1. rename the project directory重命名项目目录
    6.2. 6.2. open "workspace.xml" and rename all occurrence of the old word (you might want to cut it in another place, update it, then paste it back)打开“workspace.xml”并重命名所有出现的旧单词(您可能想将其剪切到另一个位置,更新它,然后将其粘贴回去)
  7. open IntelliJ and select import project打开 IntelliJ 并选择导入项目
  8. now, everything is okay, you can use Git inside IntelliJ normally as nothing has happened!现在,一切正常,您可以在 IntelliJ 中正常使用 Git,因为什么也没发生!

That is it, I just made a push from IntelliJ to the renamed repo and everything works as before without any mention of the old name.就是这样,我只是从 IntelliJ 推送到重命名的 repo,一切都像以前一样工作,没有提及旧名称。

I know that probably I won't be able to help sheidaei after more than 7 years from asking question, but I hope that someone will find it useful :)我知道在提出问题超过 7 年之后,我可能无法帮助 sheidaei,但我希望有人会发现它有用:)
To change project directory name of a current project without closing Intellij, choose view of "Project Files" in drop-down menu in the project browser (typically on the left) instead of "Project".要在不关闭 Intellij 的情况下更改当前项目的项目目录名称,请在项目浏览器(通常在左侧)的下拉菜单选择“项目文件”视图而不是“项目”。
How to select "Project Files" view in project browser如何在项目浏览器中选择“项目文件”视图
Then use right-click on project's directory name /path to open context menu.然后使用右键单击项目的目录名称/path 打开上下文菜单。
Use Refactor->Rename .使用Refactor->Rename
Finding option "Rename" in context menu在上下文菜单中找到选项“重命名”
Type in a new directory name, apply changes using button "Refactor" and that's it.输入一个新的目录名称,使用“重构”按钮应用更改,就是这样。
"Rename" dialog box “重命名”对话框
If you wish to change Module Name to match directory name, use Refactor->Rename option on project name in "Project" view of project browser.如果您希望更改模块名称以匹配目录名称,请在项目浏览器的“项目”视图中的项目名称上使用 Refactor->Rename 选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM