Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

git - Custom log format omits newline at end of output

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...