Home Tutorials Training Consulting Books Company Contact us


Get more...

This tutorial describes the usage of the Eclipse IDE to perform Git operations.

1. Git support for Eclipse

Via the Eclipse IDE you can perform Git commands like staging, commit, merge, rebase, pull and push.

2. Installation of Git support into Eclipse

Most Eclipse IDE distributions from Eclipse.org already contain support for Git. In this case no additional installation is required.

If the Git tooling is not available, you can install it via the Eclipse installation manager. Select the Help  Install new Software…​ menu entry. Enter one of the following update site URLs:

# Use this update site to get the latest release
https://download.eclipse.org/egit/updates

# use this update site to get the night build
https://download.eclipse.org/egit/updates-nightly/

The dialog to install the Git Integration for Eclipse is depicted in the following screenshot.

Installing EGit

3. Configuration for Git usage via the Eclipse IDE

Interoperability of Git command line settings with the Eclipse IDE

If you have already configured Git for the command line, no additional setup is required in the Eclipse IDE and you can skip this exercise. The Eclipse IDE uses the same configuration files as the Git command line tools. This makes it easier to use the Eclipse Git tooling and the command line tooling for Git interchangeably.

3.1. Configure user and email

In your Eclipse IDE, select the Window  Preferences  Version Control (Team)  Git  Configuration entry. Configure your full name and email in the user settings. As the Eclipse IDE uses the same settings as the Git command line, this might already be done.

For the user the user.name key is used, for the email the user.email key is used.

Configuration of EGit

If these keys are not available press the Add Entry…​ button and add them.

egitconfig09

Repeat the procedure for your email address via the user.email key.

Configuration of EGit

3.2. Configure Git to rebase during pull operations

To use rebase during the pull operation set the pull.rebase parameter to true. It avoids merge commits if you pull from a remote repository and have divergent changes and instead rebases your local branch on the remote branch it tracks.

This is the recommended setting by the author of this text.

3.3. Validate the setup

After this setup, the configuration should look similar to the following screenshot.

Configuration of EGit user and email defaults

3.4. Configuring the proxy settings

If you are using a proxy server, you can configure it via Windows  Preferences  General  Network Connection.

4. Exercise: Creating and using a Git repository with the Eclipse IDE

The following exercise explains how to use the Eclipse IDE to perform Git operations. To ensure that you have a Git repository, you first create a new local Git repository via the Eclipse IDE.

The Eclipse workspace and Git repositories

It is good practice to place your Git repositories outside the Eclipse workspace. This separates your Git repository from any additional meta-data which Eclipse might create. By default, Eclipse Git uses the git folder in the user’s home directory to clone new repositories.

4.1. Create a new Git repository via Eclipse

Use Ctrl+3 (or Cmd+3) and type Create a new Git repository in the dialog.

This opens a dialog which allows you to specify the directory for the new Git repository. Select a new directory outside of your workspace. By convention, this directory is a subdirectory in the git folder of the user’s home directory.

Git init with Eclipse Git

Press the Create button. Now the Git repository is created and a reference to it is added to the Git Repositories view which you use later.

4.2. Create .gitignore file

We want to ignore certain file types in our Git repository. We want Git to ignore the bin folder and *.class files.

Create a .gitignore file in the top-level folder of your Git repository. This means, the file should be placed at the same level as the .git directory.

Eclipse Git does not allow you to create a file directly in the top-level folder of your repository. You have to do this step outside of the Eclipse IDE, either via the command line or via your system project explorer.

It should contain the following content.

bin
*.class

Recent versions of MS Windows decided to prevent you from renaming a file in the file explorer without using a file extension. Create a file in Notepad or Editor (new name for Notepad) and select Save-As. Ensure you have removed the .txt extension.

4.3. Create a new Java project

Projects in Eclipse are folders which can have a special configuration, e.g. they can be configured to support Java development. Use Ctrl+3 (or Cmd+3) and type Create a Java project to open the wizard to create a Java project.

Enter com.vogella.git.first as name and leave the rest of the values to their default value.

create java project git20

Accept the default values for a module-info.java file and press Create .

create java project git30

If you are using Java 8 or lower, you will not be asked to create a module-info.java.

4.4. Optional: Create some Java content

