What is a Cherry Pick Merge, and why do you recommend against them?

When you merge in TFS 2010, you have two choices:

  • Merge all changes up to a specified version, which can be one of the following:
    • Latest Version
    • Date
    • Label
    • Changeset
    • Workspace Version
  • Or, merge Selected Changesets, where you select one or more changesets from a list of changesets that are in the source branch and not yet merged into the target branch of the Merge.

The latter option (selected changesets) is also called a Cherry Pick merge.

One problem with Cherry Picking, is changesets are not always granular enough. Consider a change where you added three new files. A second change where you modified two of the three. A third change where you modified a different two, and so on. How can you ensure that you pick all the changeset (and only the changesets) to get the changes you need into the merge without picking too little or too much.

Secondly, if you are doing Cherry Picking, it can be challenging to figure out exactly which changesets you want to merge. What if the developer didn’t put very descriptive comments on the changeset when checking-in changes. Do you need to look at individual files within individual changesets to decide to merge or not merge that specific changeset?

There is always a risk that when you do Cherry Picking, that the target branch will not build properly until you either pick additional changesets, or make manual changes to the files in the target branch to get to a successful build, or even to get to a code state that works. This is particularly a problem when the Main (stable) branch is the target of the merge. We try to recommend branching and merging approaches that keep Main as stable as possible.

Cherry Picking individual changesets for a merge may also leave you with a very confusing change history on the target branch. It is possible that the same code change is Cherry Picked multiple times over several merges.

How can you ensure that you pick all the changeset (and only the changesets) to get the changes you need into the merge without picking too little or too much. It is not as easy as you think.

Some have suggested that the challenges to being able to easily cherry pick changes for a merge is a deficiency of TFS. TFS does indeed make selecting candidate changesets for a merge rather easy. That is not the challenge. The challenge is being able to select the right changesets.

The challenge is somewhat like following a recipe for baking a cake:

In a medium bowl, cream together  1 Cup sugar and 1/2 Cup butter. Beat in 3 eggs, one at a time, then stir in 2 teaspoons vanilla. Combine 1 1/2 Cups all purpose flour and 1 3/4 teaspoons baking powder, add to the creamed mixture and mix well. Finally stir in the milk until batter is smooth.

Oh, sorry. I meant to say: Beat in 2 eggs. Go ahead and remove one of the eggs from the cake batter. Simple, right?

You can download the Microsoft VS ALM Rangers Branching Guidance here: http://tfsbranchingguideiii.codeplex.com/

Comments (5)
  1. Marie Chi says:

    Hope the next version of Visual Studio will make cherry picking merges much better. Saying it's too complicated is the exact need for a robus technical solution. It's not like this stuff is theoretically impossible and someone in Redmond's probably already figured out an algorithm.

  2. Bill Heys says:

    Marie – I don't know ANY tool that offers a robust technical solution to cherry picking merges, and that mitigates the risks I point out in this blog. What is your experience?

  3. Russell Wilson says:

    Hi Bill,

    You have highlighted some great risks associated with cherry picking which is good to be aware of, there is a flip side to cherry picking as well and there can be some really big advantages of using it correctly one example is the bug fix scenario discussed here: svnbook.red-bean.com/…/svn.branchmerge.advanced.html.  

    I too hope this is something which can be made easier in future releases of TFS.

  4. Jason says:

    Would you include merging the latest version of individual files (rather than at the branch level) as cherry picking?

  5. Jay says:

    ClearCase offers cherry picking via it's use of a configuration record.  It is a very easy and powerful way of making certain only specific changes are included in a build.

Comments are closed.

Skip to main content