Help: graft

hg graft [OPTION]... [-r] 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 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 does not reapply earlier options.


  • 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 .

Returns 0 on successful completion.


-r --rev REV [+] revisions to graft
-c --continue resume interrupted graft
-e --edit invoke editor on commit messages
--log append graft info to log message
-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 VALUE specify merge tool
-n --dry-run do not perform actions, just print output

[+] marked option can be specified multiple times

global options:

-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
--config CONFIG [+] set/override config option (use '')
--debug enable debugging output
--debugger start debugger
--encoding ENCODE set the charset encoding (default: ascii)
--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

[+] marked option can be specified multiple times