Skip this part of the exercise in case you are not familiar with Java and go directly to the next part.

Use Ctrl+3 (or Cmd+3) and type Create a Java class to open the wizard to create a Java class. Enter:

  • com.vogella.git.first as package

  • GitTest as Name

Leave the rest of the values to their default value. Press the Finish button, this creates the class and opens the editor.

create java project git40
create java project git50

Now change the code of the class to the following.

package com.vogella.git.first;

public class GitTest {
  public static void main(String[] args) {
    System.out.println("Git is fun");
  }
}

4.5. Put project under Git version control

To put your new project under version control with Git, right-click on your project, select Team  Share Project. If another version control system is installed you have to select that you want to use Git as the version control system.

Select your existing Git repository from the drop-down list.

Git repository creation wizard - Step 1

Press the Finish button.

Your project location has now moved into the folder of the Git repository.

4.6. Open the Git repository view

Use Ctrl+3 (or Cmd+3) and type Git Repositories in the dialog to open the Git repositories view. This view shows you the Git repositories you can work with in Eclipse and allows you to add existing repositories to Eclipse, create or clone repositories. It also allows you to perform Git operations.

git repository view exercise10

4.7. Using the Git Staging view for the initial commit

Use Ctrl+3 (or Cmd+3) and type Git Staging to open the Git staging view.

In this view use the ++ button to stage all files. Write a meaningful commit message and press the Commit button.

Initial commit

4.8. Create a new file

Create a new file named Readme.adoc via right mouse click on your project and New  File from the context menu. Do not commit it yet.

4.9. Change a file and commit the change

If you did not do the optional Java part, skip this part of the exercise also.

Otherwise, change the System.out.println message in your GitTest class.

package com.vogella.git.first;

public class GitTest {
  public static void main(String[] args) {
    System.out.println("Git is cool");
  }
}

Commit the changes of the GitTest class, but do not add and commit the Readme.adoc file to the Git repository.

In the Git Staging view drag only the GitTest class into the Staged Changes area, write a meaningful commit message and press the commit button.

Git Staging View - Add to staging area

This change is now also stored in your local Git repository. The Readme.adoc file is neither staged nor committed to the Git repository.

4.10. Commit more files

Stage and commit the Readme.adoc file. By now you should know how to do this.

4.11. Configure the History view

Use Ctrl+3 (or Cmd+3) and type History, ensure that the entry belongs to the Views category to open the History view.

In the History view click all toggle buttons as shown in the screenshot

  • Link with Editor and Selection

  • Show all changes in repository containing the selected resources

  • Show all Branches and Tags

History View

Afterwards, use the History view to review which files were included in your individual commits.

4.12. Open an older version with the current version of a file via the History view

We want to see the version of the GitTest.java file as it was in the first commit. Select the first commit in the history view. You see the changed files of a commit in the right bottom part of the commit details. Select your file in the commit details of the History view and select Open this version via the context menu.

History View

4.13. Accidently add an unwanted file an remove it

Create a new file named test.unwanted via right mouse click on your project and New  File from the context menu. Stage and commit the new file.

Now add *.unwanted to your .gitignore file. Make a change to your test.unwanted file

Git shows it as a change in .gitignore only apply to new files You need to untrack the file.

Select the file and select Team  Advanced  Untrack.

Stage and commit the change.

4.14. Add more projects to your Git repository

You can of course have multiple projects in a Git repository. To validate that, create two more Java projects called com.vogella.egit.multi.java1 and com.vogella.egit.multi.java2. Create at least one Java class in each project.

Afterwards select the new projects, right-click on them and select Team  Share Project…​  Git.

Select your Git repository in the following dialog and add both projects to this repository. Press the Finish button.

4.15. Validate the project move and commit changes

Afterwards validate that the projects have been moved. You can check your workspace directory and your Git repository directory via a file explorer. You see that the projects have been moved from their original location to the Git repository.

The changes have not yet been committed. Now commit all files in the two projects to your Git repository.

5. Exercise: Clone an existing repository

In this exercise you will clone a Git repository and import the existing projects from this repository into your workspace.

For this, select File  Import…​|Git|Projects from Git.

Importing projects via EGit

Select Clone URI in the next dialog.

URI selected in EGit

Enter the URL to your Git repository which you want to clone. You can use the following example URI.

