Differences between revisions 29 and 30
Revision 29 as of 2011-03-27 21:06:16
Size: 4770
Comment: streamline the patch solution a bit
Revision 30 as of 2011-06-08 10:12:08
Size: 4795
Editor: proxy
Comment: added windows commandline for "Patch queue solution (using mq)"
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

(See also: [[EditingHistory]], [[HisteditExtension]] (which provides an editor-driven UI for this), [[CollapseExtension]], [[RebaseProject]] (section ''Collapsing'')).
(See also: EditingHistory, HisteditExtension (which provides an editor-driven UI for this), CollapseExtension, RebaseProject (section ''Collapsing'')).
Line 8: Line 7:
 {{{#!dot  . {{{#!dot
Line 19: Line 18:
 {{{#!dot  . {{{#!dot
Line 32: Line 31:
 This [[Update|updates]] the [[WorkingDirectory|working directory]] to revision S.
Specifically, this means that the contents of the working directory are
changed to that of revision S, and that S becomes the [[Parent|parent]]
of the working directory.
 . This [[Update|updates]] the [[WorkingDirectory|working directory]] to revision S. Specifically, this means that the contents of the working directory are changed to that of revision S, and that S becomes the [[Parent|parent]] of the working directory.
Line 40: Line 35:
 {{{#!dot  . {{{#!dot
Line 51: Line 46:

This [[Revert|reverts]] the working directory to its contents at [[Tip|tip]].
Since the parent of the working directory is still S, this means that
the combined contents of all changesets between S and S+k show up as
the modifications in the working directory.
 This [[Revert|reverts]] the working directory to its contents at [[Tip|tip]]. Since the parent of the working directory is still S, this means that the combined contents of all changesets between S and S+k show up as the modifications in the working directory.
Line 61: Line 51:
 {{{#!dot  . {{{#!dot
Line 73: Line 63:

[[Commit|Committing]] these modifications creates a
new changeset "S+k (combined)", containing combined changesets S+1 to S+k.
 [[Commit|Committing]] these modifications creates a new changeset "S+k (combined)", containing combined changesets S+1 to S+k.
Line 80: Line 67:
 {{{#!dot  . {{{#!dot
Line 90: Line 77:
Line 92: Line 78:
Line 94: Line 79:
 
 
{{{hg clone -r tip -r branch1 -r branch2 -r branch3 oldrepo newrepo}}}

 Or you can use the {{{strip}}} command provided by the [[MqExtension|Mercurial Queues Extension]].
Note that if you're planning to use mq, there's a much more convenient way to do the above...
  . {{{hg clone -r tip -r branch1 -r branch2 -r branch3 oldrepo newrepo}}}
 Or you can use the {{{strip}}} command provided by the [[MqExtension|Mercurial Queues Extension]]. Note that if you're planning to use mq, there's a much more convenient way to do the above...
Line 101: Line 83:
Make a patch containing the changesets you want to concatenate. <<BR>> '''~+{{{1: hg -R oldrepo export --git -r S:tip > patchfile}}}+~'''
Line 102: Line 85:
Make a patch containing the changesets you want to concatenate. <<BR>>
'''~+{{{1: hg -R oldrepo export --git -r S:tip > patchfile}}}+~'''
Make a partial clone of the repository, up to and including the parent of S. This discards the patch changesets. <<BR>> '''~+{{{2: hg clone -r "p1(S)" oldrepo newrepo}}}+~'''
Line 105: Line 87:
Make a partial clone of the repository, up to and including the parent of S. This discards the patch changesets. <<BR>>
'''~+{{{2: hg clone -r "p1(S)" oldrepo newrepo}}}+~'''

Import the patch in the cloned repository as one changeset. <<BR>>
'''~+{{{3: hg -R newrepo import -m "Combine changesets S+1..S+k" patchfile}}}+~'''
Import the patch in the cloned repository as one changeset. <<BR>> '''~+{{{3: hg -R newrepo import -m "Combine changesets S+1..S+k" patchfile}}}+~'''
Line 112: Line 90:
Integrate the changesets you want to concatenate in a patch queue (verify you don't have pending patches there using {{{hg qseries}}}). <<BR>> '''~+{{{1: hg qimport -r S:tip}}}+~'''
Line 113: Line 92:
Integrate the changesets you want to concatenate in a patch queue (verify you don't have pending patches there using {{{hg qseries}}}). <<BR>>
'''~+{{{1: hg qimport -r S:tip}}}+~'''
Pop all the patches but the first. <<BR>> '''~+{{{2: hg qgoto qbase}}}+~'''
Line 116: Line 94:
Pop all the patches but the first. <<BR>>
'''~+{{{2: hg qgoto qbase}}}+~'''
"Fold" unapplied patches, i.e. concatenate changesets. <<BR>> '''~+{{{3: hg qfold $(hg qunapp)}}}+~''' <<BR>> '''~+{{{3: for /F %i in ('hg qunapp') do hg qfold %i (Windows)}}}+~''' <<BR>> This has the big advantage over the previous method that the commit messages will also be concatenated (separated by the {{{* * *}}} string). You can see the message using {{{hg qhead}}} and edit it using {{{hg qrefresh -e}}}.
Line 119: Line 96:
"Fold" unapplied patches, i.e. concatenate changesets. <<BR>>
'''~+{{{3: hg qfold $(hg qunapp)}}}+~''' <<BR>>
This has the big advantage over the previous method that the commit messages will also be concatenated (separated by the {{{* * *}}} string). You can see the message using {{{hg qhead}}} and edit it using {{{hg qrefresh -e}}}.

Reintegrate the folded patch in the repository. <<BR>>
'''~+{{{4: hg qfinish qbase}}}+~''' <<BR>>
{{{tip}}} is now the concatenation of former changesets {{{S:tip}}}. There's no extra branch left, therefore no additional cleanup to do.
Reintegrate the folded patch in the repository. <<BR>> '''~+{{{4: hg qfinish qbase}}}+~''' <<BR>> {{{tip}}} is now the concatenation of former changesets {{{S:tip}}}. There's no extra branch left, therefore no additional cleanup to do.

Concatenating multiple changesets into one

(See also: EditingHistory, HisteditExtension (which provides an editor-driven UI for this), CollapseExtension, RebaseProject (section Collapsing)).

Problem

Suppose you want to concatenate the last k changesets of a repository

into a single, combined changeset

Revert solution (using hg only)

Execute the following steps:

1: hg -R oldrepo update S

  • This updates the working directory to revision S. Specifically, this means that the contents of the working directory are changed to that of revision S, and that S becomes the parent of the working directory.

2: hg -R oldrepo revert -r tip --all

  • This reverts the working directory to its contents at tip. Since the parent of the working directory is still S, this means that the combined contents of all changesets between S and S+k show up as the modifications in the working directory. /!\ Revert does not preserve copy and move history.

3: hg -R oldrepo commit -m "Combine changesets S+1..S+k"

  • Committing these modifications creates a new changeset "S+k (combined)", containing combined changesets S+1 to S+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. /!\ This will strip out all other branches, not just the one dangling branch that you don't want. If you have other branches that you want to keep, specify their head revisions or branch names on the clone call:

    • hg clone -r tip -r branch1 -r branch2 -r branch3 oldrepo newrepo

    Or you can use the strip command provided by the Mercurial Queues Extension. Note that if you're planning to use mq, there's a much more convenient way to do the above...

Patch solution (using hg only)

Make a patch containing the changesets you want to concatenate.
1: hg -R oldrepo export --git -r S:tip > patchfile

Make a partial clone of the repository, up to and including the parent of S. This discards the patch changesets.
2: hg clone -r "p1(S)" oldrepo newrepo

Import the patch in the cloned repository as one changeset.
3: hg -R newrepo import -m "Combine changesets S+1..S+k" patchfile

Patch queue solution (using mq)

Integrate the changesets you want to concatenate in a patch queue (verify you don't have pending patches there using hg qseries).
1: hg qimport -r S:tip

Pop all the patches but the first.
2: hg qgoto qbase

"Fold" unapplied patches, i.e. concatenate changesets.
3: hg qfold $(hg qunapp)
3: for /F %i in ('hg qunapp') do hg qfold %i (Windows)
This has the big advantage over the previous method that the commit messages will also be concatenated (separated by the * * * string). You can see the message using hg qhead and edit it using hg qrefresh -e.

Reintegrate the folded patch in the repository.
4: hg qfinish qbase
tip is now the concatenation of former changesets S:tip. There's no extra branch left, therefore no additional cleanup to do.


CategoryTipsAndTricks

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