I\'ve got two branches from my master:
git cherry-pick
: Apply the changes introduced by some existing commits
Assume we have branch A with (X, Y, Z) commits. We need to add these commits to branch B. We are going to use the cherry-pick
operations.
When we use cherry-pick
, we should add commits on branch B in the same chronological order that the commits appear in Branch A.
cherry-pick does support a range of commits, but if you have merge commits in that range, it gets really complicated
git checkout B
git cherry-pick SHA-COMMIT-X
git cherry-pick SHA-COMMIT-Y
git cherry-pick SHA-COMMIT-Z
Example of workflow :
We can use cherry-pick
with options
-e or --edit : With this option, git cherry-pick will let you edit the commit message prior to committing.
-n or --no-commit : Usually the command automatically creates a sequence of commits. This flag applies the changes necessary to cherry-pick each named commit to your working tree and the index, without making any commit. In addition, when this option is used, your index does not have to match the HEAD commit. The cherry-pick is done against the beginning state of your index.
Here an interesting article concerning cherry-pick
.