git://github.com/vogella/eclipse4book.git

URI entered in the dialog

The above link uses the git protocol, alternatively you can also use the http protocol: http://github.com/vogella/eclipse4book.git

Git supports several protocols, e.g. git://, ssh:// and https://. You can paste the clone URL to the first line of the dialog, the rest of the dialog is filled based on this data.

Some proxy servers block the git:// and ssh:// prThe above link uses the git protocol, alternatively you can also use the http protocol: http://github.com/vogella/eclipse4book.gitotocols. If you face issues, please try to use the https:// or http:// protocol.

After pressing the Next button the system will allow you to import the existing branches. Select at least the master branch.

URI entered in the dialog

The next dialog allows you to specify where the repository should be copied to and which local branch should be created initially.

Define target directory for Git repository

After the Git repository is cloned, you can import existing projects.

Importing projects

Once this dialog is completed, you have clone the remote repository into a local Git repository. You can use Git operation on these projects.

The project may not compile, as you may miss pre-requisites. For this exercises, this can be ignored, the purpose of it was to learn how to clone a repository.

6. Exercise: Import projects from an existing repository

If you have already an existing Git repository you can add it to the Git Repostory view. Afterwards you can import the projects into your workspace via the File  Import  Git  Project from Git menu entry.

Importing projects via EGit

Select Local if you want to important from a local repository or Clone URL if you first want to clone the repository.

Importing projects via EGit part 2

The following screenshot shows multiple local repositories. To import the project contained in one of them, select one entries and press the Next button. To add a new local repository to this dialog (and the Git repositories view) use the Add…​ button.

Importing projects via EGit part 2

The wizard allows you to specify the projects to import. After the import the Eclipse IDE is aware that these projects are part of a Git repository.

7. Exercise: Using interactive rebase in Eclipse

Git allows to adjust the local commit history via the interactive rebase functionality. Eclipse provides support for simplified versions of this as well as support for full interactive rebase operations. This includes changing the order of commits or combining, removing and adjusting commits.

7.1. Simple interactive rebase operations available via the History view

To reword a commit, right-click on it in the History view and select Modify  Reword to change the commit message.

Reword a commit message in Eclipse

You can squash several commits by selecting them in the History view. Select afterwards the Modify  Squash menu entry from the context menu.

Squash a commit

The above options are simplified ways to do an interactive rebase.

7.2. Performing a full interactive rebase via Eclipse

To start the full interactive rebase open the History view and click Rebase Interactive on the context menu. Select the last commit preceding the oldest commit you want to rewrite. Often this is the one origin/master points to.

Interactive Rebase EGit

This opens the Git Interactive Rebase view. The Git Interactive Rebase view allow you perform the full interactive rebase functionality.

It shows the rebase plan populated with the commits to be modified. They are sorted in topological order of the sequence in which they will be processed. This order is the reverse order which you see via the git log command or in the History view. The initial action for all commits is "Pick".

Interactive Rebase EGit

The following actions are available.

Table 1. Interactive rebase actions
Action Description

pick

includes the selected commit, moving pick entries enables reordering of commits

skip

removes a commit

edit

amends the commit

squash

combines the changes of the commit with the previous commit and combines their commit messages

fixup

squashes the changes of a commit into the previous commit discarding the squashed commit’s message

reword

similar to pick but allows modifying the commit message

Use this view to finalize the rebase plan. For example, you can reorder commits with the arrow buttons and select the rebase action you want to apply to the commit. The following screenshot demonstrates a possible selection.

Interactive Rebase EGit

When the rebase plan is finalized, click the Start button to start the interactive rebase command. Eclipse Git processes the plan. It stops at all commits with an action which needs user feedback. For example, the reword action which requires entering the new commit message. The dialog for changing the commit message is depicted in the following screenshot.

Interactive Rebase EGit

Here is the result of the rebase operation displayed in the History view.

Interactive Rebase EGit

If something goes wrong during the rebase operation, you can select Abort in order to stop the rebase operation and roll back to the starting point.

8. Eclipse Git configuration

The Eclipse IDE uses the default Git settings, e.g. done via the command line tooling. You can also use the Eclipse IDE to configure these options.

8.1. Git user settings in Eclipse

