Git objects: tree

CommandNew filesChanged filesDeleted files
Alice/> git init
Initialized empty Git repository in /home/rene/github/github/git-internals/repos/objects_tree/Alice/.git/
snap no: 1
Alice/> printf "foo\nbar\nbaz\n"   > same.txt
snap no: 2
Alice/> mkdir dir; cp same.txt dir
snap no: 3
Alice/> mkdir dir/subdir; cp same.txt dir/subdir
snap no: 4
dir/subdir/same.txt
Alice/> echo foo > abc.txt; echo root > root.txt
snap no: 5
Alice/> echo bar > dir/abc.txt; echo dir > dir/dir.txt
snap no: 6
Alice/> echo baz > dir/subdir/abc.txt; echo subdir > dir/subdir/subdir.txt
snap no: 7
dir/subdir/abc.txt
dir/subdir/subdir.txt
Alice/> git add *
snap no: 8
Alice/> git commit -m "Add directories"
[master (root-commit) aba117a] Add directories
 9 files changed, 15 insertions(+)
 create mode 100644 abc.txt
 create mode 100644 dir/abc.txt
 create mode 100644 dir/dir.txt
 create mode 100644 dir/same.txt
 create mode 100644 dir/subdir/abc.txt
 create mode 100644 dir/subdir/same.txt
 create mode 100644 dir/subdir/subdir.txt
 create mode 100644 root.txt
 create mode 100644 same.txt
snap no: 9
.git/COMMIT_EDITMSG
.git/logs/HEAD
.git/logs/refs/heads/master
.git/objects/24/c8aea1a7aeaecf4ac30596b830468d4d389f72 [tree]
.git/objects/ab/a117aaa11dfff071a3a49c27ed8fb8bdbbb3a7 [commit]
.git/objects/bc/803574f4bb34f2028acf6dfe3f2e2df68434ac [tree]
.git/objects/e7/412b351c5c1999a9f7881acb1a3fab048e0e10 [tree]
.git/refs/heads/master

Show the tree object of the last commit using the master^{tree} syntax.

Alice/> git cat-file -p master^{tree}
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99	abc.txt
040000 tree e7412b351c5c1999a9f7881acb1a3fab048e0e10	dir
100644 blob d8649da39ddf7910d29982e2f19cd9c0ff5ffe96	root.txt
100644 blob 86e041dad66a19b9518b83b78865015f62662f75	same.txt

A (sub-)directory is referenced by another tree object (e7412b3…)

snap no: 10

Showing the content of this tree object (dir)

Alice/> git cat-file -p e7412b3
100644 blob 5716ca5987cbf97d6bb54920bea6adde242d87e6	abc.txt
100644 blob 0d2ecd7fd0bf6293aea541433522dc60a9236bf8	dir.txt
100644 blob 86e041dad66a19b9518b83b78865015f62662f75	same.txt
040000 tree 24c8aea1a7aeaecf4ac30596b830468d4d389f72	subdir

Again, the tree object contains another tree object (subdir, 24c8aea…)

snap no: 11

Showing the content of dir/subdir

Alice/> git cat-file -p 24c8aea
100644 blob 76018072e09c5d31c8c6e3113b8aa0fe625195ca	abc.txt
100644 blob 86e041dad66a19b9518b83b78865015f62662f75	same.txt
100644 blob 80034a114f40407fa8f08e9f3c2790952d70b7fa	subdir.txt
snap no: 12