I have a single-person single-folder mercurial repository. The directory structure is simple:
P104
lecture_notes
files under version control live here
After a while I realize I want to have two directories within the repository, like this
P104
lecture_notes
files under version control live here (.hg is here)
homework
more files under version control
Now, if I'm just trying to add files to the repository, it fails:
br@ymir:~/P104/lecture_notes$ ll ..
total 16
drwxr-xr-x 4 br br 4096 2012-02-02 18:05 ./
drwxr-xr-x 4 br br 4096 2012-02-01 20:46 ../
drwxr-xr-x 2 br br 4096 2012-02-02 17:44 homework/
drwxr-xr-x 4 br br 4096 2012-02-02 18:06 lecture_notes/
br@ymir:~/P104/lecture_notes$ hg add ../homework/hw1_P104.tex
abort: ../homework/hw1_P104.tex not under root
My first idea was to clone the repo one level up in the directory structure, add files to the clone, and delete the original repo. But even cloning fails:
br@ymir:~/P104/2011/lecture_notes$ hg clone . ..
abort: destination '..' is not empty
So the question is whether there's a Mercurial-ish way of doing this other than creating a clean repository somewhere else and copying files manually?
I like VonC's solution where you don't move the
.hg
folder. It's a straight forward solution. Here is an alternative where you do move it and so have to rename fewer folders:Move the
.hg
folder up to~/P104
Seen from the perspective of Mercurial, you will have moved all the top-level files into a
lecture_notes
directory. There will also suddenly be new untracked files in thehomework
folder.Let Mercurial figure out the renames:
This will correctly detect that files that were top-level files before now live in the
lecture_notes
directory. The untracked (and un-ignored) files inhomework
are just added.Save the changes:
The overall "trick" is that files in the working copy are seen relative to the
.hg
directory. So by moving the.hg
directory up in the file system hierarchy, we effectively move the working copy files down in the hierarchy inside the working copy.If the root directory of your Mercurial repo is under
~/P104/lecture_notes
, I would rather:lecture_notes
into P104lecture_notes
homework
and its files in the renamed P104 directoryhg add
everythingThe idea is to keep the
.hg
repo where it is (~/P104/lecture_notes
renamed into~/P104/P104
) and reorganize the files within that renamed directory.No need to clone.