Can I clone part of a Mercurial repository?
Is it possible to clone part of a Mercurial repository? Let's say the repository is quite large, or contains multiple projects, or multiple branches. Can I clone only part of the repository?
Eg in Subversion, you might have trunk
and branches
. If I only want to get trunk (or one of the branches) I can just request [project]/trunk
. If I clone the hg repo I'll get trunk and all of the branches. This might be a lot of information I don't want. Can I avoid getting this?
Alternatively, if I want to have multiple projects in one hg repo, how should I do this? Ie so that I might just get one of the projects and ignore the others.
Yes you can. I'm sure you've moved on, but for the sake of those who will wander here later, I followed the docs at ConvertExtension, and wrote a simple batch script:
@echo off
echo Converting %1
REM Create the file map
echo include %1 > ~myfilemap
echo rename %1 . >> ~myfilemap
REM Run the convert process
hg convert --filemap ~myfilemap . ..%1
REM Delete the file map
del ~myfilemap
cd ..%1
REM update the new repo--to create the files
hg update
Name it something like split.cmd
, and put it in the directory for the repo you want to split. Say for example you have C:reposReallyBigProject
, and a subfolder is C:reposReallyBigProjectsmall-project
. At the command prompt, run:
cdreposReallyBigProject
split.cmd small-project
This will create C:repossmall-project
with a slice of the relevant history of revisions from the larger project.
The convert
is not enabled by default. You'll need to make sure the following lines exist in your .hghgrc
file ( c:reposReallyBigProject.hghgrc
in my example):
[extensions]
hgext.convert=
@Nick
"Eg in Subversion, you might have trunk and branches. If I only want to get trunk (or one of the branches) I can just request [project]/trunk. If I clone the hg repo I'll get trunk and all of the branches. This might be a lot of information I don't want. Can I avoid getting this?"
Absolutely. Just use hg clone -r <branch>
and get only the branch you want. If you have lots of branches, you need a -r <branch>
for each one. <branch>
doesn't have to be a named branch: you can simply have multiple unnamed heads (or named heads using bookmark, though those still aren't perfect, because currently they don't show up with push/pull/clone).
Keep in mind that in DVCSes, Mercurial among them, branches are often short-lived and merged back into each other frequently. If you pull a branch you will still get the common history it has with any other branches.
To my knowledge, that's not possible. But compared to Subversrion, cloning the whole repos may not be slower than just a branch from SVN.
Quoting from UnderstandingMercurial:
Many SVN/CVS users expect to host related projects together in one repository. This is really not what hg was made for, so you should try a different way of working. This especially means, that you cannot check out only one directory of a repository.
If you absolutely need to host multiple projects in a kind of meta-repository though, you could try the Subrepositories feature that was introduced with Mercurial 1.3 or the older ForestExtension.
链接地址: http://www.djcxy.com/p/37536.html上一篇: Mercurial:分支版本?