6

I am a git novice trying to sort through the concepts and terms. The git glossary says a tree is equivalent to a directory and a directory is what you get with ls. Are they interchangeable terms? Or are "tree" and "directory" to be used in different contexts or to refer to separate (though related) things?

nulltoken
  • 64,429
  • 20
  • 138
  • 130
user7797
  • 337
  • 3
  • 8
  • 1
    I had the same problem http://stackoverflow.com/questions/5917738/how-does-git-record-or-more-likely-represent-file-paths-and-names-for-its-blob - The commit tree structure is/does match the directory structure of the files contained in the commit, but excludes 'empty' directories with nothing to track. Checking out a branch will create any needed directories, but won't delete any. – Philip Oakley Jun 04 '11 at 20:01

4 Answers4

3

In Git terminology, a "tree" is a hierarchical structure of files and directories. This is (purposefully) very similar to a directory in a filesystem.

A Git commit object contains a reference to a tree object, which is the state of all files at the time of that commit.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
3

The short answer: yes, a tree is a directory and a directory is a tree.

The long answer: A tree is an object that contains a list of blobs, the names to attach to the blobs, and other trees and the names to attach to them. http://book.git-scm.com/1_the_git_object_model.html has a pretty good explanation of the different object types in the git model; I would suggest reading it!

clee
  • 10,943
  • 6
  • 36
  • 28
1
OnesimusUnbound
  • 2,886
  • 3
  • 30
  • 40
-1

To put it simply, the "tree" refers to the snapshot of the entire repository state at that moment in time (like what you've got for your current code [which is also known as HEAD], of the repository when the currently checked-out commit was made, etc.)

Directory is just referring to a filesystem directory.

damianb
  • 1,224
  • 7
  • 16
  • I scare myself with my parenthesis layering sometimes. – damianb Jun 04 '11 at 03:34
  • Not strictly true since a tree contains other trees, which themselves may also belong to trees from previous (and future) commits. – siride Jun 04 '11 at 04:09
  • The tree for some directory and the tree for the same directory in other commit may be the same (same SHA1). So a tree may not represent the whole directory and it has nothing to do with time (commits do). – svick Jun 04 '11 at 21:35