TFS: Doing rollbacks with TFS 2010 and TFS 11

TFS: Doing rollbacks with TFS 2010 and  TFS 11

I got several time questions about how rollback are done with Visual Studio 2010 and Team Foundation Server 2010; instead of repeating myself i’ve decided to write a post :)

Note : although the screenshots are done under Visual Studio 11, the principals are the same with Visual Studio 2010..

In TFS when doing a rollback or cancel a changeset you will get a new version of your file or files with an Edit status:

image

The edit will then be visible in the history after doing a checkin. (you will the be able to rollback your rollback :) )

Update 08/25/2014: corrected output of rollback 22, thanks B€N :)

Since TFS 2010 it is possible to rollback without using the PowerTools by using the command line tf.exe rollback. The documentation is available on MSDN at http://msdn.microsoft.com/fr-fr/library/dd380776(VS.100).aspx. Unfortunatly this method is not really user friendly :(

Fortunately Microsoft has added a user interface and a context menu entry in Visual Studio with the TFS PowerTools August 2011 which are in standard in VS 11. In the source explorer when doing a right click on an item you will see the Rollback command:

image

If you clic on it a dialog will open letting you specify the rollback settings:

SNAGHTML8ad581

This dialog lets you specify on which item to do the rollback and the type of operation. To illustrate those 3 type of operations we will use the following code:

Changeset 21

public class RollbackDemo
{
    public int GetValue(int i)
    {
        return i;
    }

    public DateTime GetDate()
    {
        return DateTime.Now;
    }
}

Changeset 22

public class RollbackDemo
{
    public int GetValue(int i)
    {
        return i + 1;
    }

    public DateTime GetDate()
    {
        return DateTime.Now;
    }
}

Changeset 23

public class RollbackDemo
{
    public int GetValue(int i)
    {
        return i + 1;
    }

    public DateTime GetDate()
    {
        return DateTime.Today;
    }
}

The Rollback changes from a single changeset option let you cancel the modification added by a specific changeset while leaving all edits that happen after. To do this Visual Studio uses a the same logic as a merge by using the following file versions:

  • Before the selected changeset,
  • The selected changeset,
  • The lastest version.

In our example if we decide to rollback the changeset 22 we will get automatically the following result:

public class RollbackDemo
{
    public int GetValue(int i)
    {
        return i;
    }

    public DateTime GetDate()
    {
        return DateTime.Today;
    }
}

The GetValue method is back to it’s original definition (changeset 21) while the method GetDate is unchanged!

Of course if a conflict exists VS will ask the user to manually resolve it like for a merge:

image

The Rollback changes from a range of changesets option is the same as the previous one but applied to a set of consecutive. When using this option you have a high risk of having conflicts (mostly if the set is important) which may not be simple to resolve.

The last option Rollback to a specific version is simply a cancel operation which will undo all edit after the specified version. The version can be specified using one of the following option:

  • Changeset number,
  • Date,
  • Label,
  • Workspace version

If we decide to revert to the changeset 21 we will get the following code:

public class RollbackDemo
{
    public int GetValue(int i)
    {
        return i;
    }

    public DateTime GetDate()
    {
        return DateTime.Now;
    }
}

The GetValue and GetDate methods are back to the exact definition in changeset 21.

Whichever rollback type you choose the edit is only done on the selected items so watch out for dependencies (for example your rollback removes a method which is used inside a non rollbacked file) !

I hope you know have a better understanding of how rollbacks work. Note that all the above operations can be done using the command line :)

Carpe Diem.

Leave a Reply

  

  

  

CAPTCHA *