简体   繁体   English

如何将现有的eclipse java项目添加到git

[英]How do I add existing eclipse java project to git

How do I add an existing java project in eclipse to git? 如何在eclipse中添加现有的java项目到git?

I noticed when creating the project there was an option to add to source control but I can't find this option for an existing project. 我注意到在创建项目时有一个添加到源代码管理的选项,但我找不到现有项目的这个选项。 Is this possible from the git plugin in eclipse or must it be done from the command line? 这可能来自eclipse中的git插件还是必须从命令行完成? (I am using a Mac) (我使用的是Mac)

Follow these steps 跟着这些步骤

  1. Right click on the project 右键单击该项目
  2. Select Team -> Share 选择Team - > Share
  3. You will be prompted to select the tool you prefer 系统将提示您选择所需的工具
  4. Click Create -> Browse if you already have one 如果已有,请单击“ Create - >“ Browse
  5. Select git and go on 选择git然后继续

An alternative route (I have found the built-in Eclipse tool to be finicky at times): 另一种方法(我发现内置的Eclipse工具有时很挑剔):

  1. Open up your terminal 打开你的终端
  2. Navigate to your project directory 导航到您的项目目录
  3. Type git init to create a repository 输入git init以创建存储库
  4. Assuming you already have files in that folder, type git add --all to add all your files to the repository (Note: if you skip this step, you will have an empty repository. You can also use git add filename to add only specific files/folders) 假设您已经在该文件夹中有文件,请键入git add --all将所有文件添加到存储库(注意:如果跳过此步骤,您将拥有一个空存储库。您还可以使用git add filename仅添加特定git add filename文件/文件夹)
  5. Type git commit -m "your message here" to perform your first commit 键入git commit -m "your message here"以执行您的第一次提交

At this point, you have a brand new local repository containing your files! 此时,您有一个包含文件的全新本地存储库! The following steps will hook it up to a remote repository. 以下步骤将它连接到远程存储库。

  1. Create your remote repository (using GitHub as an example, simply click the New button, and follow the prompts. 创建远程存储库(以GitHub为例,只需单击“ New按钮,然后按照提示操作即可。
  2. Open up your terminal and navigate to your project directory 打开终端并导航到项目目录
  3. On the page for your repository, you should see an HTTPS link ending in your-repository-name.git 在存储库的页面上,您应该看到以your-repository-name.git结尾的HTTPS链接
  4. Paste git remote add origin into your terminal, followed by that HTTPS link git remote add origin到终端,然后是HTTPS链接
  5. Paste git push -u origin master into your terminal (Note: these last two steps are shown on the GitHub new project page as well, for easy copy-and-pasting into your terminal) git push -u origin master粘贴到终端中(注意:最后两个步骤也显示在GitHub新项目页面上,以便于复制和粘贴到终端中)

Now you have a local repository connected to a remote repository, ready to use! 现在您有一个连接到远程存储库的本地存储库,随时可以使用! All Eclipse projects exist somewhere in your file system, and can easily be accessed just like any other folder you might want to turn into a repository. 所有Eclipse项目都存在于文件系统中的某个位置,并且可以像您可能想要转换为存储库的任何其他文件夹一样轻松访问。

I do realize you asked to avoid the command line, but this is a relatively simple command line task, and learning to be somewhat familiar with how to use your command line can pay big dividends later on. 我确实意识到你要求避免使用命令行,但这是一个相对简单的命令行任务,学习如何熟悉如何使用命令行可以在以后支付大笔红利。

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

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