5

I have a hg repo on my local drive. I am new to hg and want to know if i can move the folder around freely. I am not talking about a folder under version control, i am talking about the folder that contains the repo it self.

I've found a lot of similar questions but most seem to be talking about a folder under version control. another answer is to use hg clone but i want to know if i can just cut and paste the whole repo.

I am using windows xp if that matters.

3 Answers 3

6

Yes, you can copy the repository itself by just copying the .hg folder.

Imagine the following folder structure:

MyRepo
MyRepo\.hg
MyRepo\file_under_version_control.txt

MyRepo is the whole repository (or as you called it, "folder under version control").

When you remove the .hg folder from it, MyRepo is just a normal folder without version control.

When you move the .hg folder somewhere else, you can create a new working directory by running hg update, so the new folder where .hg resides will be a complete repository again.

3
  • i think he means copying the directory containing the .hg directory.
    – Dan D.
    Commented Jul 21, 2011 at 11:57
  • Yes, that's what I meant as well. I just edited my answer to clarify! Commented Jul 21, 2011 at 12:02
  • beware! As I have been finding out recently, the contents of the .hg directory seem version-specific. You can't safely transfer a repo from Mercural version X and have it recognized by version Y on another system. For some years, that was working for me, but it seems like not these days (or I was getting lucky). Instead, use hg bundle to transfer repos like that.
    – jwd
    Commented Nov 15, 2023 at 9:05
2

Technically you can, but you have two possibly unwanted outcomes if you do move your .hg folder:

  1. There source folder no longer has hg repository in it. It just becomes a plain directory with files.
  2. The destination folder suddenly has a (most likely) totally unrelated hg repository which you cannot really do anything meaningful with.

While the first outcome is no problem, the second likely is - unless the destination folder is just different working copy checked out from the same revision of your hg repository.

1

Yes, that is the whole idea behind DVSC (distributed version control systems), git also works in that way.

Not the answer you're looking for? Browse other questions tagged or ask your own question.