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-pick one by one c
to f
and rebase 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 (thanks JJD):
Git 1.7.2 introduced the ability to cherrypick a range of commits. From the release notes:
You can use a serial combination of
git rebase
andgit branch
to apply a group of commits onto another branch. As already posted by wolfc the first command actually copies the commits. However, the change is not visible until you add a branch name to the top most commit of the group.Please open the picture in a new tab ...
To summarize the commands in text form:
gitk --all &
.git rebase --onto a b f
.HEAD
is marked.git branch selection
This should clarify things:
a
is the new root destination of the group.b
is the commit before the first commit of the group (exclusive).f
is the last commit of the group (inclusive).Afterwards, you could use
git checkout feature && git reset --hard b
to delete the commitsc
tillf
from thefeature
branch.In addition to this answer, I wrote a blog post which describes the commands in another scenario which should help to generally use it.
The simplest way to do this is with the
onto
option torebase
. Suppose that the branch which current finishes ata
is called mybranch and this is the branch that you want to movec
-f
onto.If you have selective revisions to merge, say A, C, F, J from A,B,C,D,E,F,G,H,I,J commits, simply use below command: