Git: move commits between branches with cherry-pick
Cherry-picking in Git is trivial, it's as easy and logical as it should be.
Basic usage of cherry-pick
Let’s imagine two branches
master, now we want to get one commit from
$ git checkout new-feature # Log your commits $ git log commit 0b5e336cccf6b89894894b921d4858bb34417e02 Author: hilja <firstname.lastname@example.org> Date: Mon Apr 6 00:10:42 2015 +0200 Tweaks commit cbc51480ea42dcc91deec8d8a30fbddc37d9b6d3 Author: hilja <email@example.com> Date: Sun Mar 1 12:37:11 2015 +0100 On a steady trajectory to more modular site.
Say, you want the “Tweaks” commit, copy the wanted commit ID (git-ish), in this case it’s
$ git checkout master $ git cherry-pick <commit ID>
It’s that simple.
If you hit a merge conflict, check the status of your repo:
$ git status
Now you’ll see all the files that are not added to the staging area, those have merge conflicts. Go to the files and solve the merge conflicts and save them. Then:
$ git add -A $ git cherry-pick ---continue
That’s the exact same workflow as you would have when solving merge conflicts when rebasing.