How to view Git objects

Source: Internet
Author: User
Tags sha1

Original: http://gitbook.liuhui998.com/7_2.html

If you don't know how git is stored before reading this article, read how Git stores objects. We can use the Cat-file command to query the information for a particular object. Note that only part of the SHA value is typed below, and you do not have to type all 40 characters:

$ git-cat-file -t 54196cc2 Commit$ git-cat-file commit 54196cc2 Tree 92b8b694ffb1675e5975148e1121810081dbdffe author J. Bruce fields <[email protected]. Fieldses. org> 1143414668 -0500 committer J. Bruce fields <[email protected]. Fieldses. org> 1143414668 -0500 Initial CommitA tree object can refer to one or more block (BLOB) objects, each of which corresponds to a file.  Further, the tree object can also refer to other tree objects, thus constituting a directory hierarchy. Each commit corresponds to a tree object. You can use Ls-tree to view the contents of the tree:$ git ls-tree 92b8b694 100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad file. TXT We can see that the tree contains a file. The SHA value is a reference to the contents of the file (the translator notes that the pointer points to the corresponding block object).$ git cat-file -t 3b18e512 blobA "block" (BLOB) is the data of a file, and we can view its contents with Cat-file:

$ git cat-file blob 3b18e512 Hello WorldNotice that the data in the file is old. The initial tree is actually a snapshot of the directory state that was logged the first time it was committed. All objects are stored under the GIT directory using the SHA1 value as an index:

$ find . Git/objects/ . git/objects/ . git/objects/pack . git/objects/info . git/objects/3b . git/objects/3b/18e512dba79e4c8300dd08aeb37f8e728b8dad . git/objects/ . Git/objects/b8b694ffb1675e5975148e1121810081dbdffe . git/objects/ si. Git/objects/196cc2703dc165cbd373a65a4dcf22d50ae7f7 . Git/objects/a0 . git/objects/a0/423896973644771497bdc03eb99d5281615b51 . Git/objects/d0 . git/objects/d0/492b368b66bdabf2ac1fd8c92b39d3db916e59 . git/objects/c4 . git/objects/c4/d59f390b9cfd4318117afde11d601c1085f241 The contents of these files are actually compressed data plus a callout type and length of the header. The type can be a block (BLOB), a tree, commit (commit), or a tag (tag). The most easily found commits are head commits, which we can find in. Git/head:

$ cat . Git/HEAD ref: refs/heads/Master As you can see, the above output tells us which branch we are working on. git identifies a branch by creating a file in the. git directory (refs/heads the following file, multiple branches will have multiple files). Each file contains a committed SHA1 value, and we can use Cat-file to view the content of this submission (this is the head of the branch):

$ cat . Git/refs/heads/Master c4d59f390b9cfd4318117afde11d601c1085f241$ git cat-file -t c4d59f39 Commit$ git cat-file commit c4d59f39 Tree d0492b368b66bdabf2ac1fd8c92b39d3db916e59parent 54196cc2703dc165cbd373a65a4dcf22d50ae7f7 author J.bruce fields <[email protected].. Org> 1143418702 -< Span class= "lit" >0500 committer J. Bruce fields <[email protected]. Fieldses. org> 1143418702 -0500 Add emphasisThe tree object here points to the new state of the tree:$ git ls-tree d0492b36 100644 blob a0423896973644771497bdc03eb99d5281615b51 file. TXT $ git cat-file blob a0423896 Hello World! The parent object points to the previous commit:

$ git-cat-file commit 54196cc2 Tree 92b8b694ffb1675e5975148e1121810081dbdffe author J.bruce fields <[email protected].. Org> 1143414668 -< Span class= "lit" >0500 committer J. Bruce fields <[email protected]. Fieldses. org> 1143414668 -0500 End!

How to view Git objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.