Size: 2828
Comment: moved from TipsAndTricks/Advanced
|
Size: 2358
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
Suppose you have a repository with a number of changesets which you want to combine into a single changeset. |
''(See also [:EditingHistory])'' Suppose you have a [:Repository:repository] with a number of [:ChangeSet:changesets] which you want to combine into a single changeset. |
Line 7: | Line 9: |
mercurial, namely clone, push, pull. | Mercurial, namely [:Clone:clone], [:Push:push], and [:Pull:pull]. |
Line 10: | Line 12: |
single head, and you want to combine the last k revisions into a single revision. |
single [:Head:head], and you want to combine the last k [:Revision:revisions] into a single revision. |
Line 16: | Line 18: |
Let us furthermore assume the repository has no local changes. | Let us furthermore assume the repository has no [:LocalModifications:local modifications]. |
Line 18: | Line 20: |
The strategy is to take advantage of mercurial's support for repositories with more than one head. What we do is create a branch |
The strategy is to take advantage of Mercurial's support for repositories with more than one head. What we do is create a [:Branch:branch] |
Line 26: | Line 28: |
{{{#!dot digraph { rankdir = BT; node [shape=box]; "working directory" -> R [label="1. update"]; R -> "R+1" -> "R+2"; "R+2" -> "R+k" [style=dashed]; "working directory" -> "R+k" [color=red label="2. revert"]; "working directory" [shape=ellipse]; }}} {{{#!dot digraph { rankdir = BT; node [shape=box]; "working directory" -> "R+k (concatenated)" [color=red label="3. commit"]; "working directory" -> R [style=invis]; R -> "R+k (concatenated)"; R -> "R+1" -> "R+2"; "R+2" -> "R+k" [style=dashed]; "working directory" [shape=ellipse]; }}} {{{#!dot digraph { rankdir = BT; node [shape=box]; "working directory" -> R [style=invis]; "working directory" -> "R+k (concatenated)" [color=red label="4. clone -r tip"] R -> "R+k (concatenated)" "working directory" [shape=ellipse label="cloned working directory"] }}} |
|| [[Include(/fig1)]] || [[Include(/fig2)]] || [[Include(/fig3)]] || ||<:> [:/fig1:fig 1] ||<:> [:/fig2:fig 2] ||<:> [:/fig2:fig 3] || |
Line 63: | Line 34: |
This updates the working directory to revision R. Specifically, this means that the contents of the working directory are changed to that of revision R, and that R becomes the parent of the working directory. |
This [:Update:updates] the [:WorkingDirectory:working directory] to revision R. Specifically, this means that the contents of the working directory are changed to that of revision R, and that R becomes the [:Parent:parent] of the working directory. |
Line 68: | Line 40: |
This reverts the working directory to its contents at tip. | This [:Revert:reverts] the working directory to its contents at [:Tip:tip]. |
Line 74: | Line 46: |
At this point, committing these modifications will create a changeset containing all combined changesets between revisions R and R+k. |
At this point, [:Commit:committing] these modifications will create a changeset containing all combined changesets between revisions R and R+k. |
Line 78: | Line 50: |
This assumes you want to get rid of your individual changesets (which are a dangling branch in oldrepo) and just keep the combined changeset. newrepo will now just have the combined changeset. |
This assumes you want to get rid of your individual changesets (which are a dangling branch in oldrepo) and just keep the combined changeset (see also [:PruningDeadBranches]). newrepo will now just have the combined changeset. ---- CategoryTipsAndTricks |
Concatenating multiple changesets into one changeset
(See also [:EditingHistory])
Suppose you have a [:Repository:repository] with a number of [:ChangeSet:changesets] which you want to combine into a single changeset.
This can be done as follows using only the basic operations of Mercurial, namely [:Clone:clone], [:Push:push], and [:Pull:pull].
For simplicity, let us assume that the repository in question has a single [:Head:head], and you want to combine the last k [:Revision:revisions] into a single revision.
For concreteness, let us call the base revision R, and the ending revision R+k.
Let us furthermore assume the repository has no [:LocalModifications:local modifications].
The strategy is to take advantage of Mercurial's support for repositories with more than one head. What we do is create a [:Branch:branch] whose root revision is R and which consists of just one changeset (actually it can be multiple changesets, the principle is the same, but for simplicity let us assume one).
Diagramatically, this looks like:
[:/fig1:fig 1] |
[:/fig2:fig 2] |
[:/fig2:fig 3] |
The procedure is as follows.
- hg update R
This [:Update:updates] the [:WorkingDirectory:working directory] to revision R. Specifically, this means that the contents of the working directory are changed to that of revision R, and that R becomes the [:Parent:parent] of the working directory.
- hg revert -r tip --all
This [:Revert:reverts] the working directory to its contents at [:Tip:tip]. Since the parent of the working directory is still R, this means that the combined contents of all changesets between R and R+k show up as the modifications in the working directory.
- hg ci -m "Combined changesets between R and R+k"
At this point, [:Commit:committing] these modifications will create a changeset containing all combined changesets between revisions R and R+k.
- hg clone -r tip oldrepo newrepo
This assumes you want to get rid of your individual changesets (which are a dangling branch in oldrepo) and just keep the combined changeset (see also [:PruningDeadBranches]). newrepo will now just have the combined changeset.