Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[concept] .git - JGit #71

Open
dorawyy opened this issue Nov 12, 2017 · 0 comments
Open

[concept] .git - JGit #71

dorawyy opened this issue Nov 12, 2017 · 0 comments
Labels

Comments

@dorawyy
Copy link
Owner

dorawyy commented Nov 12, 2017

Referenced from EGit

Repository

The Repository or Object Database stores all objects which make up the history of the project. All objects in this database are identified through a secure 20 byte SHA-1 hash of the object content.

Git has 4 object types:

  • Blob object: stores file content
  • Tree object: stores the directory structure and contains Blob objects and other Tree objects together with their file system names and modes.
  • Commit object represents a snapshot of the directory structure at the time of the commit and has a link to its predecessor Commit object which form an acyclic graph of the repository revisions forming the repository history.
  • A Tag object is a symbolic named link to another repository object which contains the object's name and type. Optionally, it also contains information about who created the tag and other signing information.

The object database is stored in the .git/objects directory. Objects are either stored as loose objects or in a single-file packed format for efficient storage and transport.

Index

The Git Index is a binary file stored in the .git/index directory containing a sorted list of file names, file modes, and file meta data used to efficiently detect file modifications. It also contains the SHA-1 object names of blob objects.

It has the following important properties:

  • The index contains all information necessary to generate a single uniquely defined tree object. E.g. a commit operation generates this tree, stores it in the object database and associates it with the commit.
  • The index enables fast comparison of the tree it defines with the current working directory. This is achieved by storing additional meta data about the involved files in the index data.
  • The index can efficiently store information about merge conflicts between the trees involved in the merge so that for each pathname there is enough information about the involved trees to enable a three-way merge.

Branches

A branch in Git is a named reference to a commit. There are two types of branches, namely "Local" and "Remote Tracking" branches which serve different purposes.

Local Branches

Whenever a change to a (local) Repository is committed, a new commit object is created. Without any other means, it would be very difficult to keep track of the changes in the Repository, in particular when other commits are added to the Repository, for example due to an update from the remote Repository or when checking out another commit.

A local branch helps with this task by providing a (local) name by which the "current" commit can be found. When changes are committed to the local repository, the branch is automatically updated to point to the newly created commit.

In addition, it is possible to add a so-called upstream configuration to a local branch which can be helpful when synchronizing with a remote repository.

Remote Tracking Branches

Remote tracking branches are created automatically when cloning and fetching from remote repositories. A remote tracking branch in the local repository always corresponds to a (local) branch in the remote repository. The name of such a branch follows certain conventions.

The remote tracking branch points to the same commit as the corresponding branch in the remote repository (at the time of the clone/fetch).

Remote tracking branches can be used for automated creation of upstream configuration for local branches.

Working Directory

The working directory is the directory used to modify files for the next commit. By default it is located one level above the .git directory. Making a new commit typically involves the following steps:

  • Check out the branch the new commit shall be based on. This changes the working directory so that it reflects the HEAD revision of the branch.
  • Do modifications in the working directory.
  • Tell git about these modifications (add modified files). This transfers the modified file contents into the object database and prepares the tree to be committed in the index.
  • Commit the tree prepared in the index into the object database.
    The result is a new commit object and the HEAD of the current branch moves to the new commit.

Recording Changes in the Repository

You start from a fresh checkout of a branch of a local repository. You want to do some changes and record snapshots of these changes in the repository whenever you reach a state you want to record.

Each file in the working directory can either be tracked or untracked:

  • Tracked files are those which were in the last snapshot or files which have been newly staged into the index. They can be unmodified, modified, or staged.
  • Untracked files are all other files (they were not in the last snapshot and have not yet been added to the index).
    When you first clone a repository, all files in the working directory will be tracked and unmodified since they have been freshly checked out and you haven't started editing them yet.

As you edit files, git will recognize they are modified with respect to the last commit. You stage the modified files into the index and then commit the staged changes. The cycle can then repeat.

@dorawyy dorawyy changed the title [concept] .git [concept] .git - JGit Nov 15, 2017
@dorawyy dorawyy added the JGit label Nov 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant