61

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.

Community
  • 1
  • 1
richq
  • 55,548
  • 20
  • 150
  • 144

2 Answers2

94

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:

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
pyfunc
  • 65,343
  • 15
  • 148
  • 136
  • 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! – richq Nov 11 '10 at 20:28
  • @rq: It happens to all of us. I have a number of moments of RTFM every week. – pyfunc Nov 11 '10 at 21:17
  • 2
    If there are files still left over, `hg purge` may help to get rid of them. – gbmhunter Aug 14 '15 at 03:48
  • From TortoiseHg Workbench, you can accomplish this via `Repository` > `Update` and specifying `null` as the `Update to:` – erdomke Apr 19 '16 at 19:37
-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
Anon
  • 2,654
  • 16
  • 10
  • 13
    -1 Totally not right. This is what I tried, and marks the whole working copy as "!" deleted, which can mess up pushes and pulls. – richq Nov 11 '10 at 20:31
  • @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. – Anon Nov 11 '10 at 21:10
  • 11
    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. – Niall C. Nov 11 '10 at 21:18
  • 3
    There's absolutely no reason to have a local working copy when, for instance, serving a mercurial repository from a web-server. – ebyrob Feb 14 '19 at 17:28