1

Consider the following multi-module project (within a single repository):

Module A (i.e. parent)
  - Module 1 (various core stuff)
    - Module i
  - Module 2 (non-core, depends on 1)
    - Module ii
    - Module iii

(The reason for a set up like this is it enables some developers to just work on individual modules (e.g. 2 and its children), whilst other developers can work on the whole code base (e.g. A and its children).

Let us then suppose that Module ii has been reclassified as core, and needs to be moved into Module 1.

I could just handle this by moving Module ii from Module 2 to Module 1. However, mercurial treats this as a delete (from 2) and add (in 1), and thus we would lose the revision history from ii prior to the move. (I know that we would not actually 'lose' this, as it would still be available in mercurial; however, it would not be readily accessible wrt the files in the new location).

How can I move files and have mercurial move the revision history with those files?

amaidment
  • 6,942
  • 5
  • 52
  • 88
  • 1
    This isn't very clear. Are these modules separate repos? Are you asking how to combine repositories whilst preserving history? – Paul S Nov 29 '11 at 19:18
  • 1
    As you can see in [these](http://stackoverflow.com/questions/5264528/why-hg-mv-mercurial-doesnt-move-a-files-history-by-default) [questions](http://stackoverflow.com/questions/3472216/in-mercurial-hg-rename-works-but-the-history-doesnt-follow-the-file), the history can still be accessed even though it is done with a copy and then a delete. This assumes that the top of your mercurial repository is Module A. – 101100 Nov 29 '11 at 20:14
  • @PaulS - I don't understand where your questions are coming from; they seem to be suggesting a level of complexity that is not implied in the question. For superfluous clarification, I have edited the question to confirm that this is all in a single repository... – amaidment Nov 30 '11 at 00:17
  • @amaidment It's quite common in mercurial to have different 'modules' of a system in different repositories. I was thinking there must have been something special about the situation to warrant the question. If it's all in one repo then the answer is `hg mv`, which `hg help` would have told you. – Paul S Nov 30 '11 at 08:35
  • Mercurial does treat a move as a copy + delete, preserving all history, and this is rather trivial (does not show research effort, hence -1). Like SVN, you need to use `hg mv` to perform the copy (or mark it as such after the fact), otherwise it is not aware that the file has moved. – Laurens Holst Nov 30 '11 at 11:57
  • @101100 - thanks for the links, those were helpful for working this out. However, they're not very helpfully tagged - could you (or someone else...) add tags of 'move' 'hg mv' 'revision-history' for these questions? (I would do this, but lack the rep to do so...) – amaidment Nov 30 '11 at 16:03

3 Answers3

3

It is possible to convert these add/remove pairs to "renames" using hg mv, as long as they remain in the same repository.

StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
1

The info is there and is not lost. You just need to use the -f,--follow flag for hg log. (This is what @freixo points to in post Why 'hg mv' (mercurial) doesn't move a file's history by default?)

Community
  • 1
  • 1
cape1232
  • 999
  • 6
  • 21
0

Why don't you just change your ~/.hgrc (or Mercurial.ini) doing what xanatos says here: Why 'hg mv' (mercurial) doesn't move a file's history by default?

Community
  • 1
  • 1
freixo
  • 193
  • 9