向 IntelliJ IDEA 中的现有项目添加 GIT 支持

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8724748/
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 12:38:10  来源:igfitidea点击:

Adding GIT support to existing project in IntelliJ IDEA

gitmavenintellij-idea

提问by jdevelop

I have multi-module project built with Maven. I imported only single sub-module (not parent) from that project as IDEA project, and looks like IDE doesn't recognize .git folder (because it is one level up from project root I used to import, I guess)

我有使用 Maven 构建的多模块项目。我从该项目中只导入了一个子模块(不是父模块)作为 IDEA 项目,看起来 IDE 无法识别 .git 文件夹(因为它是我以前导入的项目根目录的一个级别,我猜)

Is there still a possibility to add Git support for intelliJ somehow?

是否还有可能以某种方式为 intelliJ 添加 Git 支持?

回答by Alexander Temerev

I have successfully opened a Maven subproject within IDEA. Naturally, it hasn't enabled Git integration automatically. From VCS menu I have selected "Enable Version Control Integration" and chose "Git" from submenu.

我已经成功地在 IDEA 中打开了一个 Maven 子项目。当然,它没有自动启用 Git 集成。从 VCS 菜单中,我选择了“启用版本控制集成”并从子菜单中选择了“Git”。

Then IDEA complained that there is no .git folder within the project and offered to select parent .git folder. I did it and everything worked as expected.

然后 IDEA 抱怨项目中没有 .git 文件夹并提供选择父 .git 文件夹。我做到了,一切都按预期进行。

If you don't have Git option in VCS menu, this might be a bug. Try to disable SVN plugin and see if that helps (I don't have SVN plugin in my IDEA).

如果您在 VCS 菜单中没有 Git 选项,这可能是一个错误。尝试禁用 SVN 插件,看看是否有帮助(我的 IDEA 中没有 SVN 插件)。

回答by user830914

You may need to add git to the list of version control in the settings

您可能需要将 git 添加到设置中的版本控制列表中

settings > Version Control

设置 > 版本控制

then make sure that git is listed in the table as a VCS

然后确保 git 作为 VCS 列在表中

I had to do this otherwise git wasn't listed in the VCS menu in the menu bar.

我必须这样做,否则菜单栏中的 VCS 菜单中不会列出 git。

Make sure Git is in one of the columns here

确保 Git 位于此处的列之一中

回答by Patrice

Just delete .idea/vcs.xml and restart intelliJ

只需删除 .idea/vcs.xml 并重新启动 intelliJ

回答by Domenic D.

In my case, we had recently upgraded from CVS to GIT (gasp). There were some old CVS specific files in the project (i.e. .cvsignore) that must have indicated to IntelliJ that this was a CVS project. I had to manually remove this file for IntelliJ to recognize the new .git folder and related files.

就我而言,我们最近从 CVS 升级到 GIT(喘气)。项目中有一些旧的 CVS 特定文件(即 .cvsignore)必须向 IntelliJ 表明这是一个 CVS 项目。我必须手动删除这个文件,IntelliJ 才能识别新的 .git 文件夹和相关文件。

回答by James Watkins

In my case, I was not able to get Intellij to detect Git on the module. So I removed the module from the project and re-added it. That time it was detected and I could use the Git menu.

就我而言,我无法让 Intellij 检测模块上的 Git。所以我从项目中删除了模块并重新添加了它。那个时候它被检测到,我可以使用 Git 菜单。

回答by sweetfa

If your issue is that the Version Control tab is missing use View/Tool Windows/Version Control.

如果您的问题是缺少版本控制选项卡,请使用查看/工具 Windows/版本控制。

This will bring the Version Control window into the bottom frame, provided all the remaining pieces of your git configuration are correct.

这会将版本控制窗口带入底部框架,前提是您的 git 配置的所有其余部分都是正确的。

回答by Adam Dymitruk

Consider using Git outside of the IDE. There are great efficiencies to be gained from the command line in Git.

考虑在 IDE 之外使用 Git。在 Git 中使用命令行可以获得极大的效率。