Cliffnotes version
git cherry-pick ABC..XYZ
. I want ABC
to be included in my commits to the current branch. Do I have to reference the commit before ABC
?Long Version
master
, Apple
and NewApple
.Apple
was built upon a very old version of master
but only worked on a dozen files which were implemented on folders which the rest of the master
did not really touch.Apple
has commits ABC
, BCD
, and XYZ
. These are commits unique to Apple
. Please note there are about 10 commits between BCD
and XYZ. These commits were NEVER commited to
master`NewApple
which is spun off of a newer versions of master
, ones with newer commits.Apple
to put onto NewApple
like so git cherry-pick ABC..XYZ
ABC
was not included. Everything after it and including XYZ
were put onto NewApple
.ABC
as part of my cherry-pick without referencing the commit that is before it in Apple
. I am afraid that if I do, I won't get all the commits in Apple
or it will try to merge in random older master
commits on top of newer versions of master....
git cherry-pick ABC..XYZ
[but] I wantABC
to be included in my commits to the current branch. Do I have to reference the commit beforeABC
?
Short answer: yes.
Longer variety of answer: Git has a syntax for that, since it's such a common requirement. Any name suitable for identifying one specific commit, such as master
or a123456
, can be suffixed with ^
or ~
characters followed by numbers. The default number is just 1, and hence:
master^
or
master~
means "the commit before the one selected by the name master
".
In this case, then, you might write:
git cherry-pick ABC^..XYZ
Note that Windows-y command line interpreters tend to treat ^
as an escape character, requiring entering the command using ABC^^..XYZ
or "ABC^..XYZ"
, so there you might prefer ~
. Either one works here.
(More specifically, ^number
means the number-th parent, while ~number
tells Git to count back that many first-parents. So master~3
means the same as master^1^1^1
. Since 1
is the default number, you can write this as master^^^
as well. There are many more ways to identify commits, all outlined in the gitrevisions documentation.)