T Nguyen
T Nguyen

Reputation: 3415

How to merge new files into another branch in TFS?

Ok, in TFS we have a main trunk branch and another branch, let's call it secondary. We have created a new file in the trunk but when trying to merge that specific file, it does not give us the option to merge to the secondary branch. We're assuming that it's because an analagous file does not exist in secondary.

Is this the cause of the problem and if so, how can we get that new file from the trunk into secondary?

Here, we are merging a file that does exist in secondary. As you can see, the dropdown lists all three of our branches (secondary is actually the middle one): enter image description here

Now, when I try to merge a file which was created in trunk after secondary was branched, secondary is no longer listed as a target branch. enter image description here

Upvotes: 22

Views: 38870

Answers (5)

xr280xr
xr280xr

Reputation: 13282

I think the reason is just that you can't merge something that hasn't been branched. Notice if you merge the folder containing the new file, it says the action is [merge, branch] indicating you are branching the new file as the result of a merge of the parent folder. As far as I can tell, selecting the file > Merging & Branching > Branch, instead of Merge seems to be the solution. The only difference I see is the history then lists it has a [branch] rather than a [merge, branch]. After you've created a branch of the file in your secondary branch, you can merge changes to the file between branches.

Upvotes: 1

Buck Hodges
Buck Hodges

Reputation: 3352

"Now, when I try to merge a file which was created in trunk after secondary was branched, secondary is no longer listed as a target branch."

For that, right click on the file in Source Control Explorer and choose Branch instead of Merge. That will then bring up a dialog to specify the target.

Generally, you are better off merging trunk and secondary rather than pieces of it (easier to keep the branch consistent over time).

Upvotes: 6

AakashM
AakashM

Reputation: 63340

trying to merge that specific file

To understand TFS it helps to remember that the unit of change is the changeset, and it is changesets (not files) that are checked-in and merged.

We're assuming that it's because an analagous file does not exist in secondary

This is correct - at the version (changeset number) that the target branch is at, this file simply does not exist, so there is nothing to merge to.

In general, you don't gain anything by selecting a particular file in the merge source dialog - as it says, it asks you to select the source and targe branches. Specify the branches at their root, choose Selected changesets only, and TFS will show you a list of changesets that exist in source but have not been merged to target. If you only want the one that added this new file, you can select it in that list.

Upvotes: 11

pantelif
pantelif

Reputation: 8544

I think this should be possible over the VS GUI as follows:

Select the folder where the new file was added and order a merge (of the whole folder) to your secondary branch.
Now all changed files of the folder appear in your pending list + your new file.
Undo all other files & proceed with checking in only the one file that matters.

One could argue that this restriction of TFS in fact makes sense:

  • If you 've made additional changes to the files you 're hereby protected from breaking your secondary branch.
  • If you haven't made additional changes to any other files, it still makes sense to merge your, since the merge will only contain your new file.

Upvotes: 8

Ewald Hofman
Ewald Hofman

Reputation: 12668

You could try to use the TF Merge command

Upvotes: -1

Related Questions