glossary

Git Cherry-pick

A git command that applies the changes introduced by one or more existing commits from any branch onto the current HEAD, creating a new commit with the same changes but a different hash.

Cherry-picking is the surgical alternative to merging or rebasing entire branches. Instead of bringing every commit from a branch, exactly one commit is selected and its changes are applied to the current position. This is invaluable for hotfix backporting, where a fix committed on the main branch needs to be applied to a release branch without bringing the intervening feature commits. The command takes a commit hash and replays the diff of that commit against the current HEAD. If the diff applies cleanly, a new commit with the same author and message (by default) is created. If conflicts arise, they are resolved the same way as merge conflicts. Cherry-picking copies changes rather than moving them. The original commit remains in its source branch. This means cherry-picking the same commit to multiple branches creates multiple copies of the change, each with a different hash. For tracking purposes, git cherry-pick automatically appends the original commit hash to the cherry-picked message.

git cherry-pick abc1234 # apply commit abc1234 to current HEAD
git cherry-pick abc1234..def5678 # apply a range of commits
git cherry-pick -n abc1234 # apply changes without committing (--no-commit)
git cherry-pick --continue # continue after resolving conflicts
git cherry-pick --abort # abort the cherry-pick in progress

git-agent's consistent commit format makes cherry-pick source selection easier: each commit's subject line clearly states what it does, so you can identify the right commit to cherry-pick without reading the full diff. The structured messages also help downstream tools track cherry-picked commits across release branches.

brew install gitagenthq/brew/git-agent
Can cherry-picking introduce merge conflicts?
Yes. If the context around the cherry-picked changes differs between the source and target branches, conflicts can arise. They are resolved identically to merge conflict resolution.
Does git-agent support cherry-picking?
git-agent focuses on commit authoring, not cherry-pick execution. However, the well-structured commits it produces make cherry-pick selection easier because each commit's scope and purpose are immediately clear from its message.
What is the difference between cherry-pick and rebase --onto?
rebase --onto replays a range of commits onto a different base, used for transplanting entire sequences. cherry-pick is for individual commits. Rebase also preserves the original commit order, while cherry-pick applies commits in the order you specify them.