I use git log
a lot. It’s real handy. But you know what — it’s pretty unwieldy and takes up quite a bit of terminal real estate. I finally decided to do something about it. Every time I ran git log
, my terminal becomes a total mess. I knew about this little dingle:
git log --pretty=oneline --abbrev-commit
Which prints out a friendly, easy-to-digest, single-lined log:
a2a722b (HEAD -> master, origin/master) Fix the NoteDetail styles.
4fdcbc7 Split the NoteCell and NoteDetail.
ccc4dc2 Connected the NoteCell with data.
bce0d12 Broken components into separate pieces.
071ea13 Change destinations, now the targeting works.
0ecea01 NoteDetail and split it from the RootView.
...
Which is great! But… can we do better? Some googling around lead me to this post by Mattias Geniar:
There are longer versions of that same
--pretty
parameter. In fact, it allows you to specify all the fields you want in the output.
Sweet! So, running the same command and flagging the specified fields like so, prints a more concise log. Awesome!
$ git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
a2a722b (HEAD -> master, origin/master) Fix the NoteDetail styles. (2 days ago) <Stephen Petrey>
4fdcbc7 Split the NoteCell and NoteDetail. (2 days ago) <Stephen Petrey>
ccc4dc2 Connected the NoteCell with data. (2 days ago) <Stephen Petrey>
bce0d12 Broken components into separate pieces. (4 days ago) <Stephen Petrey>
071ea13 Change destinations, now the targeting works. (5 days ago) <Stephen Petrey>
0ecea01 NoteDetail and split it from the RootView. (6 days ago) <Stephen Petrey>
...
Mattias has the excellent suggestion of configuring a Git Alias for this:
$ 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"
Now, instead of having to type out the command and flag the fields you want to print, you can just type, git logline
and wham! It should print out a prettified git log that takes up way less space in your terminal.