Tech Chorus

Mercurial - How To View A File Exactly Like It Appeared On A Particular Date

written by Sudheer Satyanarayana on 2012-03-19

Here's a quick tip for Mercurial users.

Travel back in time and see how the file appeared. :)

hg cat --rev "date('2011-05-03')" controllers/

Let's break it down.

hg cat is the command we use to print the given revision of file.

hg cat --rev 10885:ae28ee103fed controller/

would print the file for the revision 0885:ae28ee103fed.

Mercurial supports a functional language for selecting a set of revisions. To know more about it try:

hg help revsets

In our solution:

hg cat --rev "date('2011-05-03')" controllers/

"date('2011-05-03')" is the revset we used in cat. Notice that the revset has to be quoted. The date spec also requires quoting. Hence, a pair of single and double quotes.

To see what kind of date formats Mercurial supports run:

hg help dates