1

What does the string in the third column mean when we do

$ git ls-tree HEAD

like so

enter image description here

0

2 Answers 2

2

The third column is the key of the objects contained the tree that you are currently seeing.

Git stores all the information it handles in a key-value storage, the key being the hashes that you see printed with ls-tree or the hash that is created when a commit happens.

There are three kind of objects git saves: commits, trees, and blobs.

You can access the contents of any of the objects that git has stored with the command git cat-file <hash>. For example the following command (-p for pretty printing) will print the contents of your commit object which should look similar to this:

> git cat-file -p HEAD
tree def456aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
parent f1ddfa625b139184e8b719fcb662e713a77fedcb
author Bob Foo <[email protected]> 1358366479 -0800
committer Bob Foo <[email protected]> 1358366479 -0800

The commit message.

The contents of the tree object that is displayed there (the assumed def456...) is exactly what you see when using git ls-tree HEAD. So if you use the following command you should see exactly the same output:

> git cat-file -p def456aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
# the same output as: git ls-tree HEAD

With the hashes displayed there you can keep doing the same. If you use it with a blob object it will print the contents of the file, if you use it with a tree object, it will display the contents of the tree, which would be a subdirectory in your repository. For example to see the current contents of the contact.html file you can use:

> git cat-file -p 2271a9
# contents in contact.html

Lastly, check Git Internals - Git Objects for more information about all this.

1

I would assume that it's the unique 40-character sha1 hash ID of each object contained in the given tree in the Git repository, though the documentation for git ls-tree doesn't really make that clear, and only refers to the 3rd column as <object>:

Output Format

<mode> SP <type> SP <object> TAB <file>
1
  • As far as know 40-character SHA-1 hash Id is only generated for each comment. Is it created for each file and folder in repo? Commented Aug 16, 2013 at 10:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.