Discarding changesets in TFS

We’ve recently updated our branching strategy at work and now have a Main branch and up to six branches which will each usually only have one work item on.  Once a work item is released to live the branches are forward merged from Main.  More recently I upgrade the database solution in Main and all the branches to SSDT for VS2012.  Each branch was manually upgraded so the changeset that contained the upgrade on Main wasn’t required to be forward merged into the branches. You can use the following command to discard any unwanted changesets so they don’t appear in the list of changesets in the merge wizard in TFS.

tf merge "$/sourcePath/Main/Data" "$/targetPath/Branches/BranchA/Data" /discard /recursive /version:C20144~C20666

tf.exe can be found in C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE If you have a batch of changesets that you want to discard, view them in the merge wizard in TFS and get the start and the end changeset numbers.  These are the two values you use in the /version tag prefixed with a “C”.  If there is only one changeset you still need to specific it as a range, e.g. /version:C20144~C20144. This seems to check out all the files that you would be merging if you weren’t discarding the changesets and you’ll need to check them in.


4 thoughts on “Discarding changesets in TFS

  1. Thanks for the post Simon. This helped me, as the merge feature is not well documented. Just FYI: there’s a typo above “wth”. Thanks again. -Michael

  2. Hi Simon,
    If i want to exclude only two random changesets then what should i do? Looking forward for your reply. Thanks

    • Hello Mani. I think you would have to run the process twice. Once the first changeset and then again for the second changeset.
      So if you wanted to discard changeset 123 and changeset 555 you would run

      tf merge “$/sourcePath/Main/Data” “$/targetPath/Branches/BranchA/Data” /discard /recursive /version:C123~C123

      then run

      tf merge “$/sourcePath/Main/Data” “$/targetPath/Branches/BranchA/Data” /discard /recursive /version:C555~C555

      Let me know if that doesn’t work.

      NB. you must use something like /version:C555~C555 instead of just /version:C555 as the latter will discard all changes up and including 555.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s