Cherry-picking is a powerful Git technique that allows you to apply a specific commit from one branch onto another without merging all the changes from the source branch. This method is especially useful when you need an isolated change from another branch without incorporating all of its commits.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
When to Use Cherry-Picking
If you’re working on the master branch and identify a single commit in a feature branch (for example, the Sarah branch) that introduces a vital fix or enhancement, cherry-picking enables you to import that specific change without merging the entirety of the feature branch.Before proceeding with cherry-picking, ensure that your target branch is up-to-date and that you understand how the changes from the commit will integrate with your current code base.
How to Cherry-Pick a Commit
To cherry-pick a commit, you’ll use the commit’s unique hash value. In the scenario where you wish to apply the changes from a commit on the Sarah branch to your master branch, follow these steps:- Switch to your master branch.
- Execute the cherry-pick command with the hash of the desired commit.
aaba5:
Cherry-picking only transfers the changes from the specified commit. Other commits and modifications from the source branch remain separate.