将现有的 Git 存储库导入 IntelliJ IDEA

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15571451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:48:36  来源:igfitidea点击:

Import an existing Git repository into IntelliJ IDEA

gitintellij-idearepository

提问by vatzec

I have a local Git repository with my own branches, stashes and all that jazz, and I'd like to add this repository into IntelliJ IDEA, so that I can manage it, instead of creating a new copy of the repository from within IDEA. How do I do that?

我有一个本地 Git 存储库,其中包含我自己的分支、存储和所有爵士乐,我想将此存储库添加到 IntelliJ IDEA 中,以便我可以管理它,而不是从 IDEA 中创建存储库的新副本。我怎么做?

Thanks!

谢谢!

回答by Prasanna

The ideal way is to open the directory in Intellij,not trying to import it from repo. When you open the directory as project, Intellij will ask whether you need to configure VCS.

理想的方法是在 Intellij 中打开目录,而不是尝试从 repo 中导入它。当您将目录作为项目打开时,Intellij 会询问您是否需要配置 VCS。

Or even after creating a project in Intellij,you can goto VCS menu and include into Git repo.

或者甚至在 Intellij 中创建项目后,您可以转到 VCS 菜单并将其包含到 Git 存储库中。

回答by Cari

You can actually use an existing repo. Just go to Openand open the directory that you want to be your root. Then select the git repo directory, go to the VCS menu, and select Enable Version Control Integration.

您实际上可以使用现有的存储库。只需转到“打开”并打开您想要作为根目录的目录。然后选择 git repo 目录,进入 VCS 菜单,选择Enable Version Control Integration

That's all it took me. That was how easy it was on a Mac. Not sure if the flow is exactly the same on other platforms.

这就是我的全部。这在 Mac 上是多么容易。不确定其他平台上的流程是否完全相同。

回答by ryenus

Essentially it's just two steps:

本质上只需要两步:

  1. Specify VCS root,

    This should be done in Preferences (?,) > Version Control

  2. Enable Version Control Integration

    if you can find this option in Menu > VCS, good luck, just click it. Otherwise, select Menu > Help > Find Action...(??A), then type Enable Version Control Integration, and just press the Enterkey.

  1. 指定 VCS 根,

    这应该在Preferences ( ?,) > Version Control 中完成

  2. 启用版本控制集成

    如果您可以在Menu > VCS 中找到此选项,祝您好运,只需单击它。否则,选择Menu > Help > Find Action...( ??A),然后键入Enable Version Control Integration,然后按Enter键。

回答by Ryan Walls

When you start up intellij and no projects are open, there is a dialog option to "import from VCS". Choose that instead of create new project or import project.

当您启动 intellij 并且没有打开任何项目时,有一个“从 VCS 导入”的对话框选项。选择它而不是创建新项目或导入项目。

回答by Andrey Cizov

On the latest version of IntelliJ IDEA, when the project contains more than one module and one of the modules is already tied to VCS integration, the VCS > Enable Version Control Integrationmenu will not appear. This happens in the case when one of the modules was missing a relevant .gitdirectory before the integration was added to the project.

在最新版本的 IntelliJ IDEA 上,当项目包含多个模块并且其中一个模块已经绑定到 VCS 集成时,将不会出现VCS > 启用版本控制集成菜单。如果在将集成添加到项目之前模块之一缺少相关的.git目录,就会发生这种情况。

Solved by browsing to the relevant project's .idea/vcs.xmlfile and then adding another line such as:

通过浏览到相关项目的.idea/vcs.xml文件然后添加另一行来解决,例如:

<mapping directory="$PROJECT_DIR$/../project_name" vcs="Git" />

The changes should immediately reflect in the UI (e.g. changed lines will be highlighted).

更改应立即反映在 UI 中(例如,更改的行将突出显示)。