Today, I came across the need for a function that would make most source control mechanism’s cry. Essentially I needed some work that was due to go into production in a few weeks, to go today, which meant I somehow had to grab some code that was deep down in my bleeding edge branch out into the limelight of the live server.
In Subversion, this would be pain, but luckily I’m using Git.
Out of the box, git comes with a very useful command cherry-pick. Essentially what this does is take one single commit, and then merges just those changes into the other branch. This is different to a regular merge in that it doesn’t pull ALL changes, so it’s much more precise.
git cherry-pick -n [The commit's SHA-1 Hash]
(Note that the -n option should be used when you don’t want Git to automatically commit the change into the new branch, but you should make sure your new commit message references the old commit for sanities sake).
Remember though, your newly merged into branch might not be working perfectly now, as you may now have unsatisfied dependencies, so test, test test!











