如何将现有的Eclipse Java项目添加到git [英] How do I add existing eclipse java project to git

查看:459
本文介绍了如何将现有的Eclipse Java项目添加到git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在eclipse中将现有的Java项目添加到git中?

How do I add an existing java project in eclipse to git?

创建项目时,我注意到可以添加到源代码管理中,但是我可以无法为现有项目找到此选项。这是可以从Eclipse中的git插件实现的,还是必须从命令行完成? (我使用的是Mac)

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? (I am using a Mac)

推荐答案

另一种方法(我发现内置Eclipse工具有时会很挑剔):

An alternative route (I have found the built-in Eclipse tool to be finicky at times):


  1. 打开您的终端机

  2. 导航到项目目录

  3. 键入 git init 创建存储库

  4. 假设您已经在该文件夹中拥有文件,则键入 git add --all 将所有文件添加到存储库(注意:如果跳过此步骤,将有一个空的存储库。也可以使用 git add文件名仅添加特定文件/文件夹)

  5. 键入 git commit -m您的消息在这里 执行第一次提交

  1. Open up your terminal
  2. Navigate to your project directory
  3. Type git init to create a repository
  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)
  5. Type git commit -m "your message here" to perform your first commit

此时,您已经有了一个包含文件的全新 local 存储库!以下步骤将其连接到远程存储库。

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. 创建远程存储库(以GitHub为例,只需单击新建按钮,然后按照提示进行操作。

  2. 打开终端并导航到项目目录

  3. 在您存储库的页面上,您应该看到一个HTTPS链接,该链接以 your-repository-name.git
  4. 结尾
  5. 粘贴 git remote add origin 到您的终端,然后是该HTTPS链接

  6. 粘贴 git push -u origin master 到您的终端中(注意:这最后两个步骤也显示在GitHub新项目页面上,以便于轻松地复制和粘贴到您的终端中)

  1. Create your remote repository (using GitHub as an example, simply click the New button, and follow the prompts.
  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
  4. Paste git remote add origin into your terminal, followed by that HTTPS link
  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)

现在您已经将本地存储库连接到远程存储库,可以使用了!所有Eclipse项目都位于文件系统中的某个位置,并且可以像访问其他任何文件夹一样轻松地进行访问变成存储库。

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.

我确实意识到您被要求避免使用命令行,但这是一个相对简单的命令行任务,以后学会对如何使用命令行有所了解可以带来很多好处。

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.

这篇关于如何将现有的Eclipse Java项目添加到git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