简体   繁体   English

在现有Git存储库的版本控制下很难创建一个全新的Eclipse项目吗?

[英]Difficulty creating a brand new Eclipse project under version control of existing Git repositories?

I am new to Git and having difficulty understanding how (best) to create an Eclipse (Luna) project under Git version control when the repository already exists. 我是Git的新手,很难理解,当存储库已经存在时,如何(最好)在Git版本控制下创建Eclipse(Luna)项目。

My intuitive thought is that I should: 我的直觉认为我应该:

1.1) Create an empty remote (origin) repository, for example on GitHub. 1.1)例如在GitHub上创建一个空的远程(原始)存储库。

1.2) Clone the remote repository to my local drive. 1.2)将远程存储库克隆到我的本地驱动器。

1.3) Make Eclipse aware of the connection to my Git repository. 1.3)使Eclipse知道到我的Git存储库的连接。

1.4) Create an Eclipse project within the local repository working directory. 1.4)在本地存储库工作目录中创建一个Eclipse项目。

1.5) Add and commit the project files to the local repository. 1.5)将项目文件添加并提交到本地存储库。

1.6) Push the commit out to the remote (origin) repository. 1.6)将提交推送到远程(原始)存储库。

I think I have a reasonable understanding of how Eclipse interacts with Git after the project already exists, and is already under version control. 我想我对项目已经存在并且已经在版本控制下之后Eclipse如何与Git交互有一个合理的了解。 But I am starting from the ground up and am having a great deal of confusion getting to that state. 但是我是从头开始的,对于进入该状态有很多困惑。

Steps 1.3 & 1.4 are what I can find no documentation for; 我找不到步骤1.3和1.4的文档; and have not been able to hack my way through. 而且还无法破解我的方法。 I imported a local Git repository into Eclipse using the wizard. 我使用向导将本地Git存储库导入了Eclipse。 I can then create an Eclipse project in that directory. 然后,我可以在该目录中创建一个Eclipse项目。 But for some reason I am not able to close, or later (eg after restarting Eclipse) open the project. 但是由于某种原因,我无法关闭,或者稍后(例如,重新启动Eclipse之后)打开项目。 The "Open Project" and "Close Project" options are greyed out on the menu. 菜单上的“打开项目”和“关闭项目”选项为灰色。 The project does not appear in the list of projects for that Eclipse workspace. 该项目没有出现在该Eclipse工作区的项目列表中。 I see the external project files that Eclipse has generated. 我看到了Eclipse生成的外部项目文件。 From within Eclipse, when I try to open the project file, I'm told it is not a project. 在Eclipse中,当我尝试打开项目文件时,被告知它不是项目。 If I try again to create the same project, I'm told that it already exists. 如果我再次尝试创建相同的项目,则会被告知该项目已经存在。 So I have a project in the git repository, but can't work with it. 所以我在git仓库中有一个项目,但是不能使用它。 Eclipse doesn't recognize it's a project (for opening) while simultaneously acknowledging that it already exists (preventing redundant creation). Eclipse在承认它已经存在(防止重复创建)的同时,没有意识到它是一个项目(用于打开)。 I'm obviously doing this incorrectly. 我显然做错了。 But have not been successful after many attempts to make this work. 但是经过多次尝试使这项工作没有成功。

I could follow an alternate order explained at http://wiki.eclipse.org/EGit/User_Guide : 我可以按照http://wiki.eclipse.org/EGit/User_Guide上说明的另一命令进行操作:

2.1) Create an Eclipse project completely independent from Git. 2.1)创建一个完全独立于Git的Eclipse项目。

2.2) Create a local Git repository around the Eclipse file. 2.2)在Eclipse文件周围创建一个本地Git存储库。

2.3) Create the remote (origin) repository from the local repository. 2.3)从本地存储库创建远程(原始)存储库。

However, I don't feel comfortable with this approach: 但是,我对这种方法不满意:

