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

时间:2023-01-13 12:07:57

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

如何在eclipse中向git添加现有的java项目?

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中的git插件,还是必须从命令行完成?(我在用Mac电脑)

2 个解决方案

#1


18  

Follow these steps

遵循以下步骤

  1. Right click on the project
  2. 右键单击项目
  3. Select Team -> Share
  4. 选择团队- >共享
  5. You will be prompted to select the tool you prefer
  6. 您将被提示选择您喜欢的工具
  7. Click Create -> Browseif you already have one
  8. 单击Create -> Browseif您已经有一个。
  9. Select git and go on
  10. 选择git并继续

#2


2  

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

另一种路径(我发现内置的Eclipse工具有时很挑剔):

  1. Open up your terminal
  2. 打开终端
  3. Navigate to your project directory
  4. 导航到项目目录
  5. Type git init to create a repository
  6. 输入git init以创建一个存储库
  7. 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)
  8. 假设您已经在该文件夹中有了文件,那么输入git add——所有这些都用于将所有文件添加到存储库中(注意:如果跳过这一步,您将得到一个空的存储库。您还可以使用git添加文件名只添加特定的文件/文件夹)
  9. Type git commit -m "your message here" to perform your first commit
  10. 输入git commit -m“您在这里的消息”来执行您的第一次提交

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.
  2. 创建您的远程存储库(以GitHub为例,只需单击New按钮,并遵循提示。
  3. Open up your terminal and navigate to your project directory
  4. 打开终端并导航到项目目录
  5. On the page for your repository, you should see an HTTPS link ending in your-repository-name.git
  6. 在存储库的页面上,您应该看到一个以您的-repository-name.git结尾的HTTPS链接
  7. Paste git remote add origin into your terminal, followed by that HTTPS link
  8. 将git remote add origin粘贴到终端,后面跟着HTTPS链接
  9. 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)
  10. 将git push -u源程序粘贴到您的终端(注意:在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.

我确实意识到您要求避免命令行,但是这是一个相对简单的命令行任务,并且学习熟悉如何使用命令行可以在以后支付很大的股息。

#1


18  

Follow these steps

遵循以下步骤

  1. Right click on the project
  2. 右键单击项目
  3. Select Team -> Share
  4. 选择团队- >共享
  5. You will be prompted to select the tool you prefer
  6. 您将被提示选择您喜欢的工具
  7. Click Create -> Browseif you already have one
  8. 单击Create -> Browseif您已经有一个。
  9. Select git and go on
  10. 选择git并继续

#2


2  

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

另一种路径(我发现内置的Eclipse工具有时很挑剔):

  1. Open up your terminal
  2. 打开终端
  3. Navigate to your project directory
  4. 导航到项目目录
  5. Type git init to create a repository
  6. 输入git init以创建一个存储库
  7. 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)
  8. 假设您已经在该文件夹中有了文件,那么输入git add——所有这些都用于将所有文件添加到存储库中(注意:如果跳过这一步,您将得到一个空的存储库。您还可以使用git添加文件名只添加特定的文件/文件夹)
  9. Type git commit -m "your message here" to perform your first commit
  10. 输入git commit -m“您在这里的消息”来执行您的第一次提交

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.
  2. 创建您的远程存储库(以GitHub为例,只需单击New按钮,并遵循提示。
  3. Open up your terminal and navigate to your project directory
  4. 打开终端并导航到项目目录
  5. On the page for your repository, you should see an HTTPS link ending in your-repository-name.git
  6. 在存储库的页面上,您应该看到一个以您的-repository-name.git结尾的HTTPS链接
  7. Paste git remote add origin into your terminal, followed by that HTTPS link
  8. 将git remote add origin粘贴到终端,后面跟着HTTPS链接
  9. 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)
  10. 将git push -u源程序粘贴到您的终端(注意:在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.

我确实意识到您要求避免命令行,但是这是一个相对简单的命令行任务,并且学习熟悉如何使用命令行可以在以后支付很大的股息。