如何使用 EGit 将当前的 Eclipse 项目添加到 git?

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

How can I add current Eclipse project to git with EGit?

eclipsegitegit

提问by newbie

I have GAE project in my Eclipse and I want to add it to my local git repo, how can I do that?

我的 Eclipse 中有 GAE 项目,我想将它添加到我的本地 git 存储库中,我该怎么做?

回答by VonC

Since creating a Git repo within a GAE projectis possible through command line, it is possible through Egit:
Follow that Egit tutorial:

由于可以通过命令行在GAE 项目中创建Git 存储库,因此可以通过 Egit:
按照该Egit 教程

For a new repo:

对于新的回购:

Right click your project, select Team -> Share -> Git.
Select the proposed line and press "Create repository". Press finish

右键单击您的项目,选择 Team -> Share -> Git。
选择建议的行,然后按“创建存储库”。按完成

egit repo creation dialog

egit repo 创建对话框

Create the file ".gitignore" in your project with the following content.
All files / directories which apply to the pattern described in this file will be ignored

.gitignore使用以下内容在您的项目中创建文件“ ”。
适用于此文件中描述的模式的所有文件/目录都将被忽略

But you can also add it to an existing local repo by:

但是您也可以通过以下方式将其添加到现有的本地存储库中:

  • making a special branch for your project in your local repo (with just the .gitignorefile in it)
  • clone it where your current project is
  • add all your current project files in it
  • import said Git repo into your workspace: See 4.2 Clone existing project.
  • 在本地存储库中为您的项目创建一个特殊分支(仅包含.gitignore文件)
  • 将它克隆到您当前项目所在的位置
  • 在其中添加您当前的所有项目文件
  • 将上述 Git 存储库导入您的工作区:请参阅4.2 克隆现有项目


informatik01adds in the comment a link to a short article describing how to do it using the command line:
Adding Eclipse Project to Git

informatik01在评论中添加了一个链接,指向一篇描述如何使用命令行执行此操作的简短文章:
将 Eclipse 项目添加到 Git

cd ~/workspace/my-project
git init .