Skip to content

Instantly share code, notes, and snippets.

@Lumbe
Last active November 15, 2016 14:11
Show Gist options
  • Save Lumbe/caeec05da38ba5cc0b07c5d2735827c4 to your computer and use it in GitHub Desktop.
Save Lumbe/caeec05da38ba5cc0b07c5d2735827c4 to your computer and use it in GitHub Desktop.
How to merge a specific commit in git

How to merge a specific commit in git

Scenario

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.

Solution

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.

original

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment