如何将现有的Eclipse Java项目添加到git [英] How do I add existing eclipse java project to 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):
- 打开您的终端机
- 导航到项目目录
- 键入
git init
创建存储库 - 假设您已经在该文件夹中拥有文件,则键入
git add --all
将所有文件添加到存储库(注意:如果跳过此步骤,将有一个空的存储库。也可以使用git add文件名
仅添加特定文件/文件夹) - 键入
git commit -m您的消息在这里
执行第一次提交
- 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
此时,您已经有了一个包含文件的全新 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.
- 创建远程存储库(以GitHub为例,只需单击
新建
按钮,然后按照提示进行操作。 - 打开终端并导航到项目目录
- 在您存储库的页面上,您应该看到一个HTTPS链接,该链接以
your-repository-name.git
结尾 - 粘贴
git remote add origin
到您的终端,然后是该HTTPS链接 - 粘贴
git push -u origin master
到您的终端中(注意:这最后两个步骤也显示在GitHub新项目页面上,以便于轻松地复制和粘贴到您的终端中)
- 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)
现在您已经将本地存储库连接到远程存储库,可以使用了!所有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屋!