简体   繁体   English

坚固:树的路径和commit_id

[英]Rugged: Path and commit_id of tree

I have a rugged tree object and I want to find out what is its path (relative to root) and what was the commit id when that tree was written. 我有一个坚固的树对象,我想找出它的路径(相对于根)是什么,以及写那棵树时的提交ID是什么。 For example: 例如:

tree  = repo.lookup '7892eeee70c08fae4db63aef7000dea39f883b30' #sha/oid of tree

What operations should I perform on this tree object so that I get its path and commit id? 我应该对此树对象执行哪些操作,以便获取其路径并提交ID?

That information is not stored in the tree at all. 该信息根本不存储在树中。 Git uses Merkle trees where the parents know what the children trees are, but each tree can be contained in multiple commits (this is the typical situation, as some subdirs are very rarely touched). Git使用Merkle树,父母知道孩子的树是什么,但是每棵树都可以包含在多个提交中(这是典型的情况,因为很少会触及某些子目录)。

A tree may also be accessible through many different paths, if those directories have the same contents. 如果那些目录具有相同的内容,也可以通过许多不同的路径来访问树。

The only way to figure out where a tree belongs would be to go and look at each commit and recursively look from the root to see if you can find the tree you were given. 找出一棵树所属位置的唯一方法是去查看每个提交,然后从根目录递归查看以查看是否可以找到给定的树。 This is going to be a very expensive operation. 这将是非常昂贵的操作。

I would recommend you take a step back and figure out why you think you need to figure out where a tree is reachable from. 我建议您退后一步,弄清楚为什么您认为需要弄清楚从何处可以到达树。 It sounds like you've already decided many steps and you're asking about a detail, when you should be looking at it from a higher level. 听起来好像您已经决定了许多步骤,并且您正在询问一个细节,何时应该从更高层次上进行查看。

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

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