How To Remove A Merge Candidate From The Merge Tool in Visual Studio

Create a new workspace containing the two branches for which you want to remove merge candidates (*). For example:

  • Name: Temp
  • Source Control Folder: $/Foo/Delivery - Local Folder: C:\TFS\Temp\Delivery
  • Source Control Folder: $/Foo/Production - Local Folder: C:\TFS\Temp\Production

Open the “Developer Command Prompt for VS 2019”

Change the directory to the root of your newly created workspace: C:\TFS\Temp

Run this command to see which candidates are available for merge:

1
> tf merge /candidate Production Delivery  /recursive

This will return a list:

1
2
3
4
5
6
Changeset User  Date        Comment
--------- ----- ----------- ---------- -------------------------------------
121911 J, Joe 2019-08-12 Merge DLV -> PRD
117308 Z, Han 2019-02-27 rollback rollback
117284 J, Joe 2019-02-26 Rollback Merge because of required hotfix
117270 Z, Han 2019-02-26 merge dlv-> prod (part 1)

The changesets 117308, 117284 and 117270 are the ones that I want to remove as merge candidates.

For each of the changesets you don’t want as merge candidates run a command like this to remove them:

1
> tf merge /discard Production Delivery /recursive /version:117270

To push this change to TFS you must perform a check-in:

1
> tf checkin /comment:"Discarded Prd > Dlv merge candidates for CS 117270"

Do not try to do multiple > tf merge /discard commands followed by a single tf checkin: doing that failed to remove the unwanted merge candidates for me!

*) This was needed to overcome an error running tf merge:

All specified files must reside in the same workspace. Workspace Delivery contains C:\TFS\Foo\Delivery.

Check out the TF Merge Command documentation here:
https://docs.microsoft.com/en-us/azure/devops/repos/tfvc/merge-command?view=azure-devops


Photo by Edward Ma on Unsplash