Git中的树和提交类型有什么区别? [英] What is the difference between a tree and commit type in Git?

查看:89
本文介绍了Git中的树和提交类型有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个文件签入了一个简单的git仓库。
从我的调查中;有三种类型的对象放置在 .git / objects


  1. commit


  2. blob

举个例子: / p>

  $ git cat-file -t 8b4e834eba22e60c284c7b77e43d3c29e619f92f 
commit

$ git cat-file - t c7c5b03aea0b8c970c93de3670c28f2108948266
tree

$ git cat-file -t e965047ad7c57865823c7d992b1d046ea66edf78
blob

如果我试图在blob上运行git-ls-tree,它会抛出一个错误。

但是我也可以运行它位于提交对象上。

  $ git的LS-树-t c7c5b03aea0b8c970c93de3670c28f2108948266 
100644团块e965047ad7c57865823c7d992b1d046ea66edf78 README.TXT

$ GIT中LS-树-t 8b4e834eba22e60c284c7b77e43d3c29e619f92f
100644团块e965047ad7c57865823c7d992b1d046ea66edf78自述.txt

提交对象也是一个
它们的区别是什么?

解决方案

提交对象是引用树并关联其他对象的对象元数据(作者,提交者,时间戳等)。

$ p $ 提交
/ \
/ \
(父SHA)树
(作者)/ \
(提交者)Blob Blob
(时间戳)
(etc)

多个提交对象可以引用同一棵树(如果每个提交中的文件状态相同)。



例如,如果两个人对文件进行相同的更改并进行提交,它将导致两个不同的提交对象(因为时间戳和作者都不相同)。但是,由于最终结果是相同的文件内容,因此两次提交都将指向同一棵树。



运行 git ls-tree 在提交SHA上,它会自动使用该提交引用的树SHA。


I checked in one file into a simple git repo. From my investigations; there are three types of objects placed in .git/objects

  1. commit
  2. tree
  3. 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 a blob, it throws an error.

But it is equally possible for me 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 a commit object also a tree ? What are their differences, if any ?

解决方案

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

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

Multiple commit objects can reference the same tree (if the state of files in each commit is identical).

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

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

这篇关于Git中的树和提交类型有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