GIT-CHERRY-PICK(1)
π GIT-CHERRY-PICK(1) π
okay bestie, so this is from the Git Manual and honestly it's giving "I want THAT commit but on MY branch" energy and we're obsessed πβ¨
β¨ NAME β¨
git-cherry-pick β apply the changes introduced by some existing commits. literally picking cherries off one branch and dropping them onto another, slay π
πΈ SYNOPSIS πΈ
git cherry-pick [--edit] [-n] [-m <parent-number>] [-s] [-x] [--ff]
[-S[<keyid>]] <commit>...
git cherry-pick (--continue | --skip | --abort | --quit)
π¦ DESCRIPTION π¦
So picture this: you give it one or more existing commits, and it applies the change each one introduces, recording a brand new commit for each. main character behavior fr fr. π
lowkey important: this requires your working tree to be clean (no modifications from the HEAD commit). no cap.
When it's not obvious how to apply a change, here's the whole dramatic sequence that goes down:
- The current branch and
HEADpointer stay at the last commit successfully made. - The
CHERRY_PICK_HEADref is set to point at the commit that introduced the change that is difficult to apply β unless the--no-commitoption was given. - Paths in which the change applied cleanly are updated both in the index file and in your working tree.
- For conflicting paths, the index file records up to three versions, as described in the "TRUE MERGE" section of
git-merge(1). The working tree files will include a description of the conflict bracketed by the usual conflict markers<<<<<<<and>>>>>>>. - No other modifications are made.
See git-merge(1) for some hints on resolving such conflicts. you got this π«Ά
π OPTIONS π
<commit>...β the commits to cherry-pick. For a more complete list of ways to spell commits, seegitrevisions(7). Sets of commits can be passed but no traversal is done by default, as if the--no-walkoption was specified, seegit-rev-list(1). Note that specifying a range will feed all<commit>...arguments to a single revision walk (see a later example that usesmaint master..next). iykyk π-e,--editβ with this option,git cherry-pickwill let you edit the commit message prior to committing. your words, your vibe π--cleanup=<mode>β this option determines how the commit message will be cleaned up before being passed on to the commit machinery. Seegit-commit(1)for more details. In particular, if the<mode>is given a value ofscissors,scissorswill be appended toMERGE_MSGbefore being passed on in the case of a conflict. βοΈ iconic honestly-xβ when recording the commit, append a line that says"(cherry picked from commit ...)"to the original commit message in order to indicate which commit this change was cherry-picked from. This is done only for cherry picks without conflicts. Do not use this option if you are cherry-picking from your private branch because the information is useless to the recipient. If on the other hand you are cherry-picking between two publicly visible branches (e.g. backporting a fix to a maintenance branch for an older release from a development branch), adding this information can be useful. receipt-keeping behavior ngl π§Ύ-rβ it used to be that the command defaulted to do-xdescribed above, and-rwas to disable it. Now the default is not to do-xso this option is a no-op. π rip bozo-m <parent-number>,--mainline <parent-number>β usually you cannot cherry-pick a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from1) of the mainline and allows cherry-pick to replay the change relative to the specified parent. pick a side bestie π-n,--no-commitβ usually the command automatically creates a sequence of commits. This flag applies the changes necessary to cherry-pick each named commit to your working tree and the index, without making any commit. In addition, when this option is used, your index does not have to match theHEADcommit. The cherry-pick is done against the beginning state of your index.
This is useful when cherry-picking more than one commits' effect to your index in a row.
This option does not recordCHERRY_PICK_HEAD, so a plaingit commitafterwards records you as the author. That is by design: what you are building is your own work, which you keep changing before committing, rather than a reproduction of the original commit. main character energy for real π«Άβ¨
-s,--signoffβ add aSigned-off-bytrailer at the end of the commit message. See thesignoffoption ingit-commit(1)for more information.-S[<keyid>],--gpg-sign[=<keyid>],--no-gpg-signβ GPG-sign commits. Thekeyidargument is optional and defaults to the committer identity; if specified, it must be stuck to the option without a space.--no-gpg-signis useful to countermand bothcommit.gpgSignconfiguration variable, and earlier--gpg-sign. π secure the bag--ffβ if the currentHEADis the same as the parent of the cherry-pick'ed commit, then a fast forward to this commit will be performed. zoom zoom β‘--allow-emptyβ by default, cherry-picking an empty commit will fail, indicating that an explicit invocation ofgit commit --allow-emptyis required. This option overrides that behavior, allowing empty commits to be preserved automatically in a cherry-pick. Note that when"--ff"is in effect, empty commits that meet the "fast-forward" requirement will be kept even without this option. Note also, that use of this option only keeps commits that were initially empty (i.e. the commit recorded the same tree as its parent). Commits which are made empty due to a previous commit will cause the cherry-pick to fail. To force the inclusion of those commits, use--empty=keep. read that twice bestie, it's a whole thing π--allow-empty-messageβ by default, cherry-picking a commit with an empty message will fail. This option overrides that behavior, allowing commits with empty messages to be cherry picked. no thoughts head empty π«§--empty=(drop|keep|stop)β how to handle commits being cherry-picked that are redundant with changes already in the current history.dropβ the commit will be dropped. ποΈkeepβ the commit will be kept. Implies--allow-empty. πstopβ the cherry-pick will stop when the commit is applied, allowing you to examine the commit. This is the default behavior. β
Note that--empty=dropand--empty=stoponly specify how to handle a commit that was not initially empty, but rather became empty due to a previous commit. Commits that were initially empty will still cause the cherry-pick to fail unless one of--empty=keepor--allow-emptyare specified.
--keep-redundant-commitsβ deprecated synonym for--empty=keep. it's giving legacy π°οΈ--strategy=<strategy>β use the given merge strategy. Should only be used once. See the MERGE STRATEGIES section ingit-merge(1)for details.-X<option>,--strategy-option=<option>β pass the merge strategy-specific option through to the merge strategy. Seegit-merge(1)for details.--rerere-autoupdate,--no-rerere-autoupdateβ after the rerere mechanism reuses a recorded resolution on the current conflict to update the files in the working tree, allow it to also update the index with the result of resolution.--no-rerere-autoupdateis a good way to double-check whatgit-rerere(1)did and catch potential mismerges, before committing the result to the index with a separategit-add(1). double-check queen behavior π
π§ SEQUENCER SUBCOMMANDS π§
--continueβ continue the operation in progress using the information in.git/sequencer. Can be used to continue after resolving conflicts in a failed cherry-pick or revert. pick yourself back up bestie πͺ--skipβ skip the current commit and continue with the rest of the sequence. not me, not today π--quitβ forget about the current operation in progress. Can be used to clear the sequencer state after a failed cherry-pick or revert. moving on periodt π--abortβ cancel the operation and return to the pre-sequence state. nope out of there πͺ
π EXAMPLES π
git cherry-pick masterβ apply the change introduced by the commit at the tip of themasterbranch and create a new commit with this change.git cherry-pick ..master,git cherry-pick ^HEAD masterβ apply the changes introduced by all commits that are ancestors ofmasterbut not ofHEADto produce new commits.git cherry-pick maint next ^master,git cherry-pick maint master..nextβ apply the changes introduced by all commits that are ancestors ofmaintornext, but notmasteror any of its ancestors. Note that the latter does not meanmaintand everything betweenmasterandnext; specifically,maintwill not be used if it is included inmaster. tricky tricky πgit cherry-pick master~4 master~2β apply the changes introduced by the fifth and third last commits pointed to bymasterand create 2 new commits with these changes.git cherry-pick -n master~1 nextβ apply to the working tree and the index the changes introduced by the second last commit pointed to bymasterand by the last commit pointed to bynext, but do not create any commit with these changes.git cherry-pick --ff ..nextβ if history is linear andHEADis an ancestor ofnext, update the working tree and advance theHEADpointer to matchnext. Otherwise, apply the changes introduced by those commits that are innextbut notHEADto the current branch, creating a new commit for each new change.git rev-list --reverse master -- README | git cherry-pick -n --stdinβ apply the changes introduced by all commits on themasterbranch that touchedREADMEto the working tree and index, so the result can be inspected and made into a single new commit if suitable. pipeline slay π₯
The following sequence attempts to backport a patch, bails out because the code the patch applies to has changed too much, and then tries again, this time exercising more care about matching up context lines. we love a resilient queen π«Ά
$ git cherry-pick topic^ (1)
$ git diff (2)
$ git cherry-pick --abort (3)
$ git cherry-pick -Xpatience topic^ (4)
- apply the change that would be shown by
git show topic^. In this example, the patch does not apply cleanly, so information about the conflict is written to the index and working tree and no new commit results. - summarize changes to be reconciled
- cancel the cherry-pick. In other words, return to the pre-cherry-pick state, preserving any local modifications you had in the working tree.
- try to apply the change introduced by
topic^again, spending extra time to avoid mistakes based on incorrectly matching context lines.
π SEE ALSO π
π GIT π
Part of the git(1) suite. one big happy family π
and that's the whole vibe bestie π this little page is brought to you by Git 2.56.0, dated 2026-09-27 β go forth and cherry-pick responsibly, mwah πβ¨π
π¦ where this page comes from
- arch rolling: git 2.56.0-1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms