Size: 13593
Comment: Added a copy of the command doc (which seems more complete and up to date)
|
Size: 13755
Comment: Convert some lists to headings
|
Deletions are marked like this. | Additions are marked like this. |
Line 201: | Line 201: |
* rebase on top | ==== rebase on top ==== |
Line 219: | Line 219: |
* rebase on an intermediate revision | Another syntax that would yield the same result is: {{{ $ hg up E $ hg rebase -s C }}} ==== rebase on an intermediate revision ==== |
Line 251: | Line 257: |
* rebase D on I | ==== rebase D on I ==== |
Line 269: | Line 276: |
* rebase B on I | ==== rebase B on I ==== |
Line 285: | Line 292: |
* rebase C on B | ==== rebase C on B ==== |
Line 306: | Line 313: |
* rebase G onto I | ==== rebase G onto I ==== |
Line 339: | Line 347: |
Line 352: | Line 361: |
* D onto C | ==== D onto C ==== |
Line 380: | Line 390: |
* C onto B and collapsing | ==== C onto B and collapsing ==== |
Line 392: | Line 403: |
Rebase Extension
This extension is distributed along with Mercurial releases
Author: Stefano Tortarolo
Configuration
Enable the extension in the configuration file (e.g. .hg/hgrc):
[extensions] 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".
Features
- rebase both simple and complex cases
- abort of an interrupted rebasing
- resume of an interrupted rebasing
- mq patches handling
- detect changes during interruptions
Usage
Synopsis
hg rebase [--source REV | --base REV] [--dest REV] [--collapse] [--detach] [--keep] [--keepbranches] | [--continue] | [--abort]
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
--detach (since Mercurial 1.6)
- force detaching of source from its original branch
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.
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
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
Abort
An interrupted process can be aborted, thus restoring the repository to its original state, with:
$ hg rebase --abort
Continue
The most common situation, however, is resuming an interrupted process and this can be done with:
$ hg rebase --continue
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 descendant of target
In this case, you will need to use the transplant and strip commands. For example:
hg up -r <targetrev> # Needed because the transplant -m option doesn't work hg transplant <source>:tip hg strip <source>
- the rebasing point (source) is a merge revision and both of its parents are external
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...
Scenarios
Now will be analyzed the most interesting scenarios.
Scenario A
The first one is the simplest one, a simple branch.
In this scenario there are two interesting interactions:
rebase on top
$ hg up C $ hg rebase -d E
Another syntax that would yield the same result is:
$ hg up E $ hg rebase -s C
rebase on an intermediate revision
$ hg up C $ hg rebase -d D
Scenario B
The second scenario involves something more complicated. In this scenario the user cloned from upstream, then merged several times.
rebase D on I
Despite being a merge revision D hasn't been skipped in this case, as opposite to H.
rebase B on I
- In this case two revisions (D and H) have been skipped.
rebase C on B
rebase G onto I
Note: Rebase drops a parent relationship only if the parent is an ancestor of target.
Using a development version is available the new --detach option that drops this relationship.
Scenario C
This case represents a quite common situation, a repository with just one (merge) head.
D onto C
- Obviously the revision F has been skipped.
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.
C onto B and collapsing
Details
Parent relationships
When rebasing a given node (N) different situations may happen, depending on the status of its parent(s).
From now on P1N is used to refer to the first parent of N, P2N to the second one.
e.g., P1'N identifies the rebased first parent of N
These situations are summed up in the following table:
|
P2N = A |
P2N = S |
P2N = E |
P2N = N |
||||
P1N = A |
|
p1 = P2'N |
p1 = target, p2 = P2N |
p1 = target |
||||
P1N = S |
p1 = P1'N |
p1 = P1'N, p2 = P2'N |
p1 = P1'N, p2 = P2N |
p1 = P1'N |
||||
P1N = E |
p1 = target, p2 = P1N |
p1 = P2'N, p2 = P1N |
|
p1 = target, p2 = P1N |
A: In ancestors(target) S: In the rebasing series E: External N: None
The empty cells cover the cases in which:
P1N = P2N = A that means that also N is in ancestors(target) and this scenario is disallowed
P1N = P2N = E that means that N is a merged revision and none of its parents is ancestor of target. This scenario is disallowed (Idea: Can we make assumptions about a better revision point?) Note that this case can happen only if N is the rebasing point.
Also note that:
P1N = None entails that P2N = None
P1N = P2N = None is true only if N is root (this scenario is disallowed by the rule that a node can't be rebased onto a descendant)
Command documentation
As of Mercurial 2.0, 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.
Related links
RebaseIfExtension - A separate (unbundled) extension that only rebases if there are no conflicted files, otherwise does a merge