Differences between revisions 1 and 13 (spanning 12 versions)
Revision 1 as of 2008-03-23 09:49:33
Size: 2828
Editor: abuehl
Comment: moved from TipsAndTricks/Advanced
Revision 13 as of 2008-04-06 09:23:25
Size: 2505
Editor: abuehl
Comment: less prose, more pictures
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== Concatenating multiple changesets into one changeset == == Concatenating multiple changesets into one ==
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])''
Line 6: Line 5:
This can be done as follows using only the basic operations of
mercurial, namely clone, push, pull.
=== Problem ===
Suppose you want to concatenate the last k changesets of a [:Repository:repository]
Line 9: Line 8:
For simplicity, let us assume that the repository in question has a
single head, and you want to combine the last k revisions into a
single revision.
 {{{#!dot
digraph {
  rankdir = LR;
  node [shape=box];
  R -> "R+1" -> "R+2";
  "R+2" -> "R+k" [style=dashed];
}}}
Line 13: Line 16:
For concreteness, let us call the base revision R, and the ending
revision R+k.
into a single, combined changeset
Line 16: Line 18:
Let us furthermore assume the repository has no local changes.  {{{#!dot
digraph {
  rankdir = LR;
  node [shape=box];
  R -> "R+k (combined)"
}}}
Line 18: Line 25:
The strategy is to take advantage of mercurial's support for
repositories with more than one head. What we do is create a 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).
=== Solution ===
Execute the follwoing steps:
Line 24: Line 28:
Diagramatically, this looks like: '''~+{{{1: hg update R}}}+~'''
Line 26: Line 30:
{{{#!dot  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.


'''~+{{{2: hg revert -r tip --all}}}+~'''

 {{{#!dot
Line 28: Line 40:
  rankdir = BT;   rankdir = LR;
Line 37: Line 49:
{{{#!dot  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.


'''~+{{{3: hg ci -m "Combine changesets R+1..R+k"}}}+~'''

 {{{#!dot
Line 39: Line 59:
  rankdir = BT;   rankdir = LR;
Line 41: Line 61:
  "working directory" -> "R+k (concatenated)" [color=red label="3. commit"];   "working directory" -> "R+k (combined)" [color=red label="3. commit"];
Line 43: Line 63:
  R -> "R+k (concatenated)";   R -> "R+k (combined)";
Line 49: Line 69:
{{{#!dot  At this point, [:Commit:committing] these modifications will create a
 changeset containing all combined changesets between revisions R and R+k.


'''~+{{{4: hg clone -r tip oldrepo newrepo}}}+~'''

 {{{#!dot
Line 51: Line 77:
  rankdir = BT;   rankdir = LR;
Line 54: Line 80:
  "working directory" -> "R+k (concatenated)" [color=red label="4. clone -r tip"]
  R -> "R+k (concatenated)"
  "working directory" -> "R+k (combined)" [color=red label="4. clone -r tip"]
  R -> "R+k (combined)"
Line 59: Line 85:
 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.
Line 60: Line 87:
The procedure is as follows.

 1. hg update R
    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.

 2. hg revert -r tip --all
    This reverts the working directory to its contents at 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.

 3. hg ci -m "Combined changesets between R and R+k"
    At this point, committing these modifications will create a changeset
    containing all combined changesets between revisions R and R+k.

 4. 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. newrepo will now just have the combined changeset.
----
CategoryTipsAndTricks

Concatenating multiple changesets into one

(See also [:EditingHistory])

Problem

Suppose you want to concatenate the last k changesets of a [:Repository:repository]

into a single, combined changeset

Solution

Execute the follwoing steps:

1: 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.

2: 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.

3: hg ci -m "Combine changesets R+1..R+k"

  • At this point, [:Commit:committing] these modifications will create a changeset containing all combined changesets between revisions R and R+k.

4: 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.


CategoryTipsAndTricks

ConcatenatingChangesets (last edited 2013-10-10 10:48:33 by RamiroMorales)