自定义日志格式在输出结束时省略换行符 [英] Custom log format omits newline at end of output

查看:137
本文介绍了自定义日志格式在输出结束时省略换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 gitimmersion.com 上关注git教程,并设置别名 hist 来显示自定义的漂亮日志输出。



当我禁用git的寻呼机(将GIT_PAGER设置为空或设置为 cat )时,输出会忽略



以下是我看到的内容:

  work / lab_10 $ git hist 
* 88976c6 2011-01-19 |添加了评论(HEAD,v1,master)[Jim Weirich]
* b819ef8 2011-01-19 |添加了默认值(v1-beta)[Jim Weirich]
* ff07fc9 2011-01-19 |使用ARGV [Jim Weirich]
* b73dc5c 2011-01-19 |第一次提交[Jim Weirich] work / lab_10

请注意,在最后一个字符后出现shell提示符

为了进行比较,下面是我在使用标准漂亮格式时看到的内容:

  work / lab_10 $ git log --pretty = oneline 
88976c644e65afa697b58fc940eb8f94c47f8129添加评论
b819ef832effdaea8c0e33b1fea36ea4071c61b9添加了默认值
ff07fc93d3e2e5522e5607c9952cbad10cfa1144使用ARGV
b73dc5c1579756f4e9a4f91a90384c47288023b0第一次提交
work / lab_10 $

在这种情况下,换行符之前的换行符提示符出现。



以下是别名的定义:

  [别名] 
hist = log --pretty = format:\%h%ad |%s%d [%an] \--graph --date = short

有没有办法告诉 git log 包含最后的换行符,米不使用寻呼机

解决方案

> hist = log --pretty =tformat:\%h%ad | %s%d [%an] \--graph - date = short

format 在提交之间放置换行符 tformat 放置换行符之后提交,也就是在最后一个之后。

请参阅 git -log(1)了解详情。


I'm following the git tutorial at gitimmersion.com and set up an alias hist to show a custom pretty log output.

When I disable git's pager (setting GIT_PAGER to nothing or to cat), the output omits the newline at the end.

Here's what I see:

work/lab_10$ git hist
* 88976c6 2011-01-19 | Added a comment (HEAD, v1, master) [Jim Weirich]
* b819ef8 2011-01-19 | Added a default value (v1-beta) [Jim Weirich]
* ff07fc9 2011-01-19 | Using ARGV [Jim Weirich]
* b73dc5c 2011-01-19 | First Commit [Jim Weirich]work/lab_10$

Notice that the shell prompt shows up after the last character of printable output, with no newline.

To compare, here's what I see when using a standard pretty format:

work/lab_10$ git log --pretty=oneline
88976c644e65afa697b58fc940eb8f94c47f8129 Added a comment
b819ef832effdaea8c0e33b1fea36ea4071c61b9 Added a default value
ff07fc93d3e2e5522e5607c9952cbad10cfa1144 Using ARGV
b73dc5c1579756f4e9a4f91a90384c47288023b0 First Commit
work/lab_10$ 

In this case, the newline prior to the next prompt appears.

Here's the definition of the alias:

[alias]
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

Is there a way to tell git log to include the final newline when I'm not using a pager?

解决方案

Try

hist = log --pretty="tformat:\"%h %ad | %s%d [%an]\"" --graph --date=short

format places newlines between commits, tformat places newlines after each commit, thus also after the last one.

See git-log(1) for details.

这篇关于自定义日志格式在输出结束时省略换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