Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching a single file from another mercurial repository [duplicate]

Tags:

mercurial

Possible Duplicate:
Mercurial: copying ONE file and its history to another repository

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 Mercurial devs mark 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).

like image 784
Paul Nathan Avatar asked Aug 03 '09 18:08

Paul Nathan


2 Answers

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.

like image 195
Ry4an Brase Avatar answered Oct 08 '22 15:10

Ry4an Brase


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

https://www.mercurial-scm.org/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.

like image 24
Nick Avatar answered Oct 08 '22 15:10

Nick