How to cherry-pick multiple commits -git cherry pick multiple commits

686    Asked by AnkitChauhan in Devops , Asked on Jun 8, 2021

I have two branches. Commit a is the head of one, while the other has b, c, d, e and f on top of a. I want to move c, d, e and f to first branch without commit b. Using cherry-pick it is easy: checkout first branch cherry-picks one by one c to f and rebase the second branch onto first. But is there any way to cherry-pick all c-f in one command?

Here is a visual description of the scenario:



Answered by Charles Parr

According to git release note 1.7.2, it says that

* "git cherry-pick" learned to pick a range of commits(e.g. "cherry-pick A..B" and "cherry-pick --stdin"), so did "gitrevert"; these do not support the nicer sequencing control "rebase[-i]" has, though.
And there are certain things to take care of those are

1: A should be older than B. If they're in the wrong order the command will fail.

2: Also, this will cherry pick multiple commits all except A including B.

3: To include A just type

  git cherry-pick A^..B


Your Answer

Interviews

Parent Categories