Help: rebase

hg rebase [-s REV | -b REV] [-d REV] [OPTION]

move changeset (and descendants) to a different branch

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.

Published commits cannot be rebased (see 'hg help phases'). To copy commits, see 'hg help graft'.

If you don't specify a destination changeset ("-d/--dest"), rebase will use the same logic as 'hg merge' to pick a destination. if the current branch contains exactly one other head, the other head is merged with by default. Otherwise, an explicit revision with which to merge with must be provided. (destination changeset is not modified by rebasing, but new changesets are added as its descendants.)

Here are the ways to select changesets:

  1. Explicitly select them using "--rev".
  2. Use "--source" to select a root changeset and include all of its descendants.
  3. Use "--base" to select a changeset; rebase will find ancestors and their descendants which are not also ancestors of the destination.
  4. If you do not specify any of "--rev", "source", or "--base", rebase will use "--base ." as above.

Rebase will destroy original changesets unless you use "--keep". It will also move your bookmarks (even if you do).

Some changesets may be dropped if they do not contribute changes (e.g. merges from the destination branch).

Unlike "merge", rebase will do nothing if you are at the branch tip of a named branch with two heads. You will need to explicitly specify source and/or destination.

If you need to use a tool to automate merge/conflict decisions, you can specify one with "--tool", see 'hg help merge-tools'. As a caveat: the tool will not be used to mediate when a file was deleted, there is no hook presently available for this.

If a rebase is interrupted to manually resolve a conflict, it can be continued with --continue/-c or aborted with --abort/-a.

Examples:

  • move "local changes" (current commit back to branching point) to the current branch tip after a pull:
    hg rebase
    
  • move a single changeset to the stable branch:
    hg rebase -r 5f493448 -d stable
    
  • splice a commit and all its descendants onto another part of history:
    hg rebase --source c0c3 --dest 4cf9
    
  • rebase everything on a branch marked by a bookmark onto the default branch:
    hg rebase --base myfeature --dest default
    
  • collapse a sequence of changes into a single commit:
    hg rebase --collapse -r 1520:1525 -d .
    
  • move a named branch while preserving its name:
    hg rebase -r "branch(featureX)" -d 1.3 --keepbranches
    

Configuration Options:

You can make rebase require a destination if you set the following config option:

[commands]
rebase.requiredest = True

By default, rebase will close the transaction after each commit. For performance purposes, you can configure rebase to use a single transaction across the entire rebase. WARNING: This setting introduces a significant risk of losing the work you've done in a rebase if the rebase aborts unexpectedly:

[rebase]
singletransaction = True

Return Values:

Returns 0 on success, 1 if nothing to rebase or there are unresolved conflicts.

(use 'hg help -e rebase' to show help for the rebase extension)

options ([+] can be repeated):

-s --source REV rebase the specified changeset and descendants
-b --base REV rebase everything from branching point of specified changeset
-r --rev REV [+] rebase these revisions
-d --dest REV rebase onto the specified changeset
--collapse collapse the rebased changesets
-m --message TEXT use text as collapse commit message
-e --edit invoke editor on commit messages
-l --logfile FILE read collapse commit message from file
-k --keep keep original changesets
--keepbranches keep original branch names
-D --detach (DEPRECATED)
-i --interactive (DEPRECATED)
-t --tool VALUE specify merge tool
-c --continue continue an interrupted rebase
-a --abort abort an interrupted rebase
--style STYLE display using template map file (DEPRECATED)
-T --template TEMPLATE display with template

global options ([+] can be repeated):

-R --repository REPO repository root directory or name of overlay bundle file
--cwd DIR change working directory
-y --noninteractive do not prompt, automatically pick the first choice for all prompts
-q --quiet suppress output
-v --verbose enable additional output
--color TYPE when to colorize (boolean, always, auto, never, or debug)
--config CONFIG [+] set/override config option (use 'section.name=value')
--debug enable debugging output
--debugger start debugger
--encoding ENCODE set the charset encoding (default: UTF-8)
--encodingmode MODE set the charset encoding mode (default: strict)
--traceback always print a traceback on exception
--time time how long the command takes
--profile print command execution profile
--version output version information and exit
-h --help display help and exit
--hidden consider hidden changesets
--pager TYPE when to paginate (boolean, always, auto, or never) (default: auto)