tags:

views:

117

answers:

2

Is it possible to clone only one branch (or from a given commit) in Git and Mercurial? I mean, I want to clone a central repo but since it's huge I'd like to only get part of it and still be able to contribute back my changes. Is it possible? Like, I only want from Tag 130 onwards or something like that?

If so, how?

Thanks!

+4  A: 

In mercurial land you're talking about three different types of partial clones:

  • shallow clones: I want from revision point X onward not possible
  • partial clones by filepath: I want all revision history in directory /path not possible
  • partial clones by branch: I want all revision history on brancch Y: use clone -r

If you know how people will want to break things down by filepath (multiple projects in the same repo (shame on you)) you can use subrepositories (sort of like svn externals) tto pre-split the repo into separately cloneable portions

Also, as to the "so huge I'd like to only get a part of it": You really only have to do that one time ever. Just clone it while you have lunch, and then you have it forever more. Subsequently you can pull and get deltas efficiently going forward. And if you want another clone of it, just clone your first clone. Where you got a clone doesn't matter (and local clones take up no additional diskspace since they're hard links under the covers).

Ry4an
also tags aren't the same as branches unlike in some VCS so this comes under the first point
jk
+4  A: 
Jakub Narębski
So, if I clone branch "XX" it will get all the parent commits from "master", right? Or only the single commit I've done on that branch?
pablo
If you clone (fetch) only branch "XX", you would get all its commits, including those commits that branch "XX" has in common with "master" branch. In Git commits do not '*belong*' to a branch.
Jakub Narębski
Ok, then it's not a partial clone anyway since you get all the parents and hence the entire repos (ok, the biggest part which is on master)
pablo