SteelReed

Search

Search posts, questions…

DevOps & CloudQuestion 5 / 35

Junior

What is git cherry-pick, how do you use it, and when should you avoid it?

Short answer

git cherry-pick <commit> takes one commit's diff against its parent and applies it to the current branch as a new commit (different hash). Use it when you need a few specific commits, such as bringing a hotfix from main to a release branch, not to keep two branches in sync.

git cherry-pick -x Fnoyesgive upmain: bug-fix commit Frelease: commit F' newhashConflict?DoneFix, git addcherry-pick --continuecherry-pick --abort

3 points to say:

  1. Cherry-pick copies a change into a new commit with a new hash; the original stays on its branch.
  2. Use -x to record the source; A^..B to include A; on conflict, --continue, --skip, --abort.
  3. Fix on main, then pick down to release, so the fix is never forgotten; for regular bulk syncing use merge or rebase.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.