Git

Git works a little bit different from SVN. It does not copy the repository, but it clones it. In this context, it is possible to perform any operation locally, without a connection to the Internet, because the complete repository is available. It is possible to perform several actions, such as branching, merging, or committing.

A few differences between Git and SVN are as follows:

  • Git is distributed
  • Git stores the metadata instead of the actual files along with the existing commits
  • Git can work without an active Internet connection since the operations are performed locally

Eclipse comes with a preinstalled plugin to deal with the Git program. The EGit is an Eclipse plugin that provides the Git version control system. As previously mentioned, because Git is a distributed source code manager, every developer has a full copy of all the history of every revision of the code, making the queries against the history very fast and versatile.

If there is need to install it, the user can navigate to Help | Install New Software and add the repository http://download.eclipse.org/egit/updates as it is shown in the following screenshot:

Git

When dealing with the EGit plugin, it is possible to change the perspective to the EGit one. In order to do this, simply navigate to Window | Open Perspective and choose Git Repository Exploring.

Git

In order to create a Git repository, one can navigate to File | New | Git | Git Repository. It is possible to create a local repository if needed. The other option is to import files from an already existing project by navigating to File | Import | Git | Projects from Git as shown in the following screenshot:

Git

In this example, we use the repository of an Eclipse project and the Linux tools that can be cloned using the URL git://git.eclipse.org/gitroot/linuxtools/org.eclipse.linuxtools.git.

Git

After the repository is cloned, the Local and Remote Tracking are shown in the Git perspective. The main Branches node is the master one; nonetheless, others can be created and visualized in the perspective in the Branches node. By supporting branching, Git provides support for you to work on different versions of your collection of resources in parallel. It is possible to work on a fix of a bug in a different branch and merge it back to the main one once this work is finished. Branches in Git are local. A branch created in a local repository, which was cloned from another repository, does not need to have a counterpart in the remote repository. Local branches can be compared to Remote Tracking branches that proxy the state of branches in another remote repository.

Like SVN and CVS, it is also possible to look at the history of the changes by going to the History tab shown in the following screenshot:

Git

In the previous screenshot, it is possible to see the last commits, along with details of the Author, Committer, and Committed Date. If one selects commit, it becomes possible to visualize further information. It is also possible to move to the position of a specific commit, rebasing the resources in that position by right-clicking on it and selecting the Rebase option.

After checking out a given branch by right-clicking on it and going to the Checkout option, the project will be available on the Eclipse workspace. When you modify a given file, you often need to add that modification to a local commit so that it gets pushed to the remote repository. Usually before committing to a Git repository, you need to mark the changes that should be committed. This operation is called by adding the files to the staging area. Nevertheless, in the EGit plugin, you can select which file is going to be committed in the GUI interface by selecting the commit option when right-clicking on the branch being used. Afterwards, it is necessary to type a commit message describing what modification was performed.

After this operation, the push option can be used so that this modification gets pushed upstream. In some cases, when another person has also modified the same resource, there may be merge conflicts; they can be resolved with the assistance of the merge tool of EGit. The commit option can be seen when right-clicking on the node containing the current branch (master, in this case).

Git

Another operation that can be performed is the checkout. This operation allows you to jump among the branches of a repository. In EGit, you simply need to right-click on the desired branch and select the Checkout option. Remember to verify if you have committed any changes that you performed in the previous branch, otherwise they may get lost if you stash (discard) them.

When updating the local repository with the remote repository, you need to use the fetch option. Afterwards, you can choose to rebase or merge the upstream repository with yours using the rebase option; this means that the repository is going to get cloned and the possible commits of yours that are not upstream will later be applied to the tree. The other option is to merge the files present in the local commits with the remote repository. If you choose to use the pull option, by default it performs the fetch and merge operations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset