Search code examples
gitgit-rebasecherry-pick

Does picking a range of commits with cherry-pick or rebase --onto end up with the same result?


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

  1. 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?


Solution

  • 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.