【问题标题】:What is the difference between a tree and commit type in Git?Git中的树和提交类型有什么区别?
【发布时间】:2011-03-09 16:02:58
【问题描述】:

我将一个文件签入到一个简单的 git 存储库中。 根据我的调查; .git/objects中放置了三种对象

  1. 提交
  2. 斑点

举个例子:

$ git cat-file -t 8b4e834eba22e60c284c7b77e43d3c29e619f92f
commit

$ git cat-file -t c7c5b03aea0b8c970c93de3670c28f2108948266
tree

$ git cat-file -t e965047ad7c57865823c7d992b1d046ea66edf78
blob

如果我尝试在 blob 上运行 git-ls-tree,则会引发错误。

但我同样可以在 committree 对象上运行它。

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

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

commit 对象也是 tree 吗? 它们有什么区别(如果有的话)?

【问题讨论】:

    标签: git


    【解决方案1】:

    提交对象是一个引用树并将其他元数据(作者、提交者、时间戳等)与其相关联的对象。

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2017-10-01
      • 2010-10-02
      • 2019-09-02
      • 2015-09-10
      • 2017-10-04
      相关资源
      最近更新 更多