tags:

views:

407

answers:

3

I have several repositories in my local machine. One is my main code, another is an assortment of useful code/tools. These are two fundamentally different repos. It might make sense to setup a new repo and pull these two in as sub-repos, but I want to wait until Selenic marks sub-repos as non-experimental before I do that.

One of the useful code files has become so useful, I want to put it into my main code area...but I want to maintain its history. This will, of course, result in some variant of a fork, but that's acceptable. (best case would be being able to push-pull it back and forth and keep updating its history).

+2  A: 

I'd just use the subrepo feature that came online in 1.3. It might change slightly, but you won't be left high and dry backwards compatibility wise.

If you can't bring yourself to so, then what you need to do is:

  1. use hg convert with a filemap that deletes all files except the one you want and convert from the repo with the single useful file to a new repo containing only that file and all its history
  2. then hg pull from the new single-file-full-history repo into the target repo
  3. hg merge in the target repo and you'll have that file with all it's history

The other option would be to hg export the entire tools repo, use grepdiff (part of difftools) to limit to only one file, and then import into the target repo, but that's crazy.

Ry4an
Step 1.5: hg update. :-)
Paul Nathan
I don't think update would be necessary. Your working dir in the target repo would be at the old tip, and the 'hg merge' would merge in the new other head correctly.
Ry4an
A: 

may be

hg export

also can help you.

f0b0s
A: 

The short answer is you can't copy a file and its history simply, as stated in this thread:

http://www.selenic.com/pipermail/mercurial/2009-April/025105.html

I'm relatively new to DVCS and you really have to think of each repo as a self contained package. Not like svn or p4, where you can hang different projects off the root and configure it how you like and do partial repo checkouts. (That said, I really like the flexibility of being able to clone repos quickly to try things out. And being able to commit on a local machine.)

I'm just looking at a similar problem. I've branched a repo to make changes and I only want one file out of one changeset. And it is nice to have the history.

  • You could look at:

    hg cat
    

    This would probably involve writing a script to transfer history, i.e. commit N changesets in the target repo with the hg cat results from the source. Wonder if there is an extension to do this?

  • You could get the log of the file you want to copy and paste that into a commit comment. It's not in the metadata, but you do have a record and all the hashes etc.

Nick