Git - Tree Object

Table of Contents

About

In Git, a tree is an object that corresponds to file system directories 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:


Powered by ComboStrap