How do I merge two Mercurial repos into a single o

2019-09-02 12:37发布

问题:

I have to separate Mercurial repositories. One is the main trunk for the project, while the other is a branch with a set of additional changes.

There is one central location for the project repository, in which I'd like both the trunk and the branch to be available. What I'd like to do is merge the two repositories into a single one, but still allow the branch to be accessed via tags, or something similar. This would allow developers to check out the main code, but also be able to switch to working on the branch if it requires further changes. I also want to make sure that any code in the trunk doesn't accidentally make it into the branch. Any changes to the branch should be explicit and intentional.

What is the best way to accomplish this?

回答1:

As Brandon says, just push from the branch repo to the trunk, or pull the branch into the trunk.

You can then choose if you want to merge branch & trunk together, or keep them separate. If you push from branch to trunk, you may get a warning about multiple heads. Just do a push -f if you want to keep them separate. (pull may not give a warning)

You can merge the branch changes to the trunk and still be able to do further work on the branch later if you want. In general, I tag every release so I can easily get back to anything that went out the door.

When you created the branch, did you clone it to another directory? If so, it will be harder to find the branch after pulling it into the trunk repo. You may want to read up on bookmarks to label the branch. Also look at how multiple heads work.

Note: The other option is to use named branches which labels the branch permanently. You wouldn't need to do anything extra to switch over to it later.