To use Git you must configure your full name and email address. This information is used to fill the author and committer information of commits you create. These Git configuration settings can be adjusted via the Eclipse preference setting. Select Window  Preferences  Version Control (Team)  Git  Configuration to see the current configuration and to change it.

8.2. Default clone location

If you clone a new repository via the Eclipse IDE, it will be cloned by default to a new sub-folder in a default directory. This default path can be configured via the Windows  Preferences  Version Control (Team)  Git entry in the Default Repository folder field.

EGit default repository folder

You can also use Eclipse configuration variables to define the path, e.g., if you want to store repositories in the folder "git" under the Eclipse workspace you may use ${workspace_loc}/git.

8.3. Configuring the toolbar and the menu for Git usage

To simplify access to the common Git operations you can activate the Git toolbar. For this select Window  Perspective  Customize perspective…​ and check the Git and Git Navigation Actions entries in the Action Set Availability tab.

Git toolbar buttons

Afterwards you can configure which Git operations should be available via the Tool Bar Visibility or the Menu Visibility tab.

Git toolbar buttons

8.4. Eclipse support for SSH based authentication

You can create an SSH key pair in Eclipse for SSH based communication. This can be done via Window  Preferences  General  Network Connection  SSH2.

9. Details on the Git views

9.1. Using the Git Repositories view

The Git Repositories view allows you to browse, add. initialize or clone repositories. It also allows to import projects, manage your branches and much more. You can open this view via Window  Show View  Other…​  Git  Git Repositories

Show Git Respositories View

The toolbar allows you to:

  • add an existing local repository to the view

  • clone a repository

  • create a new repository

Git Repositories view toolbar

The content area of the Git Repositories view shows the existing Git repositories and the important data of each repository. The following screenshot shows an example entry.

Git repository view

A right-click (context menu) on an element in the Git repositories view allows you to perform related Git operations. For example, if you right-click on a branch you can checkout the branch or delete it.

Git repository view context menu

9.2. Using the Git Staging view

The Git Staging view allows staging and committing as well as reverting changes.

This view presents which files you have touched and which files will be included in the next commit. Unstaged Changes lists those changes which you have done locally but which you have not yet added to the staging area. Staged Changes lists those changes which you already have added to the staging area. You can drag and drop files from one area to the other. To commit the staged changes you write your commit message and press the Commit button which is highlighted in the following screenshot.

Git Staging View - Commit

You can switch between different repositories or even restart Eclipse without losing a commit message and it allows incremental staging for changes.

You can open the Git Staging view via the Window  Show View  Other…​  Git  Git Staging menu.

9.3. Git integration into the Package and the Project Explorer

The Package Explorer view shows indicators on the files to show their status. The most important icon decorators are depicted in the following screenshot.

Icon decorator

The file name describes the state of the file from the following table:

Table 2. Git label decorations
State Description

tracked

File is committed to the Git repository and has not changed.

untracked

File is neither staged nor committed.

ignored

File is flagged to be ignored by Git operations.

dirty

File has changed since the last commit.

staged

Changes in the file will be included in the next commit.

partially-staged

The resource has changes which are added to the index and additional unstaged changes in the working tree

added

Staged but not yet committed, i.e. snapshot of this file has been stored in the git database. This status is the same as the staged status, but the file wasn’t under Git version control before.

removed

The resource is staged for removal from the Git repository.

conflict

A merge conflict exists for the file.

A combination of the staged and dirty status means: some parts of the changed file have been staged while some are still unstaged. This can happen if you stage a file and then again modify the file before creating the next commit. You can also change the staged parts using the compare editor opened by double clicking files in the staging view.

On a project level the explorer view adds information about which Git repository is used to the project name. It also adds the number of commits that are different between local and remote tracking branch. This way you can quickly see if your local branch is ahead or behind the remote branch it is tracking.

Git icon decorator in the Package Explorer

9.4. Using the History view for viewing the Git history

9.4.1. Purpose of the history view

The History view allows you to analyze the history of your Git repository and to see to which commits the branches and tags points. This view displays author, date, commit message and the modified files of a commit.

This view is depicted in the following screenshot.

History view of changes

You can open this view via Window  Show View  Other…​  Team  History. Alternatively you can open it via the repository node in the Git Repositories view. For this click on the Show In  History entry. Some views, e.g., in the Java EE-Perspective, do not have this shortcut, in this case use Team  Show in History.

