Sometimes overuse of git cherry-pick command leads to the situation, where actual difference between two branches is no longer the one you see in git log branch1..branch2
.
For example, if repo has two branches: master
and experimental
. Master
’s history looks like this:
And experimental’s:
Now let’s cherry-pick one commit to the master branch:
Note that new commit has a different SHA-1 now, because cherry-pick
“applies changes introduced by some existing commits”, not moves commit object itself. So now if we try to see what’s new in experimental
branch compared to master
brach using git log
, we get this:
There’s no difference between “First experimental commit” and “Second experimental commit” though changes presented by one of them is already in the master
. But git cherry
command can show that difference.
+ means that “upstream” (in this case master
branch) lacks both commit object and it’s changes. - tells us that changes of this commit are represented by a different commit object in “upstream”.
Now a little more about command syntax:
The first argument (optional, defaults to the branch’s remote) is upstream. There’s a lot of confusion about this term, so I would recommend this question on StackOverflow. In this case upstream is simply a branch in which you want to know what commits from another branch (head) are present. The second argument “head” is also optional and defaults to current HEAD.