简体   繁体   English

如何将IntelliJ IDEA项目链接到本地​​git存储库?

[英]How do I link an IntelliJ IDEA project to a local git repository?

I'm new to IntelliJ and trying to switch from Eclipse to IntelliJ. 我是IntelliJ的新手,正在尝试从Eclipse切换到IntelliJ。

In Eclipse it's done by creating a workspace and then importing the local repository. 在Eclipse中,它是通过创建一个工作区,然后导入本地存储库来完成的。 The workspace is separate from the repository. 工作空间与存储库是分开的。 The workspace only reference the repository. 工作空间仅引用存储库。

I want to do this in IntelliJ. 我想在IntelliJ中做到这一点。 I think the setup would be something like the project located in eg C:\\Projects\\MyProgram\\ with MyProgram having .idea in it. 我认为安装程序将类似于位于C:\\Projects\\MyProgram\\其中MyProgram具有.idea The actual code for MyProgram would be in eg C:\\Repos\\MyProgram.git . MyProgram的实际代码将在例如C:\\Repos\\MyProgram.git The repository would only contain code, not config files for the IntelliJ project. 该存储库将仅包含代码,而不包含IntelliJ项目的配置文件。 Alternatively I'd like to know how this is typcially done with IntelliJ. 另外,我想知道这是如何使用IntelliJ特别完成的。

Typically this is done 1 as follows: 通常,此操作如下进行1

  1. git clone your repo (if you don't already have it locally). git clone您的仓库(如果您在本地还没有)。
  2. In Intellij, open or import the root repo folder as a project. 在Intellij中,打开或导入根repo文件夹作为项目。
  3. Add .idea/ (or *.iml as appropriate) to your .gitignore file. .idea/ (或适当的*.iml )添加到.gitignore文件中。

I'm not sure if there's a good reason for trying to keep the IntelliJ files in a different part of your filesystem. 我不确定是否有充分的理由尝试将IntelliJ文件保留在文件系统的其他部分。 2 Some of the advice out there regarding Eclipse concerns the semantics of workspaces, which don't exist in IntelliJ. 2关于Eclipse的一些建议涉及工作空间的语义,这在IntelliJ中是不存在的。


1. To be more precise, this is how I typically do it :) 1.更准确地说,这就是通常的做法:)

2. Although I'm happy to be convinced otherwise! 2.尽管我很高兴能被说服!

You can specify a different content root in the "More Settings" while creating a project. 创建项目时,可以在“更多设置”中指定其他内容根。 This location is the one where you have your repository. 此位置是您存储库的位置。

在此处输入图片说明

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

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