Cherry-pick
A git command that copies the change from one commit onto another branch as a new commit, such as a fix from main onto release/1.4, without the commits around it. The copy gets a new hash, so the same change now exists twice in history; git cherry-pick -x adds a "cherry picked from commit" line to the message so you can trace it back. If the commit builds on earlier commits the branch doesn't have, the pick may conflict, or apply cleanly and then fail the build, so pick those commits too or fix the code by hand, and run the tests.
Cherry-pick the fix copies one commit from main onto release/1.4 as a new commit with a new hash. Cherry-pick E (needs D) tries E alone: it changes lines D added, so on release/1.4, which lacks D, it conflicts.
Chips are commits, newest on the right.
Commits on main: 6 · on release/1.4: 3 · Picked: 0 · Conflicts: 0
release/1.4 needs the fix F from main, but not the features D and E.
Say it in a prompt
Fix the rounding bug on main first as one small commit, then copy only that commit to release/1.4 with git cherry-pick -x <hash>, so the new commit's message says which commit it came from. Don't merge main into the release, since that would bring the unfinished features too. If the pick conflicts because the fix needs an earlier commit, stop with git cherry-pick --abort and tell me which commit it needs. Even when it applies cleanly, run the tests on release/1.4 before tagging v1.4.1, since a missing earlier commit can break the build without a conflict. Vague vs precise prompt
Vague prompt
get the fix into the release Typical resultMerges main into the release branch. The fix arrives, but so do the unfinished feature commits next to it, and the release now ships code nobody tested for it.
Precise prompt
Copy only commit f7e2a10, the rounding fix, from main to release/1.4 with git cherry-pick -x, so the new commit's message records where it came from. Don't merge main. If it conflicts because it needs an earlier commit, abort with git cherry-pick --abort and tell me which commit it needs. Typical resultrelease/1.4 gets one new commit with the fix and a new hash, plus a "cherry picked from commit f7e2a10" line, and the features stay on main. The same change now exists twice with two hashes, so git log on each branch shows a different id for it.
Seen on
- Git documentation, git-cherry-pick: Applies the changes introduced by existing commits and records a new commit for each. The -x option appends a "(cherry picked from commit …)" line to the message; on a conflict you resolve it, then git cherry-pick --continue, or --abort to go back.
- trunkbaseddevelopment.com, Branch for release: A bug found in a release is fixed on trunk first, then cherry-picked to the release branch, and CI checks it there too. Fixes go one way only, from trunk to the release branch.
- Martin Fowler, Patterns for Managing Source Code Branches: Describes a cherry-pick as copying a commit from one branch to another without merging the branches, and warns that copied fixes are easy to forget and get harder to copy as branches drift apart.
You might describe it as
- copy just that one fix onto the release
- take one commit from main without the rest
- backport the fix to the 1.4 branch
Not to be confused with
- Release branch
Cherry-pick is one git command that copies a single commit onto another branch as a new commit; a release branch is the line for one release that those copied fixes often land on.