What does git cherry-pick <commit> do?
Options
- Deletes a commit from the history of the branch
- Applies one commit from another branch onto yours (Correct option)
- Merges the entire other branch into your branch
- Renames the current branch in the local repository
Answer
Applies the changes of one specific commit from another branch onto your current branch as a new commit
Why
Sometimes you want just ONE commit from another branch, for example a bug fix made on develop that must also go to release/1.2.
git cherry-pick <hash> copies that commit's changes onto your current branch, creating a new commit with a different hash.
Use it sparingly: duplicated commits can confuse history later.
Remember
cherry-pick = copy one commit to here.