To see the history of a resource, select your project, a file or a folder, right-click on it and select the Show in> History context menu entry. Alternatively you can use the Alt+Shift+W shortcut and select the History entry.

You can also configure the History view to display the history of the current selection. Select the highlighted button in the following screenshot for that.

Tracking active selection

If you select a commit you see the commit message and the involved files.

History View

By right-clicking on an individual file you can compare this file with its ancestor (the commit before that) or with the current version in the workspace.

If the "compare mode" toggle is selected from the view menu of the History view you can also double click a file to compare it to the previous version.
Compare mode

9.4.2. The History view filters

The History view has quite some options to configure which commits are displayed. Its toolbar allows you to customize which commits are displayed. By default, the History view filters the history based on the current selection and shows only the active branch.

If you work with several branches, e.g., because you are using Gerrit for code reviews, you typically want to see all branch information and remove the filter based on the resource.

The History view allows you to filter based on resources. See the tooltips of the toolbar for the meaning of the different filter options. In order to see all commits click the highlighted buttons with the Show all changes in this repository and Show all branches and tags tooltips.

Toolbar settings in history view

The following listing gives an overview of the purpose of the different buttons.

History View Buttons

Depending on your use case you may want to select the following option:

  1. show only those commits which are reachable from the current branch. Hide all commits on other topic branches.

  2. see only those commits which changed the selected resource (file, project, subfolder) or its children. E.g. display only those commits which touched the selected java file. The current selection is shown in the top right corner of the History view.

  3. see only those commits which changed anything in the parent folder of the selected resource (file, project, subfolder) or its children. E.g. display only those commits which changed the same package as the selected java source.

  4. see only those commits which changed anything in the same project as the selected resource or its children. Used when you are working in a repository which contains multiple projects.

  5. don’t filter at all. Show all commits of the current repository

The options b., c. and d. are tied to the currently selected resource. Button g. allows that the history view automatically updates when you change the selection.

If you got lost with the different filters and the history doesn’t show what you expect, set it back to show everything. Therefore make sure that Show all branches and tags (a) is turned on and Show all changes in repository (e) is selected.

You can also search for commits based on committer, author, ID or comment. For this turn on the Show Find toolbar (f) and type in a search string in the Find field. The commits fitting to your search are highlighted. You can combine this search with the filters explained above.

Search in the Git history view

The Git Search available in the Search  Search menu is much more powerful and consumes less memory since it doesn’t need to also display the history.

Git search

9.4.4. Showing details of a commit

If you want to see more details about a commit, right-click it and select the Open in Commit Viewer entry.

Commit Viewer
Commit Viewer

9.5. Commit Viewer

The Eclipse IDE allows you to view the content of a commit. For example,if you are in the Git repositories view you can open a commit via the main Eclipse menu. To do this select the Navigate  Open Git Commit menu entry.

Open Git Commit dialog
Open Git Commit dialog

If you open a commit you can create a tag or branch from it. You can also revert it, cherry pick it or check it out. You can also reveal it in the history view.

Possible operation from a Git commit

10. Performing Git operations in Eclipse

10.1. Pull, push and fetch

You can use the Git Repositories view to pull, push and fetch to remote repositories. Right click on your repository and select the appropriate operation.

Pull push and fetch dialog

10.2. Basic team 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-click on your project or file.

Context menu
The Team menu is also available from the context menu of an opened editor.

The most important operations are described in the following list. Select:

  • Team  Add to index, to add the selected resource(s) to the Git index

  • Team  Commit, to open the commit dialog to create a new commit

  • Team  Create Patch…​, to create a patch

  • Team  Apply Patch…​, to apply a patch to your file system

  • Team  Ignore, to add a file to the .gitignore file

  • Team  Show in History, to display the history of the selected resources(s)

10.3. Team operations available on the project

If you select a project you can use additional team operations from the context menu.

Context menu
  • Team  Pull to pull in changes from your remote Git repository

  • Team  Fetch to fetch the current state from the remote repository

  • Team  Switch To to checkout existing or create new branches

  • Team  Push to push changes to your remote Git repository

  • Team  Tag to create and manage tags.

10.4. Amending a commit

