When to use cherry-pick
- Always try to not to use cherry-pick because it can make a duplicate commit.
- If you have already committed something on another branch, you can pick it and merge it with your working branch. Example: you may need a hotfix commit from another branch.
- Restoring lost comments. Sometimes a pull request might get closed without merging. But you can see those commit in the git log. So you can cherry-pick them
Checkout to the branch that has the required commit. Then get git hash of that commit by using CLI or Github site
git log --oneline git reflog
or you can view your git as a graph
git log --graph --oneline --all
Checkout to the brach that you want to add the commit. Enter the following command.
git cherry-pick commit-id. example:
git cherry-pick c67a4b7
if you want to add only the content without commit. You can add
git cherry-pick c67a4b7 --no-commit