I have recently started working with Git.
Going over the Git book online I found the following under the \"Git Rebase\" section:
With the reba
Both do very similar things; the main conceptual difference is (in simplified terms) that:
rebase moves commits from the current branch to another branch.
cherry-pick copies commits from another branch to the current branch.
Using diagrams similar to @Kenny Ho's answer:
Given this initial state:
A---B---C---D master
\
E---F---G topic
...and assuming that you want get the commits from the topic branch replayed on top of the current master branch, you have two options:
Using rebase: You'd first go to topic by doing git checkout topic, and then move the branch by running git rebase master, producing:
A---B---C---D master
\
E'---F'---G' topic
Result: your current branch topic was rebased (moved) onto master.
The topic branch was updated, while the master branch remained in place.
Using cherry-pick: you'd first go to master by doing git checkout master, and then copy the branch by running git cherry-pick topic~3..topic (or, equivalently, git cherry-pick B..G), producing:
A---B---C---D---E'---F'---G' master
\
E---F---G topic
Result: the commits from topic were copied into master.
The master branch was updated, while the topic branch remained in place.
Of course, here you had to explicitly tell cherry-pick to pick a sequence of commits, using the range notation foo..bar. If you had simply passed the branch name, as in git cherry-pick topic, it would have picked up only the commit at the tip of the branch, resulting in:
A---B---C---D---G' master
\
E---F---G topic