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 <m@ttias.be> Date: Fri Aug 21 09:16:26 2015 +0200 Add twitter link commit c73bbc98b5f55e5a4dbfee8e0297e4e1652a0687 Author: Mattias Geniar <m@ttias.be> 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) <Mattias Geniar> * c73bbc9 - add facebook link (6 days ago) <Mattias Geniar> * cb555df - More random values (6 days ago) <Mattias Geniar> * 60e7bbf - Merge pull request #1 from TSchuermans/patch-1 (7 days ago) <Mattias Geniar> |\ | * 8044a8f - Typo fix (7 days ago) <Tom Schuermans> |/
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!