'git log' 是否使用深度优先搜索遍历来显示提交?

Does 'git log' use Depth First Search traversal to display the commits?

我想了解 'git log' 显示提交的顺序。我的信念是 'git log' 执行 DFS(深度优先搜索)。 我知道 git 中的提交遵循 DAG 结构。 谢谢, 安达

git log 不会 进行 depth-first 搜索。但是,它的作用也不能完全描述为 breadth-first。

实际算法是使用优先级队列。根据 command-line 个参数,每个最初要访问的提交都被插入到优先级队列中。然后,在访问提交时,由于历史简化而在进行任何修改后插入其 parents(或者由于已经访问 / in-the-queue 而被省略)。当前访问完成后,下一次提交将离开要访问的优先级队列。

每个提交的优先级,因为它被插入到队列中,基于command-line 排序选项:

  • 默认值:优先级 = 提交者日期,更高的日期 = 更高的优先级(排在队列前面的更多)
  • --date-order:优先级=children>parents;但如果一对提交不相关,提交者日期照常
  • --author-date-order:优先级=children > parents,但如果一对提交不相关,则使用作者日期而不是提交者日期
  • --topo-order(由--graph自动开启):children > parents;拆分合并提交时,将每个 "leg" 中的所有 children 组合在一起。

请注意,没有 "priority = author date" 不需要 也需要 children-before-parents,即使 默认值 订单允许 children-before-parents.

(在内部,由于 --boundary 处理、--reverse--skip--max-count,代码比此描述更混乱,但上面的内容有点目标 无论如何。)


请注意 git log -g(遍历 reflog)非常不同:它始终以 reflog 顺序运行,并且会在适当的情况下多次访问提交。