Git - Tree Object


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.


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:


Traverse / List

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

git ls-tree


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

Powered by ComboStrap