gitgit-log

How to suppress blank lines with git log pretty format?


I am trying to extend the git log --oneline format to show a little more information, specifically the committer and commit time.

The original command is git log --oneline --name-status and produces this output:

$ git log --oneline --name-status
809d815 (HEAD -> master) modified bar
M       bar.txt
352d6d3 modified foo
M       foo.txt
e4150f4 initial commit
A       bar.txt
A       baz.txt
A       foo.txt

I've duplicated this format with additional information as git log --oneline --name-status --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)' and it produces this output:

$ git log --oneline --name-status --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)'
809d815 (HEAD -> master) modified bar (Mike Harvey, 29 seconds ago)
M       bar.txt

352d6d3 modified foo (Mike Harvey, 49 seconds ago)
M       foo.txt

e4150f4 initial commit (Mike Harvey, 2 minutes ago)
A       bar.txt
A       baz.txt
A       foo.txt

What I want to do is suppress the blank lines between log entries, but cannot find an option to remove it, nor why it is being inserted. The only difference here is that I am using a pretty format.

UPDATE: It seems there is no workaround, so I adapted Kjele's solution. Piping the output loses the color info, which I really wanted, so I forced it with -c color.ui=always.

This is the final version that does what I wanted:

git log ${REV}..HEAD --oneline --name-status -c color.ui=always --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)' | sed '/^\s*$/d'


Solution

  • You could pipe your command into:

    sed '/^\s*$/d'
    
    git log --oneline --name-status --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)' |  sed '/^\s*$/d'
    

    but this will not allow you to scroll down like you normally would.

    A workaround could be to select the desired number of commits:

    -n 10
    
    git log --oneline --name-status --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)' -n 10 |  sed '/^\s*$/d'