Cherry-pick
A Git command that applies changes from selected commits to the branch you are on. It lets you bring over a specific fix without merging the entire source branch.
When you would use it
Say a bug fix has landed on main, but the team still ships patches for version 1.4. Merging main into the maintenance branch would also bring in work intended for the next release. git cherry-pick lets you take just the fix. This is a common way to backport a change to an older supported version.
What Git actually copies
For an ordinary commit, Git looks at what changed between that commit and its parent, then applies those changes on top of your current HEAD. By default it records the result as a new commit. The original author and message are usually retained, but the new commit normally has a different parent and therefore a different ID. The source branch is left alone, and the original commit does not become part of the target branch's ancestry just because its changes are there.
That last point is the key difference from a merge. A merge brings branch histories together; a cherry-pick transfers selected changes without joining those histories. Rebase also replays changes, but its usual purpose is to put a sequence of commits onto a new base rather than to bring a particular fix into a maintenance branch.
Example: backport one fix
Start with a clean working tree and check out the branch that should receive the fix. Here a1b2c3d is the ID of the commit you want:
git switch release/1.4
git cherry-pick -x a1b2c3d
For a conflict-free pick, -x adds the original commit ID to the new commit message. That makes it easier to trace the backport when the same fix is maintained across several releases.
If Git stops on a conflict, use git status to see which files need attention. Resolve the conflicts, stage the resolved files with git add, and run git cherry-pick --continue. To abandon the operation and restore the state from before it started, run git cherry-pick --abort while the operation is still in progress.
A clean apply is not a passing test
Git can apply a patch without a conflict even if it calls a helper that does not exist on the older branch. Review what the fix depends on and run the relevant tests on the receiving branch. If the fix needs several commits, apply the prerequisites first. If you find yourself selecting most of a branch, reconsider whether a merge would better reflect what you intend to integrate.
What interviewers look for
A typical prompt is: “How would you ship one fix from main without shipping the unfinished features next to it?” Explain which branch you would check out, which commit ID you would pass, and how you would verify the backport. If asked why the ID changes, point to the new parent rather than saying Git simply renames the old commit.