Introduction
The cherry-pick command involves copying one or more revisions ("commits") from one branch (the source) and placing them onto another branch (the target), assigning a new revision identifier (SHA) in the process.
Example
Let's assume we have two branches - the first one called "main" (orange), which contains three files: a.txt, b.txt, c.txt. Each file created in a different revision
The second "feature" branch (green) contains two files: d.txt and e.txt, also created in separate "commits".
To move only selected commits from the "main" branch to the "feature" branch, execute two commands.
The first command goes to the target branch to which the changes will be transferred ("feature" as an example):
git checkout feature
The second command performs a copy&move operation of selected commits based on identifiers (SHA):
git cherry-pick 76b6ffa e733f01
The first revision 76b6ffa represents a new a.txt file, the second e733f01 is a b.txt file.
Result after executing the command:
The "feature" branch now contains two new commits moved from the "main" branch. Notice that the copied commits have been given a new SHA ID!
Remark
Note that cherry-picking can lead to conflicts, especially when changes to the source branch conflict with already existing changes to the target branch. In this case, Git will inform you about the conflict, which must be resolved manually.
Good luck!