How can I remove the working copy from a Mercurial clone?
Asked Answered
D

2

62

When cloning a repository with mercurial you can pass the -U/--noupdate flag to create a clone with no working copy. Can I remove the working copy if I forget to pass this flag at clone time? And if so, how?

This is conceptually similar to this git question, but for mercurial.

Dogeared answered 11/11, 2010 at 20:0 Comment(0)
T
95

Documentation at Mercurial wiki says following about bare repositories:

"Although this is a minor issue, Mercurial can obviously handle a bare repository; that is, a repository without a working copy. In Git you need a configuration option for that, whereas in Hg you only need to check out the null revision, like this:"

hg update null

The null revision is similar to the empty state you have when you have just done hg init. It is the parent of revision 0 (and the second parent of all non-merge revisions) and by updating back to it you again get an empty working copy.

The link may look ironic:

Tick answered 11/11, 2010 at 20:21 Comment(4)
Aha! That does the trick. RTFM. Or in this case RTFW. I had read "hg clone --help", which does hint at this solution... but only if you know the answer. Thanks!Dogeared
@rq: It happens to all of us. I have a number of moments of RTFM every week.Tick
If there are files still left over, hg purge may help to get rid of them.Latinism
From TortoiseHg Workbench, you can accomplish this via Repository > Update and specifying null as the Update to:Turnip
R
-24
rm -rf *

This removes all "visible" files (under *nix). Since the Mercurial repository is stored in the "hidden" file .hg, it won't be touched. Unfortunately, neither will any hidden files of your own, such as .hgignore.

To restore the working copy, I'm sure there's an hg update flag that works, but this will as well:

hg revert --all
Rubbish answered 11/11, 2010 at 20:26 Comment(4)
-1 Totally not right. This is what I tried, and marks the whole working copy as "!" deleted, which can mess up pushes and pulls.Dogeared
@rq - perhaps you should have said that in your original question. Personally, I have no idea why you'd want to copy a repository without a working directory. Running a lot of pushes and pulls without attempting to build in-between is a recipe for trouble.Rubbish
one use is to create a backup copy of a local clone on a network drive, using a commit hook that automatically pushes to the backup.Covey
There's absolutely no reason to have a local working copy when, for instance, serving a mercurial repository from a web-server.Fodder

© 2022 - 2024 — McMap. All rights reserved.