Launching the TortoiseHg log more conveniently from the command line

When working with Mercurial I usually perform most tasks from the command line but often I want to be able to visually explore the history of the whole repository or of a single file.  For this I find TortoiseHg’s repository explorer very useful.


It is easy to launch it from the command line by executing the “hgtk log” command. The annoying thing about this command is that you must specify the full path of a file to see it’s history.  I am lazy and don’t want to type the following in to see the history of a file

htgk log .\website\content\css\myfile.css

To make this quicker I wrote a PowerShell function called hlog. Just place the following function in your PowerShell profile:

function hlog ($file) {
  if (-not $file) {
    hgtk log
  elseif(Test-Path -LiteralPath $file -ErrorAction SilentlyContinue) {
    hgtk log $file
  else {
    $path = Split-Path $file
    $leaf = Split-Path $file -Leaf
    Get-ChildItem $path -include $leaf -recurse | Where-Object { hgtk log $_.FullName }

With this you have much greater flexibility in how you launch the visual log.  You can…

Launch for the whole repository


Launch it using a full file path

hlog .\website\content\css\myfile.css

Launch it with just the file name
(This will launch the log for every file with the name “myfile.css” in your source tree)

hlog myfile.css

Launch for files matching wild cards
(This will match all css files two directories deep that start with the word my)

hlog *\*\my*.css

This entry was posted in Mercurial, PowerShell. Bookmark the permalink.

5 Responses to Launching the TortoiseHg log more conveniently from the command line

  1. Pingback: Launching the TortoiseHg log more conveniently from the command line - Matt Manela's Blog - Site Home - MSDN Blogs

  2. tobi says:

    I recommend using the ui for this task. What could be quicker than right clicking the file and choosing the right option?

  3. Thomas G Mayfield says:

    Same script with improvements for color and upstream/downstream divergence (but running no more commands than the old one):

    • Thomas G Mayfield says:

      Note, I didn’t improve on any of the hg code. That I left alone, as it wasn’t what had my attention.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>