Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

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.


Monday, May 16, 2011

mercurial init - git init - summary clone and push

hg init            or      git init

...are generally the first commands I use.


Have your code ready and a reasonable directory structure in place.

Add a README and a LICENSE file (OSI approved licenses in my case)

hg init

...and you are up and running (for your git stuff   git init)

If you are working from an existing codebase then you might want 'clone'

hg clone http://hg.savannah.nongnu.org/hgweb/someproject


Publishing one time projects via git lends itself well to a set recipe:

  1. git init
  2. git add .
  3. git commit -m 'first commit of GPL3 licensed python scripts'
  4. git remote add origin git@github.com:someuser/apt-utils-python-shell.git
  5. git push -u origin master
          [ Above we used -u switch (--set-upstream) which is correct ]
  6. git add README
  7. git commit -m 'added some to README'
  8. git push origin master
          [ Note there is no -u switch here which is correct ]

Openshift and git - what commands there?

In order to commit to your new project, ...

Make your changes, then run:

git commit -a -m 'Some commit message'
git push

Then reload this page

Note: The above is quoted from the openshift page


Notes and further reading:

If you feel the desire to host your own Mercurial from which other folks can pull, then:


hg serve 

and the point browser at http://localhost:8000/


Note: If your machine is internet facing rather than on a private company network, then you should think about authentication / security, and follow this guide:
  Setting up a Mercurial CGI server

Alternatively you could think about Trac



If you feel the desire to host your own Git from which other folks can pull, then:

git-daemon 

and the point browser at http://localhost:9418/

Note: If your machine is internet facing rather than on a private company network, then you should think about authentication / security, and read up about gitosis or gitweb.