Pretty git log in one line

Mattias Geniar, Tuesday, August 25, 2015 - last modified: Wednesday, August 26, 2015

If you type git log to see the commit history in a git repository, the standard output isn't very terminal-friendly. It's a lot of text, with very little information displayed on your screen. You can, however, change the output of your git log to be more condensed and show more output on the same screen size.

By default, a git log looks like this.

$ git log

commit 3396763626316124388f76be662bd941df591118
Author: Mattias Geniar 
Date:   Fri Aug 21 09:16:26 2015 +0200

    Add twitter link

commit c73bbc98b5f55e5a4dbfee8e0297e4e1652a0687
Author: Mattias Geniar 
Date:   Wed Aug 19 09:19:37 2015 +0200

    add facebook link

Each commit, with the date and author + the commit message. But boy, it takes up a lot of screen space.

A simple fix is to pass the --pretty=oneline parameter, which makes it all fit on a single line.

$ git log --pretty=oneline

3396763626316124388f76be662bd941df591118 Add twitter link
c73bbc98b5f55e5a4dbfee8e0297e4e1652a0687 add facebook link

It's taking up less space, but missing crucial information like the date of the commit.

There are longer versions of that same --pretty parameter. In fact, it allows you to specify all the fields you want in the output.

$ git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

* 3396763 - (HEAD, origin/master, master) Add twitter link (4 days ago) 
* c73bbc9 - add facebook link (6 days ago) 
* cb555df - More random values (6 days ago) 
*   60e7bbf - Merge pull request #1 from TSchuermans/patch-1 (7 days ago) 
| * 8044a8f - Typo fix (7 days ago) 

The output is indented to show branch-points and merges. In colour, it looks like this.


To make life easier, you can can add a git alias so you don't have to remember the entire syntax.

$ git config --global alias.logline "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
$ git logline

More data on the same screen real estate!

Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek & public speaker. Currently working on DNS Spy & Oh Dear!. Follow me on Twitter as @mattiasgeniar.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!


Šime Vidas Wednesday, August 26, 2015 at 07:52 - Reply

A quick note for Windows users: The Command Prompt does not understand this git command, but PowerShell does ( ).

CaptainQuirk Wednesday, August 26, 2015 at 10:03 - Reply

I’ve been using a similar alias for quite some time now and I’m experiencing performance issues on large projects. Am I the only one ?

Godwin Wednesday, August 26, 2015 at 16:19 - Reply

Typo: `–pretty=online` should be `–pretty=oneline`

Tom Thursday, August 27, 2015 at 08:31 - Reply

I’ve been using tig for this purpose. Even more functionality as you can open commit details as well.

Kevin Scott Tuesday, January 29, 2019 at 19:28 - Reply

3 years later, still very helpful!

Bonnie S Friday, July 12, 2019 at 23:10 - Reply

Thanks, still awesome! I just google gitlogpretty whenever I need to redo this alias and there you are!

Leave a Reply

Your email address will not be published. Required fields are marked *