Mickaël Derriey
Mickaël Derriey

Reputation: 13704

Branch then rollback parent branch in TFS

I'm not very experienced with TFS, and I can't find a way to do what I want.

OK, so we have a main branch in TFS, and we began new development on this branch. We totally forgot to create a new one before beginning the modifications.

What I would like to have at the end is my main branch in the state before the modifications (I have the exact Changeset number), and a Development branch with the work in progress...

Here's what I did:

At this point, I think I was OK, but when I tried to merge the Development branch to the main one, VS stated, correctly, that it couldn't find any Changesets that were checked-in to my Development branch but not to my main one, as the rollback didn't delete the Changesets but just added a new one, with a rollback operation.

I thought maybe checking-in something new in the Development branch would unblock this, but unfortunately, only the latest (post-branching) check-ins seem to be eligible for merging.

I surely did something wrong, or not the right way.

Anybody has an explanation and an idea of how to achieve my goal?

Upvotes: 4

Views: 2530

Answers (3)

Sylvain Rodrigue
Sylvain Rodrigue

Reputation: 4963

A rollback being a normal changeset, you can rollback it like any other changeset. Here's what you could have done:

  1. Create a development branch from your main branch.
  2. Rollback unwanted changes in the main branch.
  3. Check in the rollback in the main branch. This creates changeset #XYZ.

At this point, continue your developements in the development branch. You can also check in changes in the main branch. When done with development:

  1. Rollback the rollback (the changeset #XYZ) in the main branch.
  2. Merge changes from the development branch to the main branch.

The last action should merge only the changes done in the development branch after the branching.

Depending on the complexity of your changes and branch configuration, this could be the easiest way to go.

Upvotes: 0

wensveen
wensveen

Reputation: 884

Because your situation happens quite often (working on a main branch, only later to realize you should have branched), this is use case is supported by TFS (both command line and within Visual Studio).

Instead of specifying By Latest (default) or, By: Latest Version, you want to specify By: Changeset and select the last check-in that should be included in the branch. All check-ins after that are excluded from the branch, but can be merged afterwards (cherry-picking changesets if necessary).

Alternatively, you can get a specific version in your workspace (Get Specific Version) and specify By: Workspace when creating the branch. By date or label are also valid choices but I don't use them that often.

Upvotes: 3

AaronS
AaronS

Reputation: 7703

A rollback is not how you would traditionally think of a rollback. It reverts the code back to the state you want, but you need to check-in the rollback as a new change. This preserves the full history of the code, including the rollback.

I would suggest you:

  1. Delete your child branch
  2. Put your parent branch in the state you want it, even if you have a few additional check-ins and rollbacks.
  3. Once everything is fully checked-in, then branch to your child branch.

Upvotes: 0

Related Questions