{git, hg} Custom Log Output

by Scott Hebert

Mercurial logo -rightThe standard log output for both Git and Mercurial is a bit verbose for my liking. I keep my terminal at ~50 lines, which results in only getting about 8 to 10 log entries depending on how verbose the commit was. This isn't a big deal if you are just interested in the last few commits. Anything more than that and it becomes annoying. So, I use a custom log alias ({git,hg} lg) to give me a short one-liner for each commit with the following format (please note there might be some word-wrap at play):

<commit> - <first line/short description> (relative date) <author>

I've been using this a long time, and unfortunately I don't remember where I got the idea, but here's a likely source.

There's a lot going on in this change. First, the template is set in the [templates] stanza. To get the colors, we've made use of the label() function. Not all the colors we're looking for are available or set, so we have to do that in the [color] stanza. FYI, the changeset.{phase} label colors are not set by default. Finally, adding lg to the [alias] stanza is necessary. Check here for more details on customizing Mercurial.

I use Git in my daily work, but prefer Mercurial for personal projects.

UPDATE: My current position uses Mercurial instead of Git. Because of this, I have made it a goal to improve my development habits. I talked about this briefly in my goals for 2016.

One of the new things I'm trying to do is use bookmarks in my daily work. Thus, I have updated my custom log template to show the bookmarks active on a particular revision ({if(bookmarks, label('list.bookmarks', '({bookmarks}) '))}).