Git - Tree Object

About

In Git, a tree is an object that corresponds to file system directory in the git file system.

A single tree object contains:

  • one or more entries, each of which is the SHA-1 hash of a blob
  • or subtree with its associated mode, type, and filename.

A snapshots of a directory is a tree and every new snapshot is a new tree.

Example

Most-recent tree with the master^{tree} syntax that specifies the tree object that is pointed to by the last commit on your master branch.

  • On linux bash
git cat-file -p master^{tree}
git cat-file -p master^^{tree}
  • On powershell, you need to quote it because of the {} characters.
git cat-file -p 'master^{tree}'
100644 blob a906cb2a4a904a152e80877d4088654daad0c859      README
100644 blob 8f94139338f9404f26296befa88755fc2598c289      file
040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0      dir

Note the dir subdirectory isn’t a blob but a pointer to another tree.

git cat-file -p 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0
100644 blob 47c6340d6459e05787f644c2447d2595f5d3a54b     file

It corresponds to: Git File System

Management

Traverse / List

You can traverse /list a tree with the ls-tree 1) command

git ls-tree

Example:

git ls-tree commitHash^{tree}
100644 blob 252a5555a0c77eb6f6f95580b30c575f5af62a9d    .gitattributes
100644 blob de03f380381fc2453914e9ed03fe43925591cdb1    .gitignore
100644 blob ab62e63667456a351c26ab3f798e0d31f71fae20    .travis-boot.sh
100644 blob 2dbb8ed0b3a899af4f1cd44d32f162696a4a87d6    .travis.yml
100644 blob d159169d1050894d3ea3b98e1c965c4058208fe1    LICENSE
100644 blob 1dfe81d013e730a013eab133821667e4f799c00e    README.md
100644 blob 96207da41ac9374fc76c6b6b5dba16c935f3d498    browser-sync-start.bat
040000 tree ff0d130dfbfa0329345c2017df37275dfc442fb2    resources





Discover More
Git

is a content-addressable file system used to track directory tree content (as defined by its creator Linux Torvald) It's not a version control...
Git Commit Tree Data Model
Git - Commit

A commit in git is an object that stores the information : who saved the file system snapshots, when they were saved, why they were saved. the commiter the author the parent commit It's...
Git - Database

The git core database is a key store value where a key value entry is known as an object. (All data in Git are objects) The database is mostly composed: * of tree of object * * * *...
Git - Directory

In git, a directory is a tree object
Git - Objects (Database)

An object is the value in the entry of the git database key-value. All entities in git are objects. Objects are the entity of the Git file system. On the operating file system, the objects are stored...
Git - Show

git show is a general command line tool that shows information object where hash is the object hash for commits it shows the log message and textual diff. It also presents the merge commit in a...
How to perform a text file diff in Git?

This page is text file diff in Git Diff between the head commit of the current branch (HEAD) and the current file not yet committed (in the working area) Between the head of the main branch...
Git Commit Tree Data Model
What is a git snapshot ?

A git snapshot is a representation of your local file system when a commit is performed. It's attached to each commit. Each new snapshot (ie commit) will create a new Git tree. ie the directory...
Git File System
What is the Git File System ?

git has a file system application feature. The whole git file system is stored in the object database where: the tree objects corresponds to UNIX directory entries (ie directory) and blob objects...
Git - Repository (Directory)

This page is the notion of repository and how it's implemented in Git. The git repository is a subdirectory named .git that contains all repository files. It contains : commit log configuration,...



Share this page:
Follow us:
Task Runner