How to combine two projects in Mercurial?

14,826

Solution 1

I was able to combine my two repositories in this way:

  1. Use hg clone first_repository to clone one of the repositories.
  2. Use hg pull -f other_repository to pull the code in from the other repository.

The -f (force) flag on the pull is the key -- it says to ignore the fact that the two repositories are not from the same source.

Here are the docs for this feature.

Solution 2

hg started to have subrepo since 1.3 (2009-07-01). The early versions were incomplete and shaky but now it's pretty usable.

Solution 3

If you aren't using the same code across the projects, keep them separate. You can set your personal repository of each of those projects to be just a directory apart. Why mix all the branches, merges, and commit comments when you don't have to.

About your edit: Pushing from One repository to Another. You can always use the transplant command. Although, all this is really side stepping your desire to combine the two, so you might feel uncomfortable using my suggestions. Then you can use the forest extension, or something.

hg transplant -s REPOSITORY lower_rev:high_rev
Share:
14,826

Related videos on Youtube

jm.
Author by

jm.

Always busy SOreadytohelp

Updated on June 01, 2020

Comments

  • jm.
    jm. about 4 years

    I have two separate mercurial repositories. At this point it makes sense that they "become one" because I want to work on the two projects simultaneously.

    I'd really like the two projects to each be a subdirectory in the new repository.

    1. How do I merge the two projects?
    2. Is this a good idea, or should I keep them separate?

    It seems I ought to be able to push from one repository to the other... Maybe this is really straight forward?

  • ICTMitchell
    ICTMitchell over 14 years
    Does this preserve the commits' hash keys from the second repo too? (I'd guess not, but it might be ok until you do a merge.)
  • Factor Mystic
    Factor Mystic over 14 years
    This works, but you'll need to also run hg merge to finally get everything working
  • Steve Losh
    Steve Losh over 14 years
    @Marcus Lindblom: pulling a changeset will never, ever change its hash. If you look at hg glog after doing this you'll see you have two unrelated lines of changesets. The first changeset in each line has no parent, but that's not a problem for Mercurial. Once you pull you'll want to make one new changeset for each line where you hg mv everything into the appropriate subfolder, then you merge the lines and you're all set.
  • Mizipzor
    Mizipzor about 14 years
    Im about to do the same, I was wondering (since its been some time now since you did this) if you ever encountered any problems using the mega-merged clone?
  • jm.
    jm. about 14 years
    I don't remember running into any further problems. But I don't remember which repository I did this on, either :)
  • kamal
    kamal over 13 years
    what if the two repositories have code common to both of them. Would that be automatically handled by the merge ? and as for merge, we can ust say $ hg merge ?
  • Pete Duncanson
    Pete Duncanson over 12 years
    I've found subrepos to be a pain to work with. They work but you have to jump through some hoops to get them to behave and can be the source of a lot of headaches if you are not careful.
  • Gent
    Gent almost 12 years
    for reference purposes, here is the docs for this process mercurial.selenic.com/wiki/MergingUnrelatedRepositories
  • jtpereyda
    jtpereyda over 10 years
    Might be worth noting that subrepositories are officially a feature of last resort: mercurial.selenic.com/wiki/Subrepository (as of 2013.11.12)