Git cherry picking

March 20, 2015 - 17:12

Git is a control system for developing softwares. There are a number of git commands (Git reference). While searching bringing a commit from one branch to another, I came across an interesting topic called cherry picking. Cherry pick a commit? Sounds interesting!!!

I have researched a bit to let know whether it would fit my context or not.

Git Cherry pick

This command is those cases, where we wanted to bring the commits from a particular branch to another. General syntax for cherry picking a particular commit is,

git cherry-pick commit_hash_id

Let us consider we have 3 branches as A, B, and C along with a master. Suppose, we would like to bring the last commit from branch C to B. In this case, make sure that we are the branch were we would like to bring the commit to. In this scenario, make sure you are on branch B, as we are planning to bring the commit from C to B.

Now, a question can arise for those who is not very good with git. Don't we mention the branch from were the git commit to be taken? Nice question!!

Why we need to specify that, as the hash code for every commit is unique. So we don't want to mention the branch from where we take commit. Git is an interesting software to explore, every day we see new commands to get the new functionalities integrated to it.

Post your comments / questions