git log


#Git#


让 git log 的输出漂亮简洁

git log 用于打印出提交历史。但默认的配置中限时的内容不够好看,内容密度不够高。可以配置如下:

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an %ae>%Creset' --abbrev-commit"

(来自 https://gist.github.com/johanmeiring/3002458 )

执行上面的命令后,会在 ~/.gitconfig看到:

[alias]
	lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an %ae>%Creset' --abbrev-commit

这其中的占位符的解释:

  • %Cred:将颜色设置为红色
  • %Creset:重置颜色
  • %C(yellow):将颜色设置为黄色
  • %h:缩略的提交哈希值
  • %d:ref names(不知道该怎么解释😆)
  • %s:提交时的message
  • %cr:相对的提交时间。可以换成%ci,展示的是年月日时分秒。
  • %an:提交人的name
  • %ae:提交人的邮箱

更多占位符,可以参考官方文档:https://git-scm.com/docs/pretty-formats


( 本文完 )