Size: 13166
Comment: add TOC for easier navigation
|
Size: 13052
Comment: fix wrong revision name
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
#pragma section-numbers 2 | |
Line 7: | Line 8: |
== Introduction == When contributing to a project, sometimes there is the need to keep some patches private, while keeping the whole repository up-to-date. In those cases it can be useful to "detach" the local changes, synchronize the repository with the mainstream and then append the private changes on top of the new remote changes. This operation is called ''rebase''. In general, this extension allows to move revisions from a point to another, some common scenarios are shown in the section "Scenarios". |
|
Line 8: | Line 17: |
Line 10: | Line 18: |
Line 12: | Line 21: |
rebase = }}} == Introduction == When contributing to a project, sometimes there is the need to keep some patches private, while keeping the whole repository up-to-date. In those cases it can be useful to "detach" the local changes, synchronize the repository with the mainstream and then append the private changes on top of the new remote changes. This operation is called ''rebase''. In general, this extension allows to move revisions from a point to another, some common scenarios are shown in the section "Scenarios". |
rebase = }}} |
Line 35: | Line 33: |
hg rebase [--source REV | --base REV] [--dest REV] [--collapse] [--keep] [--keepbranches] | [--continue] | [--abort] }}} |
hg rebase [--source REV | --base REV] [--dest REV] [--collapse] [--keep] [--keepbranches] | [--continue] | [--abort] }}} |
Line 39: | Line 36: |
Line 41: | Line 37: |
allows to specify a revision that will be rebased onto dest with all its descendants | . allows to specify a revision that will be rebased onto dest with all its descendants |
Line 44: | Line 40: |
the revision specified will be rebased along with its descendants and its ancestors up to the common point (excluded) between rev and dest's ancestors ''Note that this option conflicts with --source'' |
. the revision specified will be rebased along with its descendants and its ancestors up to the common point (excluded) between rev and dest's ancestors ''Note that this option conflicts with --source'' |
Line 48: | Line 44: |
the destination onto which the required revisions will be rebased | . the destination onto which the required revisions will be rebased |
Line 51: | Line 47: |
resume an interrupted rebase | . resume an interrupted rebase |
Line 54: | Line 50: |
abort an interrupted rebase | . abort an interrupted rebase |
Line 57: | Line 53: |
collapse the rebased revisions | . collapse the rebased revisions |
Line 60: | Line 56: |
keep original revisions | . keep original revisions |
Line 63: | Line 59: |
keep original branch names | . keep original branch names |
Line 67: | Line 63: |
Line 70: | Line 67: |
that pulls and rebases the local revisions if there's something to rebase. Otherwise it behaves like hg pull --update. |
that pulls and rebases the local revisions if there's something to rebase. Otherwise it behaves like `hg pull --update`. |
Line 192: | Line 188: |
Line 210: | Line 205: |
Line 213: | Line 209: |
Line 215: | Line 210: |
Line 246: | Line 240: |
Line 248: | Line 241: |
Line 252: | Line 244: |
Line 270: | Line 261: |
Line 274: | Line 264: |
Line 290: | Line 279: |
{{{ $ hg rebase --dest B --source S }}} |
{{{ $ hg rebase --dest B --source C }}} |
Line 314: | Line 301: |
Line 316: | Line 302: |
Line 321: | Line 305: |
Line 335: | Line 318: |
Line 352: | Line 334: |
Line 367: | Line 347: |
Line 369: | Line 348: |
Line 373: | Line 351: |
Line 395: | Line 372: |
Line 406: | Line 382: |
Line 412: | Line 387: |
Line 414: | Line 388: |
Line 425: | Line 398: |
Line 428: | Line 400: |
Rebase tries to turn ''<dest>'' into a parent of ''<root>'' while '''preserving the number of parents of rebased changesets''': |
Rebase tries to turn ''<dest>'' into a parent of ''<root>'' while '''preserving the number of parents of rebased changesets''': |
Line 434: | Line 403: |
changeset with a single parent. | . changeset with a single parent. |
Line 437: | Line 406: |
ancestors of ''<dest>'' or are themselves in the rebased set and pruned while rebased. If one parent of ''<root>'' is an ancestor of ''<dest>'', the rebased version of this parent will be ''<dest>''. This is always true with ''--base'' option. Otherwise, we need to '''replace''' the original parents with ''<dest>''. This ''detaches'' the rebased set from its former location and rebases it onto ''<dest>''. Changes introduced by ancestors of ''<root>'' not common with ''<dest>'' are '''removed''' from the rebased changesets. |
. ancestors of ''<dest>'' or are themselves in the rebased set and pruned while rebased. If one parent of ''<root>'' is an ancestor of ''<dest>'', the rebased version of this parent will be ''<dest>''. This is always true with ''--base'' option. Otherwise, we need to '''replace''' the original parents with ''<dest>''. This ''detaches'' the rebased set from its former location and rebases it onto ''<dest>''. Changes introduced by ancestors of ''<root>'' not common with ''<dest>'' are '''removed''' from the rebased changesets. |
Line 452: | Line 415: |
replace, the rebase operation is not clearly defined. This kind of rebase is not allowed. |
. replace, the rebase operation is not clearly defined. This kind of rebase is not allowed. |
Line 456: | Line 418: |
|| || one parent || merge || || parent in ''::<dest>'' || new parent is ''<dest>'' || parents in ''::<dest>'' are remapped to ''<dest>''|| || unrelated source || new parent is ''<dest>'' || ambiguous, abort || |
|| ||one parent ||merge || ||parent in ''::<dest>'' ||new parent is ''<dest>'' ||parents in ''::<dest>'' are remapped to ''<dest>'' || ||unrelated source ||new parent is ''<dest>'' ||ambiguous, abort || |
Line 464: | Line 426: |
Line 466: | Line 427: |
Line 509: | Line 471: |
Line 513: | Line 474: |
* [[http://code.google.com/soc/2008/hg/appinfo.html?csaid=EC7D811E53CA98EF|GSoC's Abstract ]] | * [[http://code.google.com/soc/2008/hg/appinfo.html?csaid=EC7D811E53CA98EF|GSoC's Abstract]] |
Line 515: | Line 476: |
Rebase Extension
This extension is distributed along with Mercurial releases
Author: Stefano Tortarolo
Contents
1. Introduction
When contributing to a project, sometimes there is the need to keep some patches private, while keeping the whole repository up-to-date.
In those cases it can be useful to "detach" the local changes, synchronize the repository with the mainstream and then append the private changes on top of the new remote changes. This operation is called rebase.
In general, this extension allows to move revisions from a point to another, some common scenarios are shown in the section "Scenarios".
2. Configuration
Enable the extension in the configuration file (e.g. .hg/hgrc):
[extensions] rebase =
3. Features
- rebase both simple and complex cases
- abort of an interrupted rebasing
- resume of an interrupted rebasing
- mq patches handling
- detect changes during interruptions
4. Usage
4.1. Synopsis
hg rebase [--source REV | --base REV] [--dest REV] [--collapse] [--keep] [--keepbranches] | [--continue] | [--abort]
4.2. Description
--source rev
- allows to specify a revision that will be rebased onto dest with all its descendants
--base rev
- the revision specified will be rebased along with its descendants and its ancestors up to the common point (excluded) between rev and dest's ancestors
Note that this option conflicts with --source
- the revision specified will be rebased along with its descendants and its ancestors up to the common point (excluded) between rev and dest's ancestors
--dest rev
- the destination onto which the required revisions will be rebased
--continue
- resume an interrupted rebase
--abort
- abort an interrupted rebase
--collapse
- collapse the rebased revisions
--keep
- keep original revisions
--keepbranches
- keep original branch names
4.3. Integration with pull
Rebase provides an extra option for pull.
hg pull --rebase
that pulls and rebases the local revisions if there's something to rebase. Otherwise it behaves like hg pull --update.
5. A common case
It's important to notice that this extension can be invoked with no arguments.
Semantically, invoking plain rebase can be intended as take the branch I'm working on and make it current, in other words this means moving the local changes onto the most recent head of the checked out named branch.
Let's imagine this situation:
L* represent our local changes after our last pull.
hg pull
pulls from mainstream two new revisions:
Usually what we would like to do is move L* onto R2 and this can be easily achieved with:
hg rebase
Result:
Note: As stated above, this can be achieved in one step using hg pull --rebase
6. Dealing with conflicting merges
A situation could arise where some changes in L* conflict with some changes in R*. In these cases, the extension will stop, store the current status, and provide the user with the ability to solve the conflict on his own.
In event of an interruption, users have two choices:
- abort
- continue
6.1. Abort
An interrupted process can be aborted, thus restoring the repository to its original state, with:
$ hg rebase --abort
6.2. Continue
The most common situation, however, is resuming an interrupted process and this can be done with:
$ hg rebase --continue
7. When rebase is not allowed
There are situations in which a rebasing process is not allowed:
- the rebasing point (source) is an ancestor of target
- the rebasing point (source) is a merge revision and both of its parents are external
8. Notes about MQ Patches
In the current implementation MQ patches are qfinished and qimported after being rebased. This adds an export-like header to each rebased patch. e.g.,
- Original patch:
Description P0 diff --git a/f b/f etc...
- Rebased patch:
# HG changeset patch # User Stefano Tortarolo <stefano.tortarolo@gmail.com> # Date 1217929313 -7200 # Node ID 92bd85e9196feac01fdf2eb2ce7275e9a575a730 # Parent 6e55161e68b2062d629c05b89b0ea3424eec9a2f Description P0 diff --git a/f b/f etc...
9. Scenarios
Now will be analyzed the most interesting scenarios.
9.1. Scenario A
The first one is the simplest one, a simple branch.
In this scenario there are two interesting interactions:
9.1.1. rebase on top
$ hg up C $ hg rebase --dest E
Another syntax that would yield the same result is:
$ hg rebase --dest E --base C
9.1.2. rebase on an intermediate revision
$ hg up C $ hg rebase -d D
9.2. Scenario B
The second scenario involves something more complicated. In this scenario the user cloned from upstream, then merged several times.
9.2.1. rebase D on I
$ hg rebase --dest I --source D
Despite being a merge revision D hasn't been skipped in this case, as opposite to H.
9.2.2. rebase B on I
$ hg rebase --dest I --source B
- In this case two revisions (D and H) have been skipped.
9.2.3. rebase C on B
$ hg rebase --dest B --source C
9.2.4. rebase G onto I
$ hg rebase --dest I --source G
Note: Prior Mercurial 2.3 you need to had --detach option in this situation. otherwise you get this result
9.3. Scenario C
This case represents a quite common situation, a repository with just one (merge) head.
9.3.1. D onto C
$ hg rebase --dest C --source D
- Obviously the revision F has been skipped.
9.4. Collapsing
Sometimes it could be useful to be able to rebase changesets onto another branch, obtaining though just one revision.
This can be achieved using the option --collapse.
$ hg rebase --dest B --source C --collapse
or
The base option could have been used here too
$ hg rebase --dest B --base E --collapse
9.4.1. C onto B and collapsing
10. Details
10.1. Parent relationships
Rebase tries to turn <dest> into a parent of <root> while preserving the number of parents of rebased changesets:
- A changeset with a single parent will always be rebased as a
- changeset with a single parent.
- A merge will be rebased as merge unless its parents are both
ancestors of <dest> or are themselves in the rebased set and pruned while rebased.
If one parent of <root> is an ancestor of <dest>, the rebased version of this parent will be <dest>. This is always true with --base option.
Otherwise, we need to replace the original parents with <dest>. This detaches the rebased set from its former location and rebases it onto <dest>. Changes introduced by ancestors of <root> not common with <dest> are removed from the rebased changesets.
If <root> has a single parent, set it to <dest>.
If <root> is a merge, we cannot decide which parent to
- replace, the rebase operation is not clearly defined. This kind of rebase is not allowed.
The table below sums up this behavior:
|
one parent |
merge |
parent in ::<dest> |
new parent is <dest> |
parents in ::<dest> are remapped to <dest> |
unrelated source |
new parent is <dest> |
ambiguous, abort |
11. Command documentation
As of Mercurial 2.4, here is the official documentation of the rebase command.
Rebase uses repeated merging to graft changesets from one part of history (the source) onto another (the destination). This can be useful for linearizing *local* changes relative to a master development tree. You should not rebase changesets that have already been shared with others. Doing so will force everybody else to perform the same rebase or they will end up with duplicated changesets after pulling in your rebased changesets. If you don't specify a destination changeset ("-d/--dest"), rebase uses the tipmost head of the current named branch as the destination. (The destination changeset is not modified by rebasing, but new changesets are added as its descendants.) You can specify which changesets to rebase in two ways: as a "source" changeset or as a "base" changeset. Both are shorthand for a topologically related set of changesets (the "source branch"). If you specify source ("-s/--source"), rebase will rebase that changeset and all of its descendants onto dest. If you specify base ("-b/--base"), rebase will select ancestors of base back to but not including the common ancestor with dest. Thus, "-b" is less precise but more convenient than "-s": you can specify any changeset in the source branch, and rebase will select the whole branch. If you specify neither "-s" nor "-b", rebase uses the parent of the working directory as the base. By default, rebase recreates the changesets in the source branch as descendants of dest and then destroys the originals. Use "--keep" to preserve the original source changesets. Some changesets in the source branch (e.g. merges from the destination branch) may be dropped if they no longer contribute any change. One result of the rules for selecting the destination changeset and source branch is that, unlike "merge", rebase will do nothing if you are at the latest (tipmost) head of a named branch with two heads. You need to explicitly specify source and/or destination (or "update" to the other head, if it's the head of the intended source branch). If a rebase is interrupted to manually resolve a merge, it can be continued with --continue/-c or aborted with --abort/-a. Returns 0 on success, 1 if nothing to rebase.
12. Related links
RebaseIfExtension - A separate (unbundled) extension that only rebases if there are no conflicted files, otherwise does a merge