问题
I have a Hg repository with changeset 0 representing just "adding .hgignore". Starting with changeset 1 I added changesets step by step from a number of Subversion revisions by a script. Then I worked for some time with Hg.
Now I decided that some more Svn revisions will be needed, which are located earlier in history than the beginning revision (changeset 1 in Hg).
Is it possible to insert new changesets between 0 and 1? If yes: How?
回答1:
You can use a Mercurial to Mercurial conversion for this. You need to enable the convert extension for this. The extension will let you splice history together as part of the conversion. This simply means that you can specify new parents for an existing changeset.
So if you start with
$ hg glog
@ changeset: 1:aaee9686dedf
| tag: tip
| user: Martin Geisler <mg@lazybytes.net>
| date: Fri Mar 23 15:08:11 2012 +0100
| summary: bar
|
o changeset: 0:17474bd28fe5
user: Martin Geisler <mg@lazybytes.net>
date: Fri Mar 23 15:08:05 2012 +0100
summary: foo
You can first import the needed revisions from SVN:
$ hg update null
$ run-your-script.sh
This will create a second root changeset — you now effectively have two disjoint histories in your repository. I made a single changeset where I added a baz
file:
$ hg glog
@ changeset: 2:515e1292862b
tag: tip
parent: -1:000000000000
user: Martin Geisler <mg@lazybytes.net>
date: Fri Mar 23 15:09:19 2012 +0100
summary: baz
o changeset: 1:aaee9686dedf
| user: Martin Geisler <mg@lazybytes.net>
| date: Fri Mar 23 15:08:11 2012 +0100
| summary: bar
|
o changeset: 0:17474bd28fe5
user: Martin Geisler <mg@lazybytes.net>
date: Fri Mar 23 15:08:05 2012 +0100
summary: foo
The final step is to link the histories together: we want 17474bd28fe5 to have 515e1292862b as its first parent. Use hg log --debug
to see the full changeset hashes and make a slice map file with
17474bd28fe535c15c7dad3659994ab048146e99 515e1292862ba2d6776294ffb00c533dc6850c66
Then run
$ hg convert --splicemap map.txt your-repo your-spliced-repo
You will find the modified history in your-spliced-repo
.
回答2:
As asked: yes, you can.
I see at least 3 ways to do it. All - with extensions
Import set of revisions into tip, after import use any of
- Rebase (
rebase -s tip -d X
for each moveable revision, N operations for N revisions) - Histedit (edit from start-revision, reorder revision in editor-window, 1 operation for N revisions)
- MQ (select all revisions, import to MQ, reorder revisions in patch-stack, edit content if needed, finish all revisions, N+2 operations for N revisions)
I'll prefer MQ as most powerful choice (inside MQ I'll be able to polish former changesets in order to remove conflicts and|or split changes in better way)
来源:https://stackoverflow.com/questions/9838888/add-additional-changesets-prior-to-changeset-0-zero