Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clone an hg directory from a particular date

Tags:

mercurial

Is there a way to get a copy of a hg repository as it was at a particular date?

For example, in subversion I would use:

svn checkout -r {2012-04-04} ...

And it would check out a revision as it appeared on the fourth of April.

In git its a little more complicated, but can be done:

git checkout `git rev-list -n 1 --before="2012-04-04" master`

Can you do the same thing in hg?

like image 575
kimon Avatar asked May 11 '12 05:05

kimon


1 Answers

(EDIT: My love of revsets has caused me to overlook the obvious answer: hg update --date 2012-04-04 should get you the tipmost revision as of that date.)

If you have the whole repository cloned already (date specifications don't seem to work with clone), you can do

hg update --rev "date('< 2012-04-04')"

If there's a possibility that the repository had multiple heads/branches at the date you want, you'll have to AND in some more conditions to narrow it down to the right changeset:

hg update --rev "date('< 2012-04-04') and branch(v1.1)"

Check out hg help revsets and hg help dates for more information.

Later, if you want to go back to the tip, just

hg update
like image 52
anton.burger Avatar answered Sep 30 '22 06:09

anton.burger