开发者

How can I move my Mercurial repository root up one directory?

I have a directory structure like:

project_root
  data/
  src/
    .hg/
    utils/
    math/
    graphics/
    ...
  README.txt
  LICENCE.txt

As you can see from the location of .hg/, only src/ is under Hg control. I'd like to move the repository root up from src/ to its parent directory project_root, so I can track data/, README.txt, and LICENCE.txt as well.

A hacky way to do this would be to move everything down a directory rather than movi开发者_开发问答ng .hg up:

  • Move the contents of src down to a new directory src/src/
  • Move the contents of project_root (other than src/) down to src/
  • Rename src to new_project_root
  • Move new_project_root out of project_root, delete project_root

Is there a better way? I can't be the first person with this problem, and the above solution seems overly involved.


You should try hg convert. You will be "converting" your existing Mercurial repo into a new one. You specify rules for the conversion, which in your case will be that all files from the original repo go to a src directory in the new repo. Then you can manually copy and hg add the other files to the new repo.

This has the advantage that it won't be reflected as separate changes in your history. The possible disadvantage is that it will cause your changeset IDs to be regenerated, and existing clones will no longer be able to pull from the new repo.


Your plan is fine. It may seem involved, but it should take less than 20 minutes (worst case) and only happens once.

In the first step when you move the files that are tracked, you should use hg rename (alias hg move) to move them, as Mercurial will remember what each file was before and after the move. This will help with merging changes on file prior to the move with the new files after the move. Works best when renaming/copying is not accompanied by changes to the contents in the same changeset.

I recommend cloning the actual repo (or copying the entire project directory) before proceeding.


hg's Detect Renames works a treat nowadays.

Clone the repo so that you can mess things up without worry.

Using your example:

  • create the src/src subdir
  • move utils, math, graphics etc into src/src
  • Then open the commit window.
    • the moved files will appear in their old directory with a ! and in their new directory with a ?
  • right click on any file and choose "Detect Renames..."
  • slide the Min Similarity slider to 100%
  • Click the Accept All Matches button, and close the Detect Copies/Renames window
    • the moved files should now appear with an R in the old directory and an A in their new directory
  • commit this change

  • Then I moved data, Readme.txt etc down into src (not src/src)

  • committed the adds.

Finally, now that I have the repo as I want it, push the changes back to the originally cloned repo. Don't forget you'll need to Update the original repo to see the changes in the working directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