Hi! I'm Nathan Hoad


How to: Cherry-pick changes with Git

Here's the scenario: You're working in a feature branch that isn't quite ready for a full merge but you do have a few commits in there that you want to push to master (for a release or whatever reason). This is just one of possibly many situations where making use of Git's cherry-pick command might prove useful.

First, from within your feature branch, copy the first six or seven characters of the ID of the commit that you want to bring in:

Selecting a commit hash

Now jump into the branch that you want to insert the commit into (I'm using master):

git checkout master

And then cherry-pick your commit:

git cherry-pick c90fd66

Now if you do a git log you will see your cherry-picked commit at the top.

Be wary of cherry-picking a lot of commits out of order, the Git log will reflect the order in which you cherry-picked, not the chronological order of the original commits (The original commit date is preserved, however).

For more information check out Git's documentation on cherry-picking.

If I just made your day a little better then thank me with a coffee or maybe a a pizza