git log 的提交历史排序选项

xiaoxiao2021-02-28  116

git log 命令显示提交历史时,有两种排序方式: --date-order 和 --topo-order 。默认的排序方式为 --topo-order 。

Commit Order 选项

--date-order Show no parents before all of its children are shown, but otherwise show commits in the commit timestamp order.

父提交总是显示在子提交之前,显示提交时按照提交的时间戳顺序。

--topo-order Show no parents before all of its children are shown, and avoid showing commits on multiple lines of history intermixed.

父提交总是显示在子提交之前,显示提交时尽量避免在多个历史线上交错。

示例

通过例子,能很好的看出这两个选项的对提交历史排序的产生影响的差异。

新建一个代码库,并建立两个分支: b1 和 b2 。按照时间顺序,交错提交代码。为了简化,通过提交注释,记录提交的时间顺序。操作如下:

git init . git commit --allow-empty -m "T1" git checkout -b b1 master git commit --allow-empty -m "T2" git checkout -b b2 master git commit --allow-empty -m "T3" git checkout b1 git commit --allow-empty -m "T4" git checkout b2 git commit --allow-empty -m "T5" **--topo-order 选项的提交排序结果 ** 注意: --topo-order 为默认选项。 $ git log --all --graph --oneline --decorate=short * 39aa4e6 (HEAD -> b2) T5 * 2628a88 T3 | * 2b2b4cd (b1) T4 | * 835cbdd T2 |/ * 8c1fa29 (master) T1 --date-order 选项的提交排序结果 $ git log --all --graph --oneline --decorate=short --date-order * 39aa4e6 (HEAD -> b2) T5 | * 2b2b4cd (b1) T4 * | 2628a88 T3 | * 835cbdd T2 |/ * 8c1fa29 (master) T1

结论

--topo-order 选项导致同一个分支上的提交在历史记录中显示尽量保持连续,在查看提交历史的时候,比较方便。 --date-order 选项导致有多个分支同显示的时候,提交按照时间戳顺序显示,最新的提交显示在最上面,在多个分支上同时进行开发的时候,比较方便。

图形界面设置

SourceTree

SmartGit

gitk

参考

git-log

转载请注明原文地址: https://www.6miu.com/read-19528.html

最新回复(0)