Git Object: tree


A git tree object is very similar to a filesystem directory.

Filesystem directories refer to other directories and files, while git trees refer to other git trees and git blobs:

Filesystem Directories Refer To: Git Trees Refer To:
1. Other directories 1. Other git trees
2. Files 2. Git blobs (files)

Example: Filesystem Directories and Files; Git Trees and Files

Diagram 1: The filesystem

In Diagram 1, below, an example filesystem directory and files is shown.

  • There are 3 directories: src, docs and the top of the working directory.
  • There are 4 files named README, hello.c, and hello. The contents of the files are shown in the grey boxes below the filenames.

The commands for creating the files and directories, and adding the files to the git object store, is shown here.

Diagram 2: The Git Object Store

Diagram 2 shows how the files and directories are stored as git trees and blobs in the git object store, after the user adds and commits the files and directories to the git repository.

Diagram 2 shows the top of the git tree’s hash is 39179a1 (lower left-hand corner of the highest green triangle). That git tree refers to 3 objects:

  1. The blob that contains the contents of the README file.
  2. The tree that contains the contents of the src directory.
  3. The tree that contains the contents of the doc directory.

The first few bytes of the hash of each object is shown below the object.

Diagram 3: The Object Hashes

Diagram 3 adds annotation that shows how each object’s hash is referred to in the git trees.

Diagram 4: Objects Without Name Labels

Diagram 4 shows the same git object store, but without each of the objects including their name above the left side of the object. This more accurately that objects are stored by their hash. Git knows the name of an object when the object is referred to in a git tree: The git tree includes the object’s hash and its name.

Recent Articles

What is the deal with the Git Index? What is the Git Index?

The git "index" is where you place files you want committed to the git repository. Learn more about the git index and git commit by selecting this link.

Visualising Branches And Their Commits | Git Show-branch

We explain and discuss the use of the git show-branch, gitg, gitk and qgit in this Tutorial. Complete with examples.

“Tracking Branches” And “Remote-Tracking Branches”

Both Tracking Branches and Remote Tracking Branches are created on the git client when a git clone command is used.

Temporarily Stashing Your Work

Git Stash is used when you want to record the current state of the working directory and index, without committing, to come back to complete later.

Shared Repositories Should Be Bare Repositories

Bare Repositories - When creating a central repository that will be shared by other users, the repositories should be created with the --bare option.

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox