Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom log format omits newline at end of output

Tags:

git

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?

like image 941
Doug Harris Avatar asked Jan 25 '12 17:01

Doug Harris


1 Answers

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.

like image 106
Mika Fischer Avatar answered Oct 11 '22 10:10

Mika Fischer