git cherry-pick [<options>] <commit-ish>... options: --quit quit current chery-pick sequence --continuecontinue current chery-pick sequence --abort abort current chery-pick sequence,restore current branch -n, --no-commit not auto-commit, changes will be implemnted on branch1 but need commit manually -e, --edit edit commit message
There two branch- branch1 and branch2 in local repostory, check the commit logs of each branch first:
Now, we want pick up one commit on branch2, and merge it to branch1, we can use cherry-pick command:
1 2 3 4 5
$ git cherry-pick 2555c6e error: could not apply 2555c6e... [Description]:branch2 commit 2 hint: after resolving the conflicts, mark the corrected paths hint: with 'git add <paths>' or 'git rm <paths>' hint: and commit the result with 'git commit'
If no conflicts, above command will finish the process and success. If conflict happens, like above hint, we need to resolve the conflicts first, then use git commit to commit manually:
Or use git add. to mark we have reloved the conflicts, and then git cherry-pick –continue to continue the cherry-pick. Finally, check the commit log of branch1, we can see the target commit show on branch1.
1 2 3 4
$ git log --oneline -3 790f431 [Description]:branch2 commit 2 20fe2f9 commit second c51adbe commit first