如何将现有的 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
How do I add existing eclipse java project to git
提问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 工具有时很挑剔):
- Open up your terminal
- Navigate to your project directory
- Type
git init
to create a repository - 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 usegit add filename
to add only specific files/folders) - Type
git commit -m "your message here"
to perform your first commit
- 打开你的终端
- 导航到您的项目目录
- 键入
git init
以创建存储库 - 假设您在该文件夹中已经有文件,请键入
git add --all
以将所有文件添加到存储库中(注意:如果跳过此步骤,您将拥有一个空存储库。您也可以使用git add filename
仅添加特定文件/文件夹) - 键入
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.
此时,您有一个全新的本地存储库,其中包含您的文件!以下步骤将其连接到远程存储库。
- Create your remote repository (using GitHub as an example, simply click the
New
button, and follow the prompts. - Open up your terminal and navigate to your project directory
- On the page for your repository, you should see an HTTPS link ending in
your-repository-name.git
- Paste
git remote add origin
into your terminal, followed by that HTTPS link - 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)
- 创建您的远程存储库(以 GitHub 为例,只需单击
New
按钮,然后按照提示操作即可。 - 打开你的终端并导航到你的项目目录
- 在您的存储库页面上,您应该会看到一个以
your-repository-name.git
- 粘贴
git remote add origin
到您的终端,然后是该 HTTPS 链接 - 粘贴
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
按着这些次序
- Right click on the project
- Select
Team
->Share
- You will be prompted to select the tool you prefer
- Click
Create
->Browse
if you already have one - Select git and go on
- 右键单击项目
- 选择
Team
->Share
- 系统将提示您选择您喜欢的工具
- 点击
Create
->Browse
如果你已经有了 - 选择 git 并继续