git cherry-pick allows you to append arbitrary Git commits to the current
HEAD based on their hash value. Cherry-picking is selecting a commit from one
branch and applying it to another, for example:
$ git checkout 3.10 $ git cherry-pick 61de025 [3.10 b600967] Fix bug #17 Date: Thu Sep 15 11:17:35 2022 +0200 1 file changed, 9 insertions(+)
git cherry-pick can be used with different options:
does not take over the existing commit message but allows you to create your own commit message for this cherry-pick.
does not create a new commit but moves the contents of the commit to the working directory.
adds a signature line with
signed-off-byat the end of the commit message.
git cherry-pick also accepts options to resolve merge conflicts, including
git cherry-pick can be useful for reverting changes, for example if a commit
was accidentally made to the wrong branch, you can switch to the branch where the
change was supposed to be made and then cherry-pick the commit to that branch.
However, cherry-picking usually results in duplicate commits, and in many cases
we prefer to use git merges. Nevertheless,
git cherry-pick can be very
suitable for some scenarios, for example Release branches workflows.