Changing a directory structure in Mercurial

前端 未结 2 1588
暖寄归人
暖寄归人 2021-01-05 16:40

I have a single-person single-folder mercurial repository. The directory structure is simple:

P104
  lecture_notes
    files under version control live here         


        
相关标签:
2条回答
  • 2021-01-05 17:14

    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.

    0 讨论(0)
  • 2021-01-05 17:29

    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.

    0 讨论(0)
提交回复
热议问题