HG(GRAFT)
β¨ HG(GRAFT) β¨
okay bestie, buckle up, we're talking about hg graft from the Mercurial manual β it's giving time-travel-for-commits and honestly? iconic. π¦
πΈ NAME πΈ
hg graft β copy changes from other branches onto the current branch π
π SYNOPSIS π
hg graft [OPTION]... [-r REV]... REV...
π¦ DESCRIPTION π¦
so like, this command uses Mercurial's merge logic to copy individual changes from other branches without merging the branches in the history graph. you may know this vibe by its other names: 'backporting' or 'cherry-picking'. π by default, graft will copy user, date, and description from the source changesets. no cap.
changesets that are ancestors of the current revision, that have already been grafted, or that are merges will be skipped. bye bestie π
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. lowkey a rescue mission π«Ά
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 drama.
the -c/--continue option reapplies all the earlier options. periodt.
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. main character energy honestly π
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. iykyk π
the experimental --to option allows grafting a revision in-memory, independent of the working copy. merge conflicts are not currently supported, and the operation will be aborted if the configured tool cannot handle the conflicts that might be encountered. β οΈ
as the operation is performed in-memory, the on-disk files will not be modified, and some hooks might not be run. noted.
π 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. slay.
π OPTIONS π
-r,--rev <REV[+]>β revisions to graft π±--base <REV>β base revision when doing the graft merge (ADVANCED) π₯--to <VALUE>β graft to this destination, in-memory (EXPERIMENTAL) π§ͺ-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 π
[+] marked option can be specified multiple times β
and that's the whole page, bestie!! π the footer of this manual just says hg graft again β HG(GRAFT) β no extra version or date tea spilled, so that's all we've got. go forth and graft responsibly. π β¨π¦πΈπ
π¦ where this page comes from
- arch rolling: mercurial 7.2.4-1 Β· GPL
- fedora 43: mercurial 7.1.1-1.fc43 Β· GPL-2.0-or-later
- fedora 43: mercurial 7.1.1-2.fc43 Β· GPL-2.0-or-later
- fedora 44: mercurial 7.2-1.fc44 Β· GPL-2.0-or-later
- fedora 44: mercurial 7.2.4-1.fc44 Β· GPL-2.0-or-later
- nixos 26.05: mercurial 7.1.2
- nixos 26.05: mercurial-full 7.1.2
- nixpkgs unstable: mercurial 7.2.2
- nixpkgs unstable: mercurial-full 7.2.2
- opensuse-leap 16.0: mercurial 7.0.1-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: mercurial 7.0.1-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: mercurial 7.0.1-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: mercurial 7.0.1-160000.2.2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms