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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25515393/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:33:22  来源:igfitidea点击:

How do I add existing eclipse java project to git

javaeclipsegit

提问by dmeehan

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

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

采纳答案by Abigail Fox

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 initto create a repository
  4. Assuming you already have files in that folder, type git add --allto 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 filenameto add only specific files/folders)
  5. Type git commit -m "your message here"to perform your first commit
  1. 打开你的终端
  2. 导航到您的项目目录
  3. 键入git init以创建存储库
  4. 假设您在该文件夹中已经有文件,请键入git add --all以将所有文件添加到存储库中(注意:如果跳过此步骤,您将拥有一个空存储库。您也可以使用git add filename仅添加特定文件/文件夹)
  5. 键入git commit -m "your message here"以执行您的第一次提交

At this point, you have a brand new localrepository 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 Newbutton, 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 origininto your terminal, followed by that HTTPS link
  5. Paste git push -u origin masterinto 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)
  1. 创建您的远程存储库(以 GitHub 为例,只需单击New按钮,然后按照提示操作即可。
  2. 打开你的终端并导航到你的项目目录
  3. 在您的存储库页面上,您应该会看到一个以 your-repository-name.git
  4. 粘贴git remote add origin到您的终端,然后是该 HTTPS 链接
  5. 粘贴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.

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

回答by vratojr

Follow these steps

按着这些次序

  1. Right click on the project
  2. Select Team-> Share
  3. You will be prompted to select the tool you prefer
  4. Click Create-> Browseif you already have one
  5. Select git and go on
  1. 右键单击项目
  2. 选择Team->Share
  3. 系统将提示您选择您喜欢的工具
  4. 点击Create->Browse如果你已经有了
  5. 选择 git 并继续