Monday, November 12, 2012

Clone at revision - Git and Mercurial

This is possible in both Git and Mercurial, although one seems a bit more involved.

Git - clone THEN reset or checkout:



( full clone then: git reset --hard 754bda21cbc5c9044daf7f968fb9b4ffae39e334 )

Mercurial - just do it:



( hg clone -r 34dea6ddb0b927dc223c8cdbab4314a3aac355a7 https://bitbucket.org/wrightsolutions/local-bin )

In the screenshot above, I have cloned as described, and then removed the repo and done a full clone.
By doing this I hoped to illustrate the key difference in changeset counts:
  • 'clone at revision' gave 77 changesets with 99 changes to 83 files
  • full clone gave 79 changesets with 101 changes to 84 files
That should satisfy you that the 'clone at revision' really does what it suggests.


Next I give a signature style explanation of the 'clone at revision' command

hg clone -r <sha1> source_repo

Notes and Further Reading:

But, but, but with Git you can just create an empty git and then

git remote add origin https://github.com/jquery/jquery.git
git fetch origin 754bda21cbc5c9044daf7f968fb9b4ffae39e334

Try it and you might just see the Git complaint...
  'fatal: reference is not a tree: 754bda21cbc5c9044daf7f968fb9b4ffae39e334'

Another nicety of Mercurial is that you can use shortened references (just the first 7 characters) and in most cases that will get you what you want.

Seven character abbreviation example:
  hg clone -r 34dea6d https://bitbucket.org/wrightsolutions/local-bin
( rather than the full 40 character reference used in the example above )

Note: Where you have a huge repository like say sagemath which has 100 active committers, then you might want to use the full 40 character reference to be sure of requesting the right revision



There is an excellent Mercurial Hints and Tips page at OpenOffice.org

See hg.sagemath.org for current Sagemath repository.
Most contributions are currently handled by registered lists I think, but if you have taken the time to really understand the code, then there is place for pull requests also.