Usage of hg commit –date (mercurial)

Recently, I was trying to move some stuff from RCS to mercurial. There does not seem to exist a converter and since it was only a few revisions, I decided to do it by hand. The problem arose how to set the commit date manually and google yielded a nice blog post that answered my question (refering to the formidable but less searchable hgbook).

So its basically:

hg commit --date "1234567890 0"

where 1234567890 is the seconds since epoch and 0 is the timezone. Unfortunally I was unable to comment on the above blog posting, which triggered this posting.
On unix (and bash) you can conveniently use the date command to do the conversion:

hg commit --date "$(date -u --date '2009-2-13 23:31:30' +'%s') 0"

The date command also solves the original posters question:

Actually, I regret that it isn’t possible to define a file that mercurial will use as date reference, something like hg commit -d date filexy.ext -m “commit with autodate from file xy” would be handy. This way, getting the filesystem metadata into a repository representation would be easier, but this might be a too specific request for a standard versioning system…

Just use:

hg commit -d "$(date -u -r filexy.ext +'%s') 0" -m “commit with autodate from file xy”
Share and Enjoy:
  • description
  • Reddit
  • Digg
  • Google
  • MisterWong
  • TwitThis


  1. Henryk says:
    hg help commit

    refers to

    hg help dates

    where we find

        Many date formats are valid. Here are some examples:
        "Wed Dec 6 13:18:29 2006" (local timezone assumed)
        "Dec 6 13:18 -0600" (year assumed, time offset provided)
        "Dec 6 13:18 UTC" (UTC and GMT are aliases for +0000)
        "Dec 6" (midnight)
        "13:18" (today assumed)
        "3:39" (3:39AM assumed)
        "3:39pm" (15:39)
        "2006-12-06 13:18:29" (ISO 8601 format)
        "2006-12-6 13:18"
        "12/6/6" (Dec 6 2006)
  2. [...] stat <file> –format=%Y does by prepending an echo. After I solved this here, I found this blog post that achieves the same by using the date [...]

  3. pards says:

    This can also be done via options dialog in TortoiseHG. In the commit pane, click on the 'options' button (it looks like a label, just above the comment box, check the "Set Date" box and enter the date you want to use.

Leave a Reply