如何重现git log的格式--oneline --decorate?

时间:2016-10-06 04:44:54

标签: git git-log

git log的格式在哪里--oneline --decorate定义?

使用git Iog --format = format:'我的格式',我无法重现分支,标签和HEAD的颜色,如git log --oneline --decorate所示。

 git log --oneline --decorate    

显示浅蓝色的HEAD,绿色的分支名称和棕色的标点符号(。)。

我最接近得到我想要的是:

git log --graph --abbrev-commit --decorate --date=short --format=format:'%C(bold blue)%h%C(reset) %C(bold green)%ad%C(reset)%d %C(white)%s%C(reset)' -20  

唯一的区别是branches / HEAD /标签没有像上一个命令那样着色。

2 个答案:

答案 0 :(得分:4)

git版本似乎不可能< 1.8.3。

从git 1.8.3开始,可以使用颜色%C(自动)令牌:

   git log --graph --abbrev-commit --decorate --date=short --format=format:'%C(bold blue)%h%C(reset) %C(bold green)%ad%C(reset) %C(auto)%d %C(reset)  %C(white)%s%C(reset)' -20    

关键要素是:

%C(auto)%d %C(reset) 

另见:

Color in git-log
Git pretty format colors

答案 1 :(得分:2)

TL; DR - 我认为您无法获得$watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = "C:\temp\test" $watcher.IncludeSubdirectories = $true $watcher.EnableRaisingEvents = $true $created = Register-ObjectEvent $watcher "Created" -Action { write-host "Created: $($eventArgs.FullPath)" Get-Date -Format "HH:mm:ss" | Out-File "C:\temp\log.txt" -Append } 提供的确切格式,因为git log --oneline选项不支持&--format #39; t允许任何条件语句,而git-log使用函数在每个提交消息上生成该字符串。

我最接近颜色的是:

git log --format=format:'%C(auto)%h%C(reset) %C(auto)%s%C(reset)'

在我的机器上看起来像这样:

terminal-screenshot

长版:

您可以在git-log上阅读的大部分文档都在这里:https://git-scm.com/docs/git-log

我深入研究了源代码(可在github here上找到),看看git对--oneline选项的确切作用,这里是我发现的:

  • 该路径从revision.c开始,其中解析命令行选项

  • 然后在pretty.c中解析该选项,以匹配CMIT_FMT_ONELINE枚举的cmit_fmt(在commit.h中定义)

  • 最后,实际打印在pretty.c pp_commit_easy处进行。

  • 这是一个棘手而复杂的地方。您可以在CMIT_FMT_ONELINE的少数几个地方看到对pretty.c的引用。我相信在指定--oneline选项时,每次提交只执行pp_title_line。您可以看到,随着字符串缓冲区的构建,会出现一堆条件格式。

所以是的,我认为没有办法用标签和(HEAD -> master)元信息复制实际格式。您可以编写一个执行相同操作的shell脚本,但其性能可能与git的性能不匹配。

相关问题