I sometimes want to pick a range of commits from a different repository. I know two ways to do that.
1.
git checkout myBranch
git cherry-pick begin..end
or
git rebase --onto myBranch begin end
I find the first version easier to remember. However, I read a lot about how cherry-picking is evil compared to merging because it kinda breaks the history. But what I haven't figured out yet is if there is a difference between cherry-picking a range of commits or rebasing them with --onto
I tend to think that there shouldn't be a difference. Am I mistaken?
Note: as of Git 2.9. x/2.10 (Q3 2016), you can cherry-pick a range of commit directly on an orphan branch (empty head): see "How to make existing branch an orphan in git". A rebase --onto would be better, where you replay the given range of commit on top of your integration branch, as Charles Bailey described here.
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.
Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes. For example, say a commit is accidently made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.
The git cherry-pick is a very useful command. It takes changes from a specific commit and applies them to your current branch in a new commit. As a consequence, git cherry pick does not alter your current Git history : instead it adds commits to it.
These two commands are equivalent, you're just doing the work that a normal rebase would do to figure out the unmerged commits to replay onto the target branch.
Rebasing and cherry-picking are just as 'bad' for merges. They both result in forgetting the IDs of the original commits for the changes you pick up; as a result, later merges may attempt to apply the same changes more than once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With