a) If I create things in this order, won't the remote Git repository see the local repository as origin (ie it's parent)? a)如果我按此顺序创建事物,那么远程Git存储库不会将本地存储库视为来源(即它的父级)吗?

b) I still haven't learned how to create an Eclipse file, from scratch, under version control of a preexisting repository. b)我仍然还没有学习如何在现有存储库的版本控制下从头开始创建Eclipse文件。 I have only learned to create a brand new repository from an existing Eclipse Project. 我只学习了从现有的Eclipse Project创建一个全新的存储库。

c) There is discussion in the EGit/User Guide ( http://wiki.eclipse.org/EGit/User_Guide ) about "Creating a Git Repository for multiple Projects". c)EGit /用户指南( http://wiki.eclipse.org/EGit/User_Guide )中有关于“为多个项目创建Git存储库”的讨论。 This illustrates how to create a brand new repository from several preexisting Eclipse projects. 这说明了如何从几个预先存在的Eclipse项目创建一个全新的存储库。 But it does not explain how to later create a brand new project into the existing repository containing multiple Eclipse projects. 但是,它没有说明如何稍后在包含多个Eclipse项目的现有存储库中创建一个全新项目。

How do I create a brand new Eclipse project, under version control of a preexisting repository? 如何在预先存在的存储库的版本控制下创建一个全新的Eclipse项目?

I think I've figured out the best way to do this: 我想我已经找到了执行此操作的最佳方法:

1) Create a new remote repository. 1)创建一个新的远程存储库。 Use GitHub or 使用GitHub或

git init --bare git init-裸

2) Clone the remote repository to local disk. 2)将远程存储库克隆到本地磁盘。

cd pathForTheLocalRepository cd pathForTheLocalRepository

git clone remoteRepositoryPath Project1 git clone remoteRepositoryPath Project1

3) Within Eclipse, File->New->Java Project 3)在Eclipse中,选择File-> New-> Java Project

3a) In the Create Java Project window, enter project name, uncheck "Use Default Location", and for "Location:" enter or browse to the local repository on disk. 3a)在“创建Java项目”窗口中,输入项目名称,取消选中“使用默认位置”,对于“位置:”,输入或浏览到磁盘上的本地存储库。 新建Java项目窗口

4) Eclipse automatically recognizes that it is within a git repository. 4)Eclipse自动识别它在git存储库中。

5) Right click on the project in the Project Explorer window. 5)在“项目资源管理器”窗口中右键单击该项目。

6) Team->Add To Index 6)团队->添加到索引

7) Team->Commit 7)团队->提交

8) Team->Push to Upstream 8)团队->推送到上游

9) The push creates a master branch when we were working with an empty remote repository. 9)当我们使用空的远程存储库时,推送会创建一个master分支。

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

相关问题 全新的Eclipse插件项目充满了错误 - Brand new Eclipse plugin project riddled with errors 我可以将SalesforceDX用作现有Eclipse项目的版本控制吗? - Can I use SalesforceDX as a version control for an existing Eclipse project? 在Eclipse中现有的Git存储库中启动一个新的Java项目 - Start a new Java project inside an existing Git repository in Eclipse 将现有项目导入eclipse,它将旧版本与新版本自动结合 - Import existing project into eclipse, it auto combine old version with the new one 如何将eclipse项目添加到现有的git仓库? - How to add eclipse project to existing git repo? 如何在Eclipse中更改现有Android项目的版本? - How to Change Version of Existing Android Project in Eclipse? 使用现有 Java 文件在 Eclipse 上创建新项目 - Create new project on Eclipse with existing Java files 创建新项目时,Eclipse中未显示Spring MVC选项(版本-Kepler 4.3)? - Spring MVC option not showing in Eclipse While Creating New Project (version - Kepler 4.3)? Eclipse 2019-09 - 在创建新项目时出现错误:“无法确定 Java 版本” - Eclipse 2019-09 - Getting the error: “Could not determine Java version”, while creating a new project 创建新的Android项目时Eclipse崩溃 - Eclipse crashes when creating a new android project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM