更改 Mercurial 中的目录结构
我有一个单人单文件夹 Mercurial 存储库。目录结构很简单:
P104
lecture_notes
files under version control live here
过了一会儿,我意识到我想要在存储库中有两个目录,就像这样
P104
lecture_notes
files under version control live here (.hg is here)
homework
more files under version control
现在,如果我只是尝试将文件添加到存储库,它会失败:
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
我的第一个想法是克隆存储库升级目录结构,将文件添加到克隆,并删除原始存储库。但即使克隆也会失败:
br@ymir:~/P104/2011/lecture_notes$ hg clone . ..
abort: destination '..' is not empty
所以问题是,除了在其他地方创建一个干净的存储库并手动复制文件之外,是否有一种类似 Mercurial 的方法可以做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我喜欢 VonC 的解决方案,您无需移动
.hg
文件夹。这是一个简单的解决方案。这是一种替代方法,您确实移动它,因此必须重命名更少的文件夹:将
.hg
文件夹移至~/P104
<前><代码>$ mv ~/P104/lecture_notes/.hg ~/P104
从 Mercurial 的角度来看,您已将所有顶级文件移至
lecture_notes
目录中。homework
文件夹中也会突然出现新的未跟踪文件。让 Mercurial 确定重命名:
<前><代码>$ hg addremove
这将正确检测到之前属于顶级文件的文件现在位于
lecture_notes
目录中。刚刚添加了homework
中未跟踪(且未忽略)的文件。保存更改:
<前><代码>$ hg 提交
总体“技巧”是工作副本中的文件是相对于
.hg
目录查看的。因此,通过将.hg
目录在文件系统层次结构中向上移动,我们可以有效地将工作副本文件在工作副本内的层次结构中向下移动。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.如果您的 Mercurial 存储库的根目录位于
~/P104/lecture_notes
下,我宁愿:lecture_notes
重命名为 P104lecture_notes
homework
及其在重命名的 P104 目录中的文件hg add
everything这个想法是保留
.hg
存储库(~/P104/lecture_notes
重命名为~/P104/P104
)并重新组织该重命名目录中的文件.无需克隆。
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.