更改 Mercurial 中的目录结构

发布于 2025-01-02 02:51:40 字数 971 浏览 0 评论 0原文

我有一个单人单文件夹 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

农村范ル 2025-01-09 02:51:40

我喜欢 VonC 的解决方案,您无需移动 .hg 文件夹。这是一个简单的解决方案。这是一种替代方法,您确实移动它,因此必须重命名更少的文件夹:

  1. .hg文件夹移至~/P104

    <前><代码>$ mv ~/P104/lecture_notes/.hg ~/P104

    从 Mercurial 的角度来看,您已将所有顶级文件移至 lecture_notes 目录中。 homework 文件夹中也会突然出现新的未跟踪文件。

  2. 让 Mercurial 确定重命名:

    <前><代码>$ hg addremove

    这将正确检测到之前属于顶级文件的文件现在位于 lecture_notes 目录中。刚刚添加了 homework 中未跟踪(且未忽略)的文件。

  3. 保存更改:

    <前><代码>$ 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:

  1. Move the .hg folder up to ~/P104

    $ mv ~/P104/lecture_notes/.hg ~/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 the homework folder.

  2. Let Mercurial figure out the renames:

    $ hg addremove
    

    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 in homework are just added.

  3. Save the changes:

    $ hg commit
    

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.

相思故 2025-01-09 02:51:40

如果您的 Mercurial 存储库的根目录位于 ~/P104/lecture_notes 下,我宁愿:

  1. lecture_notes 重命名为 P104
  2. 子目录 lecture_notes
  3. 移动 该新子目录中的所有现有文件
  4. add homework 及其在重命名的 P104 目录中的文件
  5. 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:

  1. rename lecture_notes into P104
  2. make a subdirectory lecture_notes
  3. move all the existing files in that new sub-directory
  4. add homework and its files in the renamed P104 directory
  5. hg add everything

The 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文