Partial clone with Git and Mercurial

Is it possible to clone only one branch (or from a given commit) in Git and Mercurial? I mean, I want to clone the central repo, but since it is huge, I would only like to get part of it and still contribute to my changes. Is it possible? For example, I want only from Tag 130 or something like that?

If so, how?

+66
git mercurial
Apr 6 '10 at 17:15
source share
6 answers

In the Git area, you are talking about three different types of partial clones:

  • shallow clones: I want the story from revision point X to continue.

    Use git clone --depth <n> <url> , but remember that small clones are somewhat limited in interaction with other repositories. You will be able to create patches and send them by email.

  • partial clone along the file path: I want the entire history of the change history in some directory /path .

    Impossible in Git. With modern Git, although you may have a rare check, i.e. You have a whole story, but you only check (have in the workspace) a subset of all the files.

  • cloning only the selected branch: I want to clone only one branch (or a selected subset of branches).

    Maybe and

    Before Git 1.7.10 itโ€™s not easy: you will need to do what the clone does, i.e. git init [<directory>] , then git remote add origin <url> , edit .git/config replacing * in remote.origin.fetch with the requested branch (possibly 'master'), then git fetch .

    from Git 1.7.10, git clone offers --single-branch , which seems to have been added just for this purpose, and seems pretty straightforward.

    Note that since branches usually share most of their story, the benefit of cloning only a subset of branches may be less than you think.

You can also make a shallow clone of only a selected subset of branches.

If you know how people want to split things along the file path (multiple projects in the same repository), you can use submodules (like svn: externals) to pre-split the repo into separate cloned parts.

+67
Apr 6 '10 at 18:16
source share

In mercury earth, you are talking about three different types of partial clones:

  • shallow clones: I want the story from revision point X to use the remote file extension
  • partial clones on the path to the file: I want the entire history of changes in the directory / path to be experimental narrow extension or I want the files in the directory / path to be in my working directory with the experimental sparse extension (ships with version 4.3, see hg help sparse ).
  • partial clones on a branch: I want the entire change history on branch Y: use clone -r

If you know how people want to break things along the file path (multiple projects in the same repo (shame on you)), you can use subrepositories (like svn externals) to pre-split the repo into separate cloned parts

In addition, with regard to โ€œso huge that I would only like to get part of itโ€: you really need to do this only once. Just clone it while you have lunch, and then you have it even more. Subsequently, you can pull and effectively delta effectively move forward. And if you need another clone, just clone your first clone. Where you received the clone does not matter (and local clones do not take up additional disk space, since they are hard links under covers).

+41
Apr 6 '10 at 17:55
source share

This method creates an unversioned archive with no subitems:

 hg clone -U ssh://machine//directory/path/to/repo/project projecttemp cd projecttemp hg archive -r tip ../project-no-subrepos 

Unversified source code without subsequence is in the project-no-subrepos directory

+5
Feb 29 '12 at 19:21
source share

The selected answer gives a good overview, but there is no complete example.

Minimize load and control (a) , (b) :

 git clone --no-checkout --depth 1 --single-branch --branch (name) (repo) (folder) cd (folder) git config core.sparseCheckout true echo "target/path/1" >>.git/info/sparse-checkout echo "target/path/2" >>.git/info/sparse-checkout git checkout 

Optimize your local repository (c) periodically (optional, use with caution):

 git clean --dry-run # consider and tweak results then switch to --force git gc git repack -Ad git prune 

See also: How to handle large repositories using git

+5
Feb 06 '16 at 0:48
source share

As for Git, it may have historical significance that Linus Torvalds answered this question from a conceptual perspective back in 2007 in a conversation that was recorded and made available on the Internet.

The question is whether it is possible to check only some files from the Git repository.

Tech Talk: Linus Torvalds on Git t = 43: 10

Summing up, he said that one of Git's design decisions that distinguishes it from other version control systems (he quotes BitKeeper and SVN) is that Git manages content, not files. The consequences are that, for example, diff of a subset of files in two versions is computed by first taking the whole diff and then trimming it only to the files that were requested. Another thing is that you need to check the whole story; in all or nothing. For this reason, he suggests dividing loosely coupled components between several repositories and mentioning the ongoing attempt to implement a user interface for managing the repository, which is structured as a superproject with smaller repositories.

As far as I know, this fundamental design decision is still apples today. The super-design thing has probably become what submodules are now.

+2
Jan 04 '14 at
source share

In mercurial, you should be able to use some of them like this, using:

 hg convert --banchmap FILE SOURCEDEST REVMAP 

You also can:

 --config convert.hg.startrev=REV 

The source can be git, mercury, or many other systems.

I have not tried, but the converter is quite rich.

-one
Feb 21 '12 at 17:09
source share



All Articles