- Cherry-picking copies the some commit information and changes from one branch into another branch.
- It will create new commit and adds the changes/information
- In case you made a mistake and committed a change into the wrong branch, but do not want to merge the whole branch. You can revert the commit and apply it on another branch.
Explaining with an example:
Copying specific commit from feature-1 branch to master branch using Git cherry-pick
Master branch :
Feature branch :
Steps :
(i). Checkout to a particular branch : git checkout master
(ii). Command : git cherry-pick <commit-id>
(iii)To get commit id by this command : git log –oneline
Observations:
(i) Specific commit added to master from feature-1 branch as latest commit
(ii) We can see commit-hash of feature-1 is a5dee03 and the commit hash in the master is 64bd9e7
That means it creates a new commit and copies the files/changes/information