Mercurial > hg > a8e
Help: graft
hg graft [OPTION]... [-r REV]... REV...
copy changes from other branches onto the current branch
This command uses Mercurial's merge logic to copy individual changes from other branches without merging branches in the history graph. This is sometimes known as 'backporting' or 'cherry-picking'. By default, graft will copy user, date, and description from the source changesets.
Changesets that are ancestors of the current revision, that have already been grafted, or that are merges will be skipped.
If --log is specified, log messages will have a comment appended of the form:
(grafted from CHANGESETHASH)
If --force is specified, revisions will be grafted even if they are already ancestors of, or have been grafted to, the destination. This is useful when the revisions have since been backed out.
If a graft merge results in conflicts, the graft process is interrupted so that the current merge can be manually resolved. Once all conflicts are addressed, the graft process can be continued with the -c/--continue option.
The -c/--continue option reapplies all the earlier options.
The --base option exposes more of how graft internally uses merge with a custom base revision. --base can be used to specify another ancestor than the first and only parent.
The command:
hg graft -r 345 --base 234
is thus pretty much the same as:
hg diff --from 234 --to 345 | hg import
but using merge to resolve conflicts and track moved files.
The result of a merge can thus be backported as a single commit by specifying one of the merge parents as base, and thus effectively grafting the changes from the other side.
It is also possible to collapse multiple changesets and clean up history by specifying another ancestor as base, much like rebase --collapse --keep.
The commit message can be tweaked after the fact using commit --amend .
For using non-ancestors as the base to backout changes, see the backout command and the hidden --parent option.
Examples:
- copy a single change to the stable branch and edit its description:
hg update stable hg graft --edit 9393
- graft a range of changesets with one exception, updating dates:
hg graft -D "2085::2093 and not 2091"
- continue a graft after resolving conflicts:
hg graft -c
- show the source of a grafted changeset:
hg log --debug -r .
- show revisions sorted by date:
hg log -r "sort(all(), date)"
- backport the result of a merge as a single commit:
hg graft -r 123 --base 123^
- land a feature branch as one changeset:
hg up -cr default hg graft -r featureX --base "ancestor('featureX', 'default')"
See 'hg help revisions' for more about specifying revisions.
Returns 0 on successful completion, 1 if there are unresolved files.
options ([+] can be repeated):
-r | --rev REV [+] | revisions to graft |
--base REV | base revision when doing the graft merge (ADVANCED) | |
-c | --continue | resume interrupted graft |
--stop | stop interrupted graft | |
--abort | abort interrupted graft | |
-e | --edit | invoke editor on commit messages |
--log | append graft info to log message | |
--no-commit | don't commit, just apply the changes in working directory | |
-f | --force | force graft |
-D | --currentdate | record the current date as commit date |
-U | --currentuser | record the current user as committer |
-d | --date DATE | record the specified date as commit date |
-u | --user USER | record the specified user as committer |
-t | --tool TOOL | specify merge tool |
-n | --dry-run | do not perform actions, just print output |
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) |