Git amend allows you to adjust the last commit. For example you can change the commit message or add another modification.

The Git Staging view allows you to perform the Git amend command via the highlighted button in the following screenshot.

Git amend in the Git Staging view

10.5. Creating and switching branches in Eclipse

Right-click your project and select Team  Switch to  New Branch to create new branches or to switch between existing branches.

You can also switch branches in the History view or the Git repositories view.

10.6. Starting a merge operation in Eclipse

Eclipse supports merging of branches to add the changes committed on one branch into another branch.

Checkout the branch into which you want to merge the changes and select your project and Team  Merge to start the merge dialog.

Team Merge menu
Team Merge menu

10.7. Rebasing a branch onto another branch

The Git Repositories view allows you to rebase your currently checked out branch onto another branch.

Right-click on a repository node and select Rebase as depicted in the following screenshot.

Rebase in EGit

In the following dialog you can select the branch onto which you want to rebase.

Rebase in EGit

You can also select the branch to rebase onto from the Branches node of the tree directly.

If the rebase was successful a dialog is shown. You have to resolve rebase conflicts if they occur. After resolving them, select Rebase  Continue.

If you want to skip the conflicting commit and continue with the rebase operation use Rebase  Skip.

To cancel the rebase operation select Rebase  Abort.

10.8. Solving conflicts created by merge, rebase or other operations

If during a Git operation, two changes are conflicting, you have to solve these conflicts manually. Eclipse highlights the affected files in the Package Explorer and Project Explorer view.

Eclipse Git supports the resolution of these merge conflicts.

To trigger this via the explorer views, right-click on a file with merge conflicts and select Team  Merge Tool.

You can also use the Git staging view to find the conflicting files. In large projects this is usually faster than navigating the Package Explorer or Project Explorer view.

This opens a dialog, asking you which merge mode you would like to use. The easiest way to see the conflicting changes is to use the Use HEAD (the last local version) of conflicting files as merge mode. This way you see the original changes on the left side and the conflicting and non-conflicting changes on the right side.

Selecting the merge model

You can manually edit the text on the left side or use the Copy current change from right to left button to copy the changes from right to left.

Seeing merge conflicts
Copy changes from right to left

Eclipse also allows you to show the common ancestor of both commits to make the merge easier. Press the Hide/Show Ancestor Pane button for that. This is demonstrated by the following screenshots.

Three way merge view in Eclipse
Three way merge view in Eclipse

Once you have manually merged the changes, select Team  Add from the context menu of the resource to mark the conflicts as resolved and commit the merge commit via Team  Commit.

10.9. Git reset and Git reflog

The History view allows you to reset your current branch to a commit. Right-click on a certain commit and select Reset and the reset mode you would like to use.

Reset in EGit

10.10. Finding "invisible" commits with the Reflog view

Commits are not visible in the Git history if they can’t be reached from a branch or tag. This might happen during a reset, commit amend or rebase operation. By default, such invisible commits are removed after two weeks by the Git system.

The Git Reflog view keeps track of the movements of the HEAD pointer and the movements of each branch. This view allows you to find a commit again, e.g., if you used the git reset --hard command to remove certain commits.

10.11. Selecting individual commits via git cherry-pick

In the History view, you can cherry-pick a commit via the context menu. Cherry-pick allows you to move selected changes described by a commit to another branch. You can also use it in combination with a Git reset to perform a simplified interactive rebase.

Let’s assume the following situation, in which you would like to remove the "Bad commit" from the history described by the master branch.

Situation before the cherry pick

You could start with a hard reset of the branch to origin/master. This will move the master branch pointer to the commit described by origin/master. The Good and the bad commit are not reachable anymore by the master branch.

Situation before the cherry pick

To re-apply the changes by the "Good commit", cherry-pick the good commit.

Situation before the cherry pick
Situation before the cherry pick

This results in a history without the bad commit.

10.12. Comparing and replacing files based on the Git history

10.12.1. Comparing files

Eclipse Git allows you to compare a selected file, folder or project with another commit or with the Git index. Use Team  Compare with to open the menu. Afterwards select with what you want to compare. The HEAD Revision selection is depicted in the following screenshot.

Compare

10.12.2. Replacing files

The Team  Replace with menu entry allows you to replace the current selection with the version contained in the selected commit or the Git index.

Compare

11. See Git information line by line (aka git blame)

Eclipse allows you to display which commit and person changed a line. To enable this, right-click on your file and select Team  Show Revision Information.

This action is also available via the line ruler in most editors.

Afterwards, you can place the mouse on the left side of the editor. A popup dialog shows the commit information and the change applied by the shown commit.

Blame annotations in EGit

To ignore whitespace changes in the Git blame annotations in Eclipse, select Window  Preferences  Version Control (Team)  Git and select Ignore whitespace changes.

11.1. Stash via the Git repository view

The git stash command is available in the Git repositories view. Right-click on your Git repository and select Stashes  Stash Changes.

Stash changes in EGit
Stash changes in EGit
Stash changes in EGit

11.2. Creating patches

To create a patch for a set of changes with Eclipse, select the resources for which you want to create a patch in the Package Explorer view. Now, right click and select Team  Create Patch.

Create Patch via EGit menu path
Create Patch via Eclipse Git

The resulting file can be used to get applied to another Git repository, via Team  Apply Patch. You can also apply the patch on a system where Git isn’t installed at all, i.e., you don’t need a Git repository to apply a patch.

12. Using Eclipse Git with GitHub

12.1. Clone project

Copy the URL from GitHub and select in Eclipse from the menu the File  Import  Git  Projects from Git

Eclipse fills out most of the fields based on the URL in the clipboard. Enter your user and password to be able to push to GitHub. Alternatively you can also use an SSH key. You can configure Eclipse to know your SSH via the Window  Preferences  General  Network Connection  SSH2 preference setting. This setting is depicted in the following screenshot.

SSH settings

12.2. Push changes

After you made changes and committed them to your local repository, you can select Team  Push to upstream on the project folder, to push your changes to your GitHub. This requires write access to the GitHub repository.

13. Writing Good Commit Messages

13.1. Importance of Git Commit Messages

A commit adds a new version to the repository. This version is described by a commit message.

The commit message details the changes recorded in a commit. It should help users understand the repository’s history.

A commit message should be descriptive and informative without repeating the code changes.

13.2. Guidelines for Useful Commit Messages

A commit message should consist of a header and a body. The header should be less than 50 characters and the body should wrap at 72 characters. The body is separated from the header by an empty line.

This format ensures the commit message displays well on the command line and in graphical tools.

The body should explain why the change was made. The actual changes can be reviewed with Git.

Use the imperative mood for commit messages, e.g., "Add better error handling" rather than "Added better error handling".

The last paragraph may also include metadata as key-value pairs. This data is known as the commit message footer.

This metadata can trigger specific behaviors. For example, the Gerrit code review system uses the Change-Id key followed by a change-id. This change-id identifies the review associated with the message.

The commit message footer can also include items such as 'Signed-off-by' or link to a bug tracking system, e.g., 'Bug: 1234'.

13.3. Example Message

The following example illustrates a well-structured commit message.

Short summary of the commit (less than 50 characters)

Detailed explanation of the changes, if necessary.
Line breaks at around 72 characters for readability.
Additional details or context can be provided here.

Fixes #8009

This example includes a reference to an issue. GitHub and other Git hosting services automatically recognize such references.

13.4. Good and Bad Examples of Git History

The following listing shows the output of the git log --oneline command from a repository with poor commit messages. The first value in each line is the shortened SHA-1, and the second is the commit message. This history is less informative.

21a8456 update
29f4219 update
016c696 update
29bc541 update
740a130 initial commit

The next listing shows the history of another repository with improved commit messages. This history provides a clearer overview of the activities.

7455823 Adds search and filter to the model editor tree
9a84a8a Missing DynamicMenuContribution in child selector
952e014 Fixes spelling error in Toolbar/Add child
71eeea9 Adds option to import model elements from legacy RCP
123672c New Application wizard is missing dependencies
97cdb9a Creates an id for handlers

14. Contributing to EGit - Getting the source code

This support is provided by the EGit project via a set of plug-ins (software component).

Eclipse uses the JGit library to perform the Git commands. JGit is a library which implements the Git functionality in Java.

EGit is hosted on git://git.eclipse.org.

See EGit contributor guide for a description how to work with the EGit and JGit source.

15. Eclipse Git Resources