让Git的输出更友好: 多种颜色和自定义log格式
来源:互联网 发布:广电网络网格化意义 编辑:程序博客网 时间:2024/05/16 11:00
git多颜色输出
git默认的输出是单一颜色的,不仅不够美观,也不容易阅读。实际上,git本身就支持用多种颜色来显示其输出的信息,只需在命令行中运行以下命令来修改git的设置,即可开启多颜色输出:
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
执行以上命令后,git的status, diff和branch等诸命令的输出就都是带有颜色的了。见下图示例。
自定义log格式
完成上述步骤后,
git log
命令的输出虽然有了点颜色,但还是显得枯燥(见下图)。不要紧,强大的git提供了自定义log格式的功能,尝试输入以下命令:
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
你将看到类似下图的输出:
怎么样,不赖吧?不过,每次查看log都输出这么一长串的命令,实在是不太现实。咱们来通过git的命令别名来解决这个问题。输入以下命令:
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
上述命令将创建一个命令别名
lg
,每次你使用命令git lg
就相当于输入了刚才那一长串命令。现在,如果想看美观的多颜色输出,就使用git lg
,如果想看普通的log输出,就使用git log
,二者互不干扰。如果你想让log输出某些特定的信息,可以自己调整
--pretty
参数的值,例如下面的命令将只显示commit的hash,提交时间,提交者姓名:git log --pretty=format:'%h %ar %an'
把format后面单引号中的内容替换为你想要的格式,即可实现自定义的log输出格式。这里的
%Hcommit hash%hcommit的短hash%Ttree hash%ttree的短hash%Pparent hashes%pparent的短hashes%an作者名字%aNmailmap中对应的作者名字 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))%ae作者邮箱%aE作者邮箱 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))%ad日期 (–date= 制定的格式)%aD日期, RFC2822格式%ar日期, 相对格式(1 day ago)%at日期, UNIX timestamp%ai日期, ISO 8601 格式%cn提交者名字%cN提交者名字 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))%ce提交者 email%cE提交者 email (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))%cd提交日期 (–date= 制定的格式)%cD提交日期, RFC2822格式%cr提交日期, 相对格式(1 day ago)%ct提交日期, UNIX timestamp%ci提交日期, ISO 8601 格式%dref名称%eencoding%scommit信息标题%f过滤commit信息的标题使之可以作为文件名%bcommit信息内容%Ncommit notes%gDreflog selector, e.g., refs/stash@{1}%gdshortened reflog selector, e.g., stash@{1}%gsreflog subject%Cred切换到红色%Cgreen切换到绿色%Cblue切换到蓝色%Creset重设颜色%C(…)制定颜色, as described in color.branch.* config option%mleft, right or boundary mark%n换行%%a raw %%x00print a byte from a hex code%w([<w>[,<i1>[,<i2>]]])switch line wrapping, like the -w option of git-shortlog(1).%h
,%ar
等是一些git预定义的占位符,完整的列表如下:
0 0
- 让Git的输出更友好: 多种颜色和自定义log格式
- 让Git的输出更友好: 多种颜色和自定义log格式
- 让Git的输出结果带有颜色
- 自定义HtmlTextView,让textView显示多种颜色的文字
- 自定义AndroidStudio Locat的输出颜色与Log的级别
- 让log4j输出IDE友好的日志
- 【Git学习】git log自定义格式
- 让 git输出颜色变成彩色的方法
- 让 git输出颜色变成彩色的方法
- 多种颜色的RGB格式、代码格式
- 修正linux下ls输出的目录颜色,让putty用起来更舒服
- 使用 XML: 提供更友好的 RSS 和 Atom 提要
- 设置git bash打印log的颜色
- MapReduce多种输出格式
- 让Eclipse/MyEclipse的控制台和log4j日志支持多种颜色
- git log颜色配置
- git log 颜色调整
- 调整ViewState的位置,让你的asp.net页面对搜索引擎更友好
- XmlDocument操作xml文档
- vi命令
- Linux网络抓包工具——tcpdump
- 二叉树
- 进程与线程的区别
- 让Git的输出更友好: 多种颜色和自定义log格式
- ORACLE 体系结构(Architecture of ORACLE)
- 内存中堆和栈的区别
- 给同校大一IT新生的建议
- wpf中UserControl制作
- 钟周期、机器周期、指令周期的概念及三者之间的关系
- Heap-Sort
- 可以分列排序,隐藏的表格,异步加载 mootools
- UFLDL Tutorial_Sparse Autoencoder