Lo&#239&#59;c Baumann

Hi all,

I'd like to merge a specific changeset from one branch to another.

Here what I do:

ChangesetVersionSpec csvs = new ChangesetVersionSpec(csid);

GetStatus st = m_Workspace.Merge(m_SrcBranch.Text, m_DstBranch.Text, csvs, csvs, LockLevel.None, RecursionType.Full, MergeOptions.None);

In return I have some merge conflicts, and it looks like the conflicts are detected by comparing the version I have in local (because the changeset is so old that the local version has different lines of code).

I don't really understand why the local version of the files included in the changeset are analyzed for the merge

All I want is to get the content of a given changeset, then merge it in another branch.

Is there a way to do that

Regards,

Loic



Re: Team Foundation Server - Version Control Merge of specific changeset.

Richard Berg MSFT

Probably. Depends what you mean. If you want to make the target branch look like the source did at time "csid" then you should do a catch-up merge, i.e. pass versionFrom = 1.

When you cherry-pick a changeset (versionFrom = versionTo = csid) then TFS will only apply the differences from that changeset.




Re: Team Foundation Server - Version Control Merge of specific changeset.

Loic Baumann

So to sum up, if I want to merge the content of a given Changeset with its content at the time it was created, I have to set versionFrom to 1, and versionTo to my changeset's ID. But it'll be a merge, right I mean if the dest branch evolved on its own, there will still be a merge process. The src branch will be totally ignored in that case, right

One last question, where was I supposed to find documentation about this "versionFrom = 1" thing

I find few blog posts about merging, but so far I couldn't grab a good documentation on the whole topic, do you have some

Thanks for your time,

Loic

EDIT:

Let me rephrase my need: I want to merge the content of a given changeset (only the changes that are made in this particular changeset) to a destination branch without involving my current source branch.

Actually, when I call the code I posted, I got conflicts due to the state of the source branch. But I really don't care about the source branch, all I want is to get the changes of the changeset merged in the destination branch.

I hope this is more clear that way, sorry for having troubles with the explanation of my needs.





Re: Team Foundation Server - Version Control Merge of specific changeset.

Richard Berg MSFT

I do have some docs Smile I just need to convert it to blog format. The idea behind versionFrom=1 is the same as tf merge /version:Cxxx -- when you only pass one version to tf.exe it assumes a "catch-up merge" i.e. everything up to changeset xxx. This is also the default behavior of the GUI Merge Wizard.

From the sound of it, that's not what you want. You want to merge the changes that happened in xxx and only those changes (cherry-pick). That's not the same thing as making the files look like they did at time xxx (catch-up).

I don't really understand what's going wrong with your source branch. Merge should only touch the target. The source files you have locally shouldn't matter unless you're using a WorkspaceVersionSpec.




Re: Team Foundation Server - Version Control Merge of specific changeset.

Loic Baumann

I still have hard time to figure things out about changeset merging.

Here an example:

I have a Branch A, and another B (derived from A, from its very beginning).

Let's say I have 50 changesets in A, and I want to merge them one by one (basically to keep relation with the Work Items) to B, with B totally untouched.

I do get merge conflicts ! And I don't understand why. Your thoughts

Also when the Merge tool popups (I use KDiff3 with the command line of James Mannings), I don't understand from where I get the content of the middle window (i.e. the one labelled "Yours"). The left one is the "Base/Common" part of the two others, I'm fine with it. The Last one is the content of the Changeset I'm (trying) to merge.

What is supposed to be the "Yours" file The content of the destination branch If it's the case, I don't understand why the content differs from the "Base/Common" one, because it happens! Is it because a merge was incorrectly made

I really thought in such merge scenario I wouldn't get conflict, and that's not the case...





Re: Team Foundation Server - Version Control Merge of specific changeset.

Richard Berg MSFT

yours = target @ now
theirs = source
base = target @ the time of the last merge, or the base version of the merge, whichever is later

You will get a conflict if base != yours. In your case, that will happen if you are merging any of the 50 changesets out of order. Only if you merge them in the same order they were checked in will you avoid conflicts.




Re: Team Foundation Server - Version Control Merge of specific changeset.

Loic Baumann

So "theirs" = source = the changeset I'm merging, that's right

I do merge the changesets in order, I really made sure of that, but I still get merge conflicts!

Sometimes I may skip some changesets (but I'm never out of order), do you think that would be a reason for getting conflicts

Here's basically what I'm doing, please tell me if I'm doing something wrong.

For each changeset:

1) Merge (src, dst, csid, csid)

2) if (NumConflict>0) then

For each conflict:

1) MergeContent(conflict, true), if successful then:

2) ResolveConflict(conflict)

3) CheckIn(GetPendingChanges(), comments, null, wilist, null)

Thanks again for your help!

Loic





Re: Team Foundation Server - Version Control Merge of specific changeset.

Richard Berg MSFT

Yes, skipping changesets will cause conflicts. So will renames and undeletes.

Doing all this automatically seems pretty dangerous. Conflicts exist for a reason.