1

We accidentally destroyed a branch from our TFS server.

is there a way to create a new branch from the local files on my computer?

I looked into those 2 solutions:

But I don't think that I can use them since my changes are not shelved

Basically I think I need to create a new branch and overwrite it with a local directory. Is this possible?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Dardar
  • 624
  • 3
  • 13
  • 30

2 Answers2

3

You can start from a fresh folder

  • Map the parent folder to a new local workspace
  • create the folder you want to use as branch root in your local workspace.
  • Copy the contents from your local backup.
  • Check in the folder.
  • In the source control explorer use the Convert Folder to Branch option.
  • From the commandline perform a baseless merge with the original parent folder tf merge /baseless $/project/revivedfolder $/project/parentbranch /recursive /force
  • Resolve all conflicts (this is potentially going to be a lot of work)
  • Check in the complete the restore process.

If you have a previous changeset that's similar enough to the destroyed branch (e.g. the changeset that was used to originally create the destroyed branch, or the changeset of the last successful merge from this branch), you could also use the following technique:

  • Branch a new branch from the parent from the changeset the now deleted branch was created from or last merged with.
  • Map the new branch folder to a new local workspace and get latest
  • Locally delete all files in the new local workspace (this is to ensure deleted files will stay deleted)
  • Paste your changed files over the branch. Be careful with renames, these may get lost. You can resolve them from the Team Explorer window. See: Fix the outcome after you rename an item in your operating system.
  • Check in the files in your local workspace.
  • Because the branch was created from the parent branch, the merge relationship will be present without performing a baseless merge.

Support option If the branch was deleted recently it may still exist in the TFS database, the cleanup job doesn't run immediately unless you've told it to. By contacting Microsoft Support you may be able to revive the deleted content including all history.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
2

First, please make sure you or your teammates haven't destroyed this branch (After doing this, there is no way to recover it in TFS server).

If you delete this branch in Visual Studio,

To restore an item deleted from the server

From the menu bar choose Tools, Options.

On the Options dialog box, navigate to Source Control, Visual Studio Team Foundation Server.

Select Show deleted items in the Source Control Explorer, and then choose OK.

From the menu bar choose View, Other Windows, Source Control Explorer.

In Source Control Explorer, navigate to the folder that contains the item you want to restore.

Open the item’s context menu (select the item and right-click it) and then choose Undelete.

If you delete this branch from your dev machine outside of Visual Studio,

Please check the solution from MSDN link Delete or restore files and folders


If you got the options gray(not available) such as below screenshot

enter image description here

Note: To be able to undelete a branch you must first map the parent folder/branch to your workspace. Now, the undelete option will be enable.

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • Unfortunately i think our IT destroyed it since i don't see it as deleted. but thx for the help. ill update the question – Dardar Jul 17 '17 at 15:11
  • Hi @Dardar Please double confirm this, usually a person will not accidentally destroy files in tfs source control. To see the deleted files you need to **Show deleted items in the Source Control Explorer**, detail ways please refer this thread: http://pinter.org/archives/1455 – PatrickLu-MSFT Jul 17 '17 at 17:24
  • @Dardar If your IT really destroy the branch, below step may do the trick: delete the old workspace ,back up your local files. create a new empty folder in TFS server, create a new workspace , map the empty folder with the local , move local files to the empty folder, check in all pending changes. Covert the folder to a branch. – PatrickLu-MSFT Jul 17 '17 at 17:30
  • @MrHinsh No, ill-conceived. OP still need to perform a baseless merge, just the same behavior as creating a new branch. – PatrickLu-MSFT Jul 31 '17 at 02:03