Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In TFS, how can I cherry-pick a changeset to an unrelated branch?

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?

like image 953
idieeasy Avatar asked Sep 13 '10 02:09

idieeasy


People also ask

How do you cherry-pick a commit from another branch TFS?

Open up Team Explorer and check out the branch you want to cherry-pick changes into using the Branches view. Right-click the branch containing the changes you want and select View History.... Right-click the commit you want to cherry-pick and select Cherry-pick.

How do I merge changesets from one branch to another in TFS?

In Source Control Explorer in Visual Studio, right-click your branch, and choose the new menu-option 'Merge Changeset By Comment'. After that, enter the TFS item under phrase.

What is cherry-pick in TFS?

Cherry-Pick is a process to copy commits from one branch to another. It only copies the changes from the commits instead of copying all the changes available in a branch. Thus, it is completely different from what a merge or rebase performs.


2 Answers

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
like image 138
Robaticus Avatar answered Nov 09 '22 12:11

Robaticus


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

like image 22
gcs06 Avatar answered Nov 09 '22 12:11

gcs06