如何在 Eclipse 项目上创建 git 存储库,反之亦然?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2062861/
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
How do I create a git repository over an eclipse project or vice versa?
提问by Sastopher
I have a git repository that is just a directory tree (/myprogram/src/com/mycompany/test) with some source files. I wish to create an eclipse project around this repository. Both orders of create project
in eclipse and git clone <url> <myprogram>
from the command line give me a "folder already exists" error from whatever tool I use last. I could move the files manually to merge them, but it feels messy and I'm not 100% confident I know which files to touch.
我有一个 git 存储库,它只是一个带有一些源文件的目录树 (/myprogram/src/com/mycompany/test)。我希望围绕这个存储库创建一个 eclipse 项目。create project
在 eclipse 和git clone <url> <myprogram>
命令行中的两个命令都给我一个“文件夹已经存在”的错误,无论我最后使用的是什么工具。我可以手动移动文件以合并它们,但感觉很混乱,而且我不是 100% 确信我知道要触摸哪些文件。
How is this supposed to be done properly?
这应该如何正确完成?
回答by Fabian Steeg
You could do it by selecting Import-> Existing Projects into Workspace, select the directory containing your project (the parent of myprgram), and check the checkbox next to your project (myprogram).
您可以通过选择Import-> Existing Projects into Workspace 来实现,选择包含您的项目的目录(myprgram的父目录),然后选中您的项目旁边的复选框(myprogram)。
To have Git support in Eclipse, install eGitand then right-click your project, select Team-> Share Project-> Git, expand the triangle to select the existing repository and click Finish. This should give you Git annotations on your project.
要在 Eclipse 中获得 Git 支持,请安装eGit,然后右键单击您的项目,选择Team-> Share Project-> Git,展开三角形以选择现有存储库并单击Finish。这应该为您的项目提供 Git 注释。
Another option might be to just select Import-> Git-> Git Repository(after eGit is installed) and import your repository (but I've never done that with a local repository). See also the eGit user guide.
另一种选择可能是只选择Import-> Git-> Git Repository(在安装 eGit 之后)并导入您的存储库(但我从未使用本地存储库这样做过)。另请参阅eGit 用户指南。
回答by Sastopher
To resolve this I just ended up copying the git repository into a newly created project, but upon revisiting the issue I found a link herethat suggests something slightly more elegant (but functionally similar).
为了解决这个问题,我最终将 git 存储库复制到一个新创建的项目中,但是在重新审视这个问题时,我发现这里有一个链接,它暗示了一些更优雅的东西(但功能相似)。
After creating a new project, use Import -> Filesystemand Select All. In my case, my repository already had a proper /src/com/...directory structure which merged nicely into the one set up by the new eclipse project.
创建新项目后,使用Import -> Filesystem和Select All。就我而言,我的存储库已经有一个正确的/src/com/...目录结构,它很好地合并到新 eclipse 项目设置的目录结构中。