What is the difference between tree and type of commit in Git?

I checked in a single file a simple git repository. From my research; there are three types of objects placed in .git/objects

  • commit
  • wood
  • blob

As an example:

 $ git cat-file -t 8b4e834eba22e60c284c7b77e43d3c29e619f92f commit $ git cat-file -t c7c5b03aea0b8c970c93de3670c28f2108948266 tree $ git cat-file -t e965047ad7c57865823c7d992b1d046ea66edf78 blob 

If I tried to run git -ls-tree on blob, it gives an error.

But for me it is also possible to run it on a commit or tree object.

 $ git ls-tree -t c7c5b03aea0b8c970c93de3670c28f2108948266 100644 blob e965047ad7c57865823c7d992b1d046ea66edf78 readme.txt $ git ls-tree -t 8b4e834eba22e60c284c7b77e43d3c29e619f92f 100644 blob e965047ad7c57865823c7d992b1d046ea66edf78 readme.txt 

Is the commit object also a tree ? What are their differences, if any?

+4
source share
1 answer

A commit object is an object that refers to a tree and associates other metadata with it (author, committer, timestamps, etc.).

  Commit / \ / \ (parent SHA) Tree (author) / \ (committer) Blob Blob (timestamps) (etc) 

Several commit objects can refer to the same tree (if the state of the files in each commit is identical).

For example, if two people make the same change in a file and commit, this will result in two different commit objects (since both timestamps and authors will be different). However, since the end result is the same file content, both commits point to the same tree.

When you execute git ls-tree on a SHA commit, it automatically uses the SHA of the tree referenced by that commit.

+9
source

Source: https://habr.com/ru/post/1342956/


All Articles