问题
When changing the VCS for my project FakeItEasy from SVN to Mercurial on Google Code I was a bit too eager (I'm funny like that). What I did was just checking the latest version out of SVN and then commiting that checkout as the first revision of the new Mercurial repo. This obviously has the effect that all history is lost.
Later when getting a bit better acustomed to Mercurial I realized that there is such a thing as a "convert extension" that allows you to convert a SVN repo into a Mercurial repo. Now what I want to do is to convert the old SVN repo and then have all change sets from the currently existing Mercurial repo imported into this converted repo except the very first commit to Mercurial.
I've converted the SVN repo to a local Mercurial repo but now is when I'm stuck. I thought I'd be able to use the convert extension to bring the current Mercurial repository into the converted one and having a splice map remove the first commit but I can not seem to get this to work.
I've also tried to just use convert without splice map to get all change sets from the current Mercurial repo into the converted one and the rebase the second version in the current to the last commit from the old SVN repository but I can't get that to work either.
To make this clearer lets say I have these two repositories:
A: revA1-revA2
B: revB1-revB2-revB3 (Where revB1 is actually a copy of revA2)
Now I want to combine these two into the new repository containing this:
C: revA1-revA2-revB2-revB3
回答1:
So long as you're changing the hashes on the new revisions (you are), you might as well just use export
and import
(or the transplant
command that is a wrapper around the two).
You already did your convert, which is great, now go into repo B and do:
hg export -o 'changeset-%R.patch' 1:tip
that will create a changeset-##.patch for each changeset in repo B, except the first (numbered zero).
Now go to repo C and import them:
hg import $(ls *.patch | sort -V)
That should all apply cleanly if indeed the revA2 and revB1 were identical.
回答2:
You can pull in changes from an unrelated repository with "hg pull --force"
Here is a simple usage example:
set up the test directories
C:\temp>mkdir hgtest
C:\temp>cd hgtest
C:\temp\hgtest>mkdir a
C:\temp\hgtest>mkdir b
C:\temp\hgtest>mkdir c
make repository a
C:\temp\hgtest>cd a
C:\temp\hgtest\a>hg init
C:\temp\hgtest\a>echo line one >> file.txt
C:\temp\hgtest\a>hg add file.txt
C:\temp\hgtest\a>hg ci -m "check in one"
C:\temp\hgtest\a>echo line two >> file.txt
C:\temp\hgtest\a>hg ci -m "check in two"
C:\temp\hgtest\a>echo line three >> file.txt
C:\temp\hgtest\a>hg ci -m "check in three"
make repository b
C:\temp\hgtest\a>cd ..\b
C:\temp\hgtest\b>copy ..\a\file.txt file.txt
C:\temp\hgtest\b>hg init
C:\temp\hgtest\b>hg add file.txt
C:\temp\hgtest\b>hg ci -m "check in b one"
C:\temp\hgtest\b>echo line four >> file.txt
C:\temp\hgtest\b>hg ci -m "check in b two"
C:\temp\hgtest\b>echo line five >> file.txt
C:\temp\hgtest\b>hg ci -m "check in b three"
make repository c as first a clone of a, then pull in the changes from b
C:\temp\hgtest\b>cd ..\c
C:\temp\hgtest\c>hg clone C:\temp\hgtest\a .
C:\temp\hgtest\c>hg pull --force C:\temp\hgtest\b
C:\temp\hgtest\c>hg merge
C:\temp\hgtest\c>hg ci -m "check in c one"
来源:https://stackoverflow.com/questions/2684727/adding-changes-from-one-mercurial-repository-to-another