I am Hack Sparrow
Captain of the Internets.

How to merge a specific commit in git


You were working on a certain branch of a git repository, and you committed some changes to it. Then you realize, this particular commit should also go to another branch of the repository BUT you are not ready for a complete merge. Maybe this commit was meant for the other branch?

You want to merge this particular commit from the current branch to the other branch of your requirement.


Merging a specific commit from one branch to another is pretty easy: use the git cherry-pick command. The syntax is: git cherry-pick <commit hash>.

First make a note of the commit hash using the git reflog or git log command.

Then, switch to the branch where you'd like to merge the commit and run git cherry-pick with the commit hash, as shown in the example below.

$ git cherry-pick d4d8e7c

Now you will have merged the specific commit from one branch to the other.

3 Responses to “How to merge a specific commit in git”

  1. Piotr Gajos says:

    Very helpful, thank you. I will definitely use this information when cooking dinner tonight!

  2. Captain says:

    Hahaha. Dude, why are you even here?

  3. João Pedro Alves says:

    Thank you so much for this contribution. It really saved my life 😉

Make a Comment