Git Object: Tree

本文介绍了Git树对象如何类似于文件系统的目录结构。通过示例展示了文件和目录如何被存储为Git树和Blob对象,并解释了这些对象之间的引用关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

tree

A git tree object is very similar to a filesystem directory.

Filesystem directories refer to other directories and files, while git trees refer to other git trees and git blobs:

Filesystem Directories Refer To: Git Trees Refer To:
1. Other directories 1. Other git trees
2. Files 2. Git blobs (files)

Example: Filesystem Directories and Files; Git Trees and Files

Diagram 1: The filesystem

In Diagram 1, below, an example filesystem directory and files is shown.

  • There are 3 directories: src, docs and the top of the working directory.
  • There are 4 files named README, hello.c, hello.py and hello. The contents of the files are shown in the grey boxes below the filenames.

The commands for creating the files and directories, and adding the files to the git object store, is shown here.

Diagram 2: The Git Object Store

Diagram 2 shows how the files and directories are stored as git trees and blobs in the git object store, after the user adds and commits the files and directories to the git repository.

Diagram 2 shows the top of the git tree’s hash is 39179a1 (lower left-hand corner of the highest green triangle). That git tree refers to 3 objects:

  1. The blob that contains the contents of the README file.
  2. The tree that contains the contents of the src directory.
  3. The tree that contains the contents of the doc directory.

The first few bytes of the hash of each object is shown below the object.

Diagram 3: The Object Hashes

Diagram 3 adds annotation that shows how each object’s hash is referred to in the git trees.

Diagram 4: Objects Without Name Labels

Diagram 4 shows the same git object store, but without each of the objects including their name above the left side of the object. This more accurately that objects are stored by their hash. Git knows the name of an object when the object is referred to in a git tree: The git tree includes the object’s hash and its name.

In the next section, the commands for both creating the above git object store and displaying the hashes are shown.

Next: Git Session: The Commands Used For The Examples On This Page
Previous: The Git Blob Object

Related:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值