Pretty HG Log Style
Tags: programming.hg, programming.mercurial, programming.git, programming.terminal, programming.log-style
There’s a somewhat famous styled git log I have in my config. The guy I grabbed it from said it was from scm-breeze, I think maybe he meant tiimgreen’s github-cheat-sheet. In any case, The Git one is like:
alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"Consulting the docs, (who does that, right?), it’s not insane to figure out what this is doing:
%h- abbrev commit hash%d- ref names (like(origin/master))%s- subject (first line of commit)%cr- committer date, relative.%an- author name.
Great.
But I’ve been using HG. Can Mercurial haz it, too?
Sources:
S/O: “Mercurial Log with One-Liners” Because one-liner logs themselves can be useful.
This one has:alias hl="hg log --template '{node|short} | {date|isodatesec} | {author|user}: {desc|strip|firstline}\n'"
This helps us get a plain one-liner
I’m trying for “direct equivalence”. YMMV, since Git/HG don’t exactly share all
concepts. (e.g. every commit in HG has the notion of a ‘branch’, etc.).
So, note that when building the template, this is the stuff to put within the
{}:
node|short- commit hashrev- int, revision number.branches/branch- branchname.desc|strip|firstline- ‘subject’date|age- human-readable difference in time.author|person- Richard from Richard richard.goulter@gmail.com
So, my .hgrc has:
[color]
custom.rev = red
custom.decorate = yellow
custom.date = green
custom.author = blue boldWith the hg alias: alias hl="hg log --style ~/.hgrc.d/fancy.style". (Or do
this from your shell, whatever).
And, finally, ~/.hgrc.d/fancy.style is:
changeset = "* {label('custom.rev', node|short)} - ({label('custom.decorate', branch)}) {desc|strip|firstline} ({label('custom.date', date|age)}) <{label('custom.author' , author)}>\n"Screenshot:

(The repo is old, because I don’t use HG so much, okay?).