16

How to remove a specific changeset in tfs2010?

I have changeset version numbers with 545, 544, 543,542.

Now, I am looking to delete the particular changeset 543 only in tfs?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Cherry
  • 675
  • 3
  • 10
  • 28
  • `tf destroy` https://learn.microsoft.com/en-us/vsts/tfvc/destroy-command-team-foundation-version-control – samus Nov 16 '17 at 21:25
  • The `tf destroy` command looks like the nuclear option. To be used only when necessary. – Rod Jun 08 '21 at 19:26

3 Answers3

16

You have to Rollback the changeset, you can't delete a changeset. (Rollback Command)

In your case a simple Rollback command would be like this:

TF rollback /changeset:C543
Arin Ghazarian
  • 5,105
  • 3
  • 23
  • 21
  • 4
    Where does that leave the changes made in C544, and 545? – John Saunders Dec 27 '13 at 03:49
  • @JohnSaunders +1 for your very good question. Generally as MSDN said, *"this command creates in your workspace a set of pending changes that negate the effects of the changesets that you specify."* It's vert tricky, cause using these kind of commands can cause serious problems. As a best practice (In my opinion) all side effects should be considered by TFS admin and if safe then use this command, but generally it shouldn't be considered as a usual workflow. If something failed, fix it and check-in again rather than undoing previous changeset. – Arin Ghazarian Dec 27 '13 at 04:14
  • 1
    In other words, you don't know what happens to those changes. – John Saunders Dec 27 '13 at 04:16
  • 1
    @JohnSaunders, I exactly know what happens but it requires much more explanation. Briefly, when you rollback changeset C543, a new changeset will be created to negate it. If changes don't relate to each other, then the effects of changeset will be undone in new changeset, but if changes relate to each other, undoing that changeset is much more complicated. Please read this: http://msdn.microsoft.com/en-us/library/dd380776(v=vs.100).aspx, if you still had questions then please post a question and I'll deeply explain the process. Any how if you have access to TFS, you can test it by yourself. – Arin Ghazarian Dec 27 '13 at 04:43
  • 3
    I was hoping you would explain it _in your answer_. That way, it will benefit others who have the same question. – John Saunders Dec 27 '13 at 06:14
  • 2
    @JohnSaunders I appreciate your concern, but I tried to answer the question as simple as possibe. It isn't asked, what will happen to C544 and C545! it's asked how to delete changeset C543 and I just answered that question, nothing less, nothing more. BTW as I mentioned in comments, nothing will happen to C544 and C545, instead some new negating changes will be created by TFS in user's workspace and like other pending changes, they should be checked in as a regular changeset by user, so after checkin a new changeset will be created (like C546) and nothing will happen to other changesets. – Arin Ghazarian Dec 27 '13 at 06:42
10

You cannot delete a changeset in TFS. Even if you could somehow, (I think you can run a sql query against the TFS database to do that) its not a good practice. If people start deleting changesets/history the whole purpose of version control will be defeated. I think few other source controls allow that but I would not suggest to do that. Its a bad practice.

Also, if you use other features of TFS like Workitems/Test Cases etc. changesets get linked to it so if they get deleted the links will become orphan(I think).

As Arin said the closest thing you can do is to use Rollback command but when you do that you will have to check-in the code after rollback so basically you will see the old changset and the new one(rollback) in the history.

Adarsh Shah
  • 6,755
  • 2
  • 25
  • 39
  • 4
    I am trying to fix a botched migration from one TFS to another, and I would have loved if it was possible to purge "bad" changesets! I don't want to preserve history, it's bad data. My options - restart from scratch (days already wasted), or drop them. – David Airapetyan Nov 04 '14 at 02:34
6

Disclaimer - you should never, never do this. Don't even think about it!

Background - I am trying to do a partial TFS migration, and having the most villainous time with the "TFS Integration" tool. Recently it dumped a series of wrong changesets into my destination TFS. Instead of wiping everything out and starting from scratch, I nosed around the TFS database, and came up with the following (on TFS 2013, TFS 2010 would be more or less similar I suppose):

declare @ChangeSetId int = 5735

-- Delete the actual file content first
delete from tbl_Content where ResourceId in (select ResourceId from tbl_File where FileId in (select FileId from  tbl_Version where VersionFrom = @ChangeSetId))
-- Remove the file
delete from tbl_File where FileId in (select FileId from  tbl_Version where VersionFrom = @ChangeSetId)
-- Purge the version
delete from tbl_Version where VersionFrom = @ChangeSetId
-- Destroy the changeset
delete from tbl_ChangeSet where ChangeSetId = @ChangeSetId

It is not wise to do it. It is not supported by Microsoft. Do not use it on a live production environment! Use rollback instead! But if you're desperate to wipe out a changeset, you can try this. But don't tell me you were not warned.

David Airapetyan
  • 5,301
  • 4
  • 40
  • 62