Cherry-picking commits in Git is easy and straightforward, here’s how to do that.
Take two branches:
master, now we want to get one commit from
$ git checkout new-feature
And see what commits have been issued in the past:
$ git log commit 0b5e336cccf6b89894894b921d4858bb34417e02 Author: bob <email@example.com> Date: Mon Apr 6 00:10:42 2015 +0200 Tweaks commit cbc51480ea42dcc91deec8d8a30fbddc37d9b6d3 Author: bob <firstname.lastname@example.org> Date: Sun Mar 1 12:37:11 2015 +0100 Change button color.
There seems to be two commits: "Tweaks" and "Change button color."
Maybe you need the "Tweaks" commit in the other branch, note down the commit hash. In this case it’s
The checkout the branch you want to put it in, and cherry-pick it:
$ git checkout master $ git cherry-pick 0b5e336cccf6b89894894b921d4858bb34417e02
It can be that the same file was edited in the other branch, then you might hit a merge conflict. If you do, first check the status of your repo:
$ git status
You’ll see all the files that are not added to the staging area, those are the ones with merge conflicts. Manually solve the conflicts, save the files, and then:
$ git add -A $ git cherry-pick ---continue
That’s the exact same workflow as you would have when solving merge conflicts when rebasing.
Comments would go here, but the commenting system isn’t ready yet, sorry. Tweet me @hiljaa if you want to make a correction etc.