Is there an easy way to create a patch in one branch and then apply it to another branch in TFS 2010?

StackOverflow https://stackoverflow.com/questions/8828003

  •  15-04-2021
  •  | 
  •  

Question

I have two service pack branches coming out of one ‘main’ branch in TFS 2010. I want to ‘transport’ a change set from one service pack branch to another without promoting it through the main branch and without doing baseless merge.

The ‘main’ branch contains a conflicting change set that I don’t want to merge with the change set from the first service pack branch. I want the second service pack branch to receive that change set in unmodified form.

The baseless merge will create a link between two branches. I don’t want such link to appear in the merge dialog.

Is there an easy way to create a patch in one branch and then apply it to another branch? Something like in Subversion.

P.S. I’m not going to change branching structure to accommodate this one scenario. The overall structure is way more complex that what I described and it accommodates a number of releases, service packs, sub-releses, and etc. It follows the well-known branching guideline.

Was it helpful?

Solution

So you have something like this:

------------------------------------> MAIN
      \          \
       \          \
        A          B

You can make a B' branch out of B:

------------------------------------> MAIN
      \          \
       \          \
        A          B
                    \
                     \
                       B'

Then make a baseless merge from A->B'. After that make a merge B'->B. Go ahead & destroy B'. Though I haven't ever done this, it should work.

OTHER TIPS

One approach:

  • Map both branches (A and B) into separate folders on your PC.
  • Locate the changes in A that you want to merge into B (look at source control history for the branch, locate the changeset(s) and double click them to list the chnaged files), and check them out in the destination branch. (Alternatives: Check out all the files - TFS will discard unchanged files when you check in. Or unplug your network cable and then run VS and it'll go offline. After merging use File>Source Control>Go online to go back online and check out any changed files)
  • Use a merge tool (I'd recommend Beyond Compare, Araxis, but anything aside from the terrible ones that ship with VS should do) to merge from each file in branch A to the eqiuivalent file in branch B
  • Build and test branch B
  • Check in

This avoids using TFS to do any of the merging, so it won't know that it's a merge. It will just think you've written a lot of code in branch B rather fast :-)

Another approach:

  • Merge the changeset into your main branch from A. During the merge, include both variants of the code and add #if commands around the new and old code blocks so that they coexist side by side, and the service pack is "enabled" in the main trunk by a simple define. By default this define should not be defined, so the binary output by the main branch code is unaffected. i.e.

    #if SERVICE_PACK_A  
        ...ServicePackA code...  
    #else  
        ...original Main branch code...  
    #endif
    
  • Now merge the change down into branch B

My answer is similar to Jason Williams's. If you want to stay "inside" TFS then you only have 2 options. Perform the baseless merge, or merge from A to Main and then from Main to B.

As you don't want to do either of these, then you'll need to perform the merge "outside" of TFS.

Tools you'll need: Team Explorer, Team Foundation Power Tools, a 3rd party merge tool. I like Sourcegear DiffMerge (cos it's free) but Araxis, Beyond Compare and Winmerge will all work just as well. (as an aside you can configure TFS to use a 3rd party merge tool(Thanks again Jason!))

  1. Get Latest on both service pack branches
  2. Check out the target branch
  3. Use the merge tool to do a folder comparison between the 2 local folders
  4. Merge the appropriate changes from A to B
  5. On the command line run tfpt uu against the local copy of B, this will undo the checkout of any files that haven't changed as part of the merge. (this requires that the TFS Power tools are installed.)
  6. Check in the pending changes in B

It's not great but I think it's the only way to do what you're trying to achieve

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top