7

I have a very messy TFS structure that I am trying to clean up (thanks to my predecessor). I now have a situation where I need to bring changesets selectively from one branch to another where they don't have a parent/child relationship and I don't want those changes to pass through their shared trunk. How can I do this?

I have tried a baseless merge - In TFS, how do I do a baseless merge on specific changesets? - which told me that there were no changes to merge.

What I want to achieve is something like this TFS : Can a shelveset be restored to another location? except with a changeset.

In GIT I think this would be a simple cherry-pick.

My structure looks something like:

   Y-C1-C2-C3
  /
X-------------
    \
     Z

And the question is how do I get C2 from Y into Z without passing through X?

Community
  • 1
  • 1
idieeasy
  • 135
  • 2
  • 7
  • What options did you use in your baseless merge attempt? Did you use the /force option? – Ryan Cromwell Sep 13 '10 at 16:36
  • Yes I tried force and a few other things that I read around the place but with the same result - that there were no changes. In the end I bit the bullet and merged all it manually... it took 14 hours but at least I am 100% confident in the result. – idieeasy Sep 14 '10 at 11:49

2 Answers2

4

We have a similar situation, though, in our case, we do a baseless merge from multiple branches into a "scratch" build branch. The only way we were able to do this is by writing our own utility leveraging the TFS API.

The good news is, you should be able to accomplish this in less than a couple hundred lines of code.

The basic steps are:

  • Connect to TFS
  • Get an instance of the VersionControlServer (let's call it VCS)
  • Create a workspace
  • Do a VCS.GetChangeset()
  • Iterate through the Changes to get a list of items that have changed
  • Perform a Workspace.Merge for each of the items from your source branch to your destination branch.
  • Check in the items in the destination branch.
  • Delete workspace
Robaticus
  • 22,857
  • 5
  • 54
  • 63
  • It looks like this is the only way to go aside from doing it manually (which I did rather than hold up my team). It should be a simple/common problem? – idieeasy Sep 14 '10 at 11:55
  • Best practices say that you shouldn't have to cherry-pick. If you're doing that a lot, there's a problem with your branching strategy. You may want to consider branching on feature instead. In our situation we do it for trial builds. – Robaticus Sep 14 '10 at 12:20
  • You are absolutely right, there was a problem with the branching strategy and this question arose as I was attempting to rearrange the branches so that I wouldn't have so much trouble merging. – idieeasy Oct 01 '10 at 01:30
  • The bad news was that the only way to do it was by writing your own utility. The good news is, they provide a good API and the approach is relatively simple. – Robaticus Aug 31 '12 at 15:42
3

Its simpler to do it using Visual studio.

In Visual studio use the Source Control Merge wizard to merge the unrelated branches.

It has an option to merge selective changesets. The only restriction is that the changesets must be consecutive

gcs06
  • 51
  • 4
  • 1
    If you want to merge non consecutive changesets then you just repeat opening the Source Control Merge Wizard until you are done. You can choose to commit between each merge or in one commit at the end. – Tore Østergaard Nov 23 '17 at 13:12