On cherry-picking [Git]

This friend asked me on twitter to write about cherry-picking. In essence, cherry-picking a basic git concept which lets you create a copy of any commit and apply it on top of your current HEAD.

For example, say your repository has branches for different versions of the app. If you make a bug fix on one branch v2.0 and you want to apply that bug fix to v3.0 as well, you can cherry-pick the commit with the fix in v2.0 to v3.0. Checkout v3.0 and type

git cherry-pick <SHA-of-bug-fix-commit>

If you’re lucky there will be no merge conflicts and you’re done. If you get any conflicts, resolve them and type git cherry-pick –continue. You can also cherry-pick several commits at once as well. Some useful options to cherry-pick command include -e (edit – which lets you edit the commit message prior to committing) and -n (no commit, which applies the changes but does not make a commit). You can also use the merge strategies you use in git merge.

That’s just cherry-pick in a few words. Do checkout the man pages. Think-like-a-git has a good visual explanation of the concept.

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Your email address will not be published. Required fields are marked *