Git with Eclipse (EGit) - Tutorial
Lars Vogel
Version 2.7
Copyright © 2009, 2010, 2011 Lars Vogel
09.11.2011
Revision History
Revision 0.1 11.12.2009 Lars Vogel
Created
Revision 0.2 - 2.7 12.12.2009 - 09.11.2011 Lars Vogel
bug fixes and enhancements
Git with Eclipse (EGit)
This tutorial describes the usage of EGit; an Eclipse plugin to use the distributed version control system Git. This tutorial is based on Eclipse 3.7 (Indigo).
Table of Contents
1. Overview
2. EGit Installation
3. Prerequisites for this tutorial
4. Putting projects under version control
4.1. Put a new project under version control
4.2. Clone existing project
4.3. Repository view
5. Using EGit
5.1. Basic operations
5.2. Merge
5.3. View the resource history
6. Create a Git repository for multiple projects
7. Using EGit with Github
7.1. Github
7.2. Create Repository in Github
7.3. Push project to Github
7.4. Clone repository from Github
7.5. Mylyn integration with Github
8. Hacking EGit - Getting the source code
9. Thank you
10. Questions and Discussion
11. Links and Literature
11.1. EGit and Git Resources
11.2. vogella Resources
1. Overview
Git is a distributed version control system written in C. JGit is a library which implements the Git functionality in Java. EGit is an Eclipse Team provider for Git (using JGit) and makes Git available in the Eclipse IDE.
This tutorial describes the usage of EGit. If you want to learn about the usage of the Git command line you can use the Git Tutorial as a reference.
2. EGit Installation
Eclipse 3.7 contains EGit in its default configuration. So typically you do not need to install anything.
If you use an older version of Eclipse you can use the Eclipse Update manager to install the EGit plugin from http://download.eclipse.org/egit/updates. The latest features can be found in the nightly build but this build is not as stable as the official update site target http://download.eclipse.org/egit/updates-nightly .
3. Prerequisites for this tutorial
This article assumes what you have basic understanding of development for the Eclipse platform. Please see Eclipse RCP Tutorial or Eclipse Plugin Tutorial .
4. Putting projects under version control
The following section explains how to create a repository for one project and shows how to checkout an exiting projects from a remote repository.
4.1. Put a new project under version control
Create a new Java project "de.vogella.git.first" in Eclipse. Create the following class.
package de.vogella.git.first;
public class GitTest {
public static void main(String[] args) {
System.out.println("Git is fun");
}
}
Right click your project, select Team -> Share Project -> Git. Select the proposed line and press "Create repository". Press finish.
You have created a local Git repository. The git repository is in this case directly stored in the project in a ".git" folder.
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 by git. In this example all files in the "bin" directory will be ignored.
bin
4.2. Clone existing project
EGit allows to clone an existing project. We will use an Eclipse plugin as example. To learn more about accessing standard Eclipse coding please see Eclipse Source Code Guide.
Select File -> Import -> Git -> Git Repository. Press clone and maintain the git repository "git://dev.eclipse.org/org.eclipse.jface/org.eclipse.jface.snippets.git". You only have to paste the URL to the first line of the dialog, the rest will be filled out automatically.
After pressing next the system will allow you to import the existing branches. You should select at least "master".
The next dialog allow you to specify where the project should be copied to and which branch should be initially selected.
You get an additional import dialog.
You have checked to the project and can use the team Git operation on your project.
4.3. Repository view
EGit has a "Git repository"" view which allow you to browse your repositories, checkout projects and manage your branches.
5. Using EGit
5.1. Basic operations
Once you have placed a project under version control you can start using team operations on your project. The team operations are available via right mouse click on your project. You can:
Select "Team" -> "Add", on the project node to add all files to version control.
Select "Team" -> "Commit", to commit your changes to the local Git repository.
Select "Team" -> "Branch" to create and to switch between branches.
Select "Team" -> "Push" to push your change to a remote Git repository (see the GitHub chapter).
"Team" -> "Tag" allows you to create and manage tags.
5.2. Merge
EGit supports currently fast-forward merge. Fast-forward merge allows to add the changes of one branch into another if this branch has not been changed. Select "Team" -> "Merge" to perform this operation.
5.3. View the resource history
Select a resource and select Show in (Alt+Shift+W) -> History to see the commit history of this resource.
6. Create a Git repository for multiple projects
To put several plugins into the same git repository you should create them in a subfolder under your workspace and then create via EGit a repository for this subfolder.
To test this create two new Java projects "de.vogella.egit.multi.java1" and "de.vogella.egit.multi.java2". Do not use the default location (which would be the workspace) but in a subfolder "gitmulti".
Create a few classes, as git is not able to save empty folders. Now select both projects, right click on them, select Team-> Share-> Git.
Done. Both projects are now in the same git repository.
7. Using EGit with Github
7.1. Github
Github is a popular hosting provider for Git projects and if you repository is public to everyone Github hosting is free. To use GitHub create an account on the Github Website. During the sign-up you will be asked to provide a "passphase". This "passphase" is later needed to push to Github from your local repository.
7.2. Create Repository in Github
Create a new repository on Github, e.g. "de.vogella.git.github".
After creation of your new repository Github tells you what to do if you would inport via the command line. As we are going to use EGit we can ignore this information.
7.3. Push project to Github
Create a new project "de.vogella.git.github" and put it under version control. Right-mouse click on your project and select "Team" -> "Push". A dialog pops up. Maintain the following data. Adjust the hightlighted line so that you are using your user and your project name.
git+ssh://git@github.com/vogella/de.vogella.git.github
Maintain your passphase which you maintained during the Github setup.
Select your branch (you should currently only have master if you followed my tutorial), press "Add all branches spec" and select next.
Press finish.
If you now select your github Dashboard and then your project you should see the commited files.
7.4. Clone repository from Github
Use the same URI you use to push to Github to clone the project into another workspace.
7.5. Mylyn integration with Github
Eclipse Mylyn is a productively tool for programmers. There is a GitHub connector for Mylyn available, please see http://wiki.eclipse.org/EGit/GitHub/UserGuide for details. .
8. Hacking EGit - Getting the source code
EGit is self-hosted on git://egit.eclipse.org. You can clone the EGit code from the repository using EGit using the following URL git://egit.eclipse.org/jgit.git and git://egit.eclipse.org/egit.git.
You also need some libraries from Orbit. See Libraries from Orbit for getting these libraries.
9. Thank you
Please help me to support this article:
Flattr this
10. Questions and Discussion
Before posting questions, please see the vogella FAQ. If you have questions or find an error in this article please use the www.vogella.de Google Group. I have created a short list how to create good questions which might also help you.
11. Links and Literature
11.1. EGit and Git Resources
http://www.vogella.de/articles/Eclipse/article.html EGit IDE Tutorial
http://wiki.eclipse.org/EGit/User_Guide EGit User Guide
http://wiki.eclipse.org/EGit/Contributor_Guide EGit contributor guide
Git Tutorial
11.2. vogella Resources
Eclipse RCP Training (German) Eclipse RCP Training with Lars Vogel
Android Tutorial Introduction to Android Programming
GWT Tutorial Program in Java and compile to JavaScript and HTML
Eclipse RCP Tutorial Create native applications in Java
JUnit Tutorial Test your application
Git Tutorial Put everything you have under distributed version control system
分享到:
相关推荐
Egit-1.3 是一个专门为 Eclipse 和 MyEclipse 开发的 Git 集成插件,用于在这些集成开发环境中实现对 Git 版本控制系统的支持。Git 是一种分布式版本控制系统,它允许开发者追踪代码的修改历史,协同工作,并进行...
eclipse-temurin官网下载的eclipse-temurin-alpine-jre-17
Git Learn Version Control with Git A step-by-step Ultimate beginners Guide 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
微信小程序学习用demo:git-book(源代码+截图)微信小程序学习用demo:git-book(源代码+截图)微信小程序学习用demo:git-book(源代码+截图)微信小程序学习用demo:git-book(源代码+截图)微信小程序学习用demo:git-...
A new version of Git for Windows' SDK [was released](https://github.com/git-for-windows/build-extra/releases/git-sdk-1.0.3] that works around pacman-key issues. We no longer show asterisks when ...
**基于Eclipse的Git插件——Egit** Egit是Eclipse IDE中的一个核心插件,专门用于集成Git版本控制系统,让开发者能够在熟悉的Eclipse环境中高效地管理代码仓库。Git是一种分布式版本控制系统,广泛应用于软件开发,...
Git-2.28.0-64-bit.exe Git-2.28.0-64-bit.exe Git-2.28.0-64-bit.exe
Git-2.42.0.2-64-bit.exe 是Git的最新64位Windows版安装程序,提供了在Windows操作系统上运行Git的功能。在这款安装包中,你可以找到Git的所有核心组件和工具,包括命令行界面、图形化界面(如Git Bash和Git GUI),...
Git-2.23.0-64-bit--Windows安装包是一个专门为Windows操作系统设计的64位Git版本,它包含了所有必要的组件,使得用户可以在Windows环境下无缝地使用Git。 Git的核心功能包括: 1. 版本追踪:Git能够记录文件和...
MyEclipse8.5的git插件egit-1.2 使用方法:下载后解压,将features、plugins文件夹和artifacts.jar、content.jar至于MyEclipse\dropins\egit\目录下,重启即可。
Git-2.41.0-64-bit window版本是针对Windows操作系统的一个特定构建,提供64位架构的支持。这个版本的发布,意味着用户可以在Windows环境下享受到Git的最新功能和性能优化。 Git的核心特性包括: 1. 分布式:每个...
shargs-tutorial-git 是入门教程 :shark: . 有关更多详细信息,请参阅! 代码 我们将在本教程中编写的代码可用作此存储库中的git脚本。 要运行它,首先要设置依赖项: $ git clone ...
Egit是Git在Eclipse平台上的一个集成插件,它使得开发者可以在熟悉的Eclipse环境中方便地使用Git版本控制系统。在Eclipse中集成Egit,可以极大地提升开发效率,实现代码的版本控制、协同开发和历史追踪等功能。针对...
Git-2.21.0-64-bit.zip是一个专为Windows 64位操作系统设计的Git官方客户端工具的压缩包文件。这个版本号(2.21.0)表明这是Git在某个时间点的一个稳定发行版,通常会包含性能优化、新功能和已知问题的修复。 Git的...
Git-2.28.0-64-bit.exe 是适用于Windows 64位操作系统的Git官方安装程序,该版本为2.28.0,意味着它包含了最新的功能和性能改进。 **Git基础概念** 1. **版本控制**:Git的核心功能是版本控制,它能跟踪文件和目录...
Git-2.18.0-64-bit是Git官方发布的一个针对64位Windows系统的更新版本,旨在提供更稳定、高效和功能丰富的代码管理体验。 1. Git的基本概念: - 版本控制:Git的核心功能是版本控制,它记录了代码的每一次修改,...
"Learn Version Control with Git" is a beginner-friendly step-by-step course. The book doesn't require a deep technical background. Instead, it's aimed at beginners of version control and/or ...
官网目前已经没有下载链接。上述安装:下载的插件解压。在MyEclipse8.5的dropins目录下新建一个egit文件夹,然后把刚才解压的features、plugins和另外两个jar包放进去。重启MyEclipse即可
* tree 对象格式:https://git-scm.com/docs/git-tree * 查看 tree 对象:`git cat-file -p 对象>` ### Git cat-file 命令 * 查看 object 类型:`git cat-file -t <object>` * 查看 object 大小:`git cat-file -s...
标题 "201406egit-eclipse插件" 提到的是Eclipse集成的Git工具EGit的安装包,这是Eclipse IDE中用于版本控制的重要组件,它使得开发人员能够在Eclipse环境中直接管理和协作Git仓库。EGit是Eclipse项目的一部分,提供...