Custom One-Line Log Output for Git and Mercurial

Published · Updated · Programming

The default history view in Git and Mercurial is optimized for completeness, not scanning. A compact one-line log is a better daily tool: short ID, subject, relative date, author, and branch or bookmark context. It does not replace a full graph; it makes the first pass fast enough that you inspect history before changing it.

A useful Git lg alias

Add this to ~/.gitconfig:

[alias]
    lg = log --graph --decorate --abbrev-commit --date=relative --pretty=format:'%C(auto)%h%Creset %C(auto)%d%Creset %s %Cgreen(%cr)%Creset %Cblue<%an>%Creset'

Then run:

git lg
git lg --all

--graph matters when more than one branch is involved; --decorate puts branch and tag names where they matter. If color escapes become unreadable in a terminal or CI log, remove them before debugging the theme. Keep a simpler machine-friendly alias for scripts:

[alias]
    lgn = log --oneline --decorate

Do not make automation depend on human-oriented columns or terminal color.

A Mercurial template for the same job

Mercurial templates make custom formatting explicit. Put a small template in your configuration and reference it from an alias:

[templates]
lg = "{node|short} {if(bookmarks, '({bookmarks}) ')}{desc|firstline} ({date|age}) <{author|user}>\\n"

[alias]
lg = log --template lg

Run it with hg lg or hg lg -l 20. Bookmarks appear when present, which is usually more useful in daily work than a wall of metadata. Add labels and color only after confirming the template works in the Mercurial version deployed on your machines; copied color configuration ages badly.

Keep the alias honest

A log alias is a navigation aid, not a safety check. Before rewriting history or deleting a branch, use the full graph and inspect the upstream relationship. Rebase versus merge covers the collaboration tradeoff. For Mercurial users who want a familiar inspection command, the git show equivalent pairs changeset metadata with the diff.

The best configuration is the one you can still understand six months later. Start with a short, portable line and add graph or color detail only when it makes a real decision easier.

More practical engineering notes

Slaptijack's Koding Kraken