Junior — Middle
Can you explain how the cherry-pick command works in Git version control system?
sobes.tech AI
Answer from AI
The git cherry-pick command allows you to apply a specific commit from one branch to another by copying the changes of that commit without merging the entire branch. This is useful when you need to transfer individual fixes or features.
Working principle:
- You specify the hash of the commit you want to transfer.
- Git applies the changes of that commit on top of the current branch, creating a new commit with the same content.
Example of usage:
git checkout feature-branch
# transfer commit with hash abc123 from master
git cherry-pick abc123
If conflicts occur, they need to be resolved manually, then execute git cherry-pick --continue. This allows selectively transferring changes without a full branch merge.