Changing a directory structure in Mercurial

前端 未结 2 1609
暖寄归人
暖寄归人 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: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.

提交回复
热议问题