How can i check out only a sub directory from mercurial repository? It seems i can only check out the whole repository.
-
You should be careful about exactly what constitutes a repository. – Omnifarious Jan 22 '10 at 03:35
4 Answers
No, you cannot. See the discussion here:

- 127,765
- 105
- 273
- 257

- 10,943
- 6
- 36
- 28
-
1
-
Hopefully! But considering how hg and git both store the repository history, it's unlikely to happen soon. – clee Jan 22 '10 at 03:37
-
1ACtually, from what I know of how Mercurial does it vs. git, it should be easier to implement in Mercurial. Though all the ways I know of will still result in manifest files that are a lot bigger than they strictly need to be. – Omnifarious Jan 22 '10 at 03:40
You can't do it. The feature is planned, but not implemented. The previous person gave a nice link to where you can read a discussion about the partial clone feature.
For now, you should just be really careful to divide things up so a repository is a fairly small unit that makes logical sense to manage in one piece. The existence of the ability to have subrepos might help you organize and manage things until that feature exists.

- 127,765
- 105
- 273
- 257

- 54,333
- 19
- 131
- 194
The next best thing is using the Convert extension as discussed here: https://www.mercurial-scm.org/wiki/ConvertExtension
It's also useful to filter Mercurial repositories to get subsets of an existing one. For example to transform a subdirectory subfoo of a repository foo into a repository with its own life (while keeping its full history), do the following:
echo include subfoo > /tmp/myfilemap
echo rename subfoo . >> /tmp/myfilemap
hg convert --filemap /tmp/myfilemap /path/to/repo/foo /tmp/mysubfoo-repo

- 127,765
- 105
- 273
- 257

- 8,521
- 5
- 40
- 64
This is the same question as How do I clone a sub-folder of a repository in Mercurial? so the answers there and here are going to be same. I'll summarize them:
- "It's not possible".
- "Convert the original repository to only contain the directory you're interested in" (but it will no longer be possible to push changes from it into the original repository).
- "Convert your main repository into several repositories (using the above) and use Mercurial's subrepository feature to make them act like one" (having to use subrepsitories is considered a Mercurial feature of last resort though).
- "Clone the whole repo but do a narrow checkout of only a directory" (needs Facebook's
sparse.py
third-party extension installed). - "Clone only the history (and by extension the contents) of a specified directory" (needs Google's third-party NarrowHG extension on the client and server).
Terminology notwithstanding (the original question was asking about only "check out" which can only happen after cloning in Mercurial but Subversion doesn't really have the concept of cloning) the NarrowHG solution is arguably the closest to what was desired.