简体   繁体   English

如何从提交 object 中获取 git ls-tree?

[英]How to git ls-tree from a commit object?

From documentation, in order to use git ls-tree you need to pass the hash of a tree object.从文档中,为了使用git ls-tree ,您需要传递树 object 的 hash。 What if I want to obtain the same output of git ls-tree starting from a commit object.如果我想从提交 object 开始获得与git ls-tree相同的 output 怎么办。 I can obviously do it with something like this:我显然可以这样做:

git ls-tree $(git cat-file -p my_commit | grep -oP "(?<=tree ).*")

But I feel like I am reinventing the wheel.但我觉得我正在重新发明轮子。 Is there a git command that already does this?是否有已经执行此操作的 git 命令?

No, git ls-tree takes a tree-ish object .不, git ls-tree采用树状object

The "-ish" suffix here is important.这里的“-ish”后缀很重要。 Per the Cambridge Dictionary :根据剑桥词典

-ish suffix (QUITE) -ish 后缀(QUITE)

used to form adjectives to give the meaning to some degree;用于构成形容词以在一定程度上赋予意义; fairly:相当:

  • He had a sort of reddish beard.他有一种红色的胡须。
  • She was oldish - about 60, I'd say.她很老——我会说大约 60 岁。
  • We'll start at sevenish (= about seven o'clock).我们将从七点钟开始(= 大约七点钟)。

In this case, "tree-ish" means like a tree .在这种情况下,“tree-ish”的意思是就像一棵树 A tree, of course, is like a tree .当然,一棵树就像一棵树 But a commit is also like a tree since it has exactly one tree component;但是提交像一棵树,因为它只有一个树组件; that means that you can unambiguously refer to that tree by simply using the commit itself.这意味着您可以通过简单地使用提交本身来明确地引用该树。

So, just do git ls-tree <commit-ish> .因此,只需执行git ls-tree <commit-ish>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM