DAG 与使用 Git 的树?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26395521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DAG vs. tree using Git?
提问by Jonathan.Brink
I've often read that Git uses the directed acyclic graph(DAG) data structure, with each commit as a node, and things like branches and tags as pointers to nodes.
我经常读到 Git 使用有向无环图(DAG) 数据结构,将每个提交作为一个节点,将分支和标签等内容作为指向节点的指针。
But when I try to visualize my commit history using tools like gitk, it looks more like a tree than a graph since every parent-child relationship is directed one way.
但是当我尝试使用 gitk 之类的工具可视化我的提交历史时,它看起来更像是一棵树而不是图形,因为每个父子关系都是以一种方式指向的。
So, what's the difference between a DAG and a tree, specifically with regards to Git?
那么,DAG 和树之间有什么区别,特别是在 Git 方面?
回答by John Kugelman
But when I try to visualize my commit history using tools like gitk, it looks more like a tree than a graph since every parent-child relationship is directed one way.
但是当我尝试使用 gitk 之类的工具可视化我的提交历史时,它看起来更像是一棵树而不是图形,因为每个父子关系都是以一种方式指向的。
A DAG, like a tree, can be laid out such that all parent-child relationships are one-way. The difference between them is that nodes in a DAG can have multiple parents. The most common case of this in Git is when you do a merge. A merge commit will have all of the commits that were merged as parents. A tree doesn't allow nodes to have multiple parents.
一个 DAG,就像一棵树,可以布置成所有的父子关系都是单向的。它们之间的区别在于 DAG 中的节点可以有多个父节点。Git 中最常见的情况是进行合并时。合并提交将具有作为父项合并的所有提交。一棵树不允许节点有多个父节点。
(图片来源)
Notice how the merge commit C6 has two parents, C4 and C5.
注意合并提交 C6 有两个父级 C4 和 C5。