Yanıt TFS 2008 Recover/restore a deleted file with history

  • 03 Nisan 2012 Salı 22:22
     
     

    I made a mistake and deleted a file from TFS. After discovering the mistake I re-added the file, but now it doesn't have it's history. This is a lot of information that I've lost which I'd like to get back.

    I followed methods for undeleting a file, which probably would have worked if I hadn't already re-added the file. Now it doesn't show up as a deleted file because a new file is there with the same name.

Tüm Yanıtlar

  • 03 Nisan 2012 Salı 22:58
     
     

    In Visual Studio try

    => Tools | Options

    => Go to Source Control, Visual Studio Team Foundation Server and check "Show deleted items in source control explorer" 

    Now go to source control explorer, you should be able to see the deleted file. Right click the file and pick restore, this should get the file and its history back.

    HTH
    Cheers, Tarun


    Please remember to mark the replies as answers if they help.

    Tarun Arora

    Blog: http://geekswithblogs.net/TarunArora  Subscribe in a reader

  • 05 Nisan 2012 Perşembe 05:18
    Moderatör
     
     

    Hi Gastroman,

    Thank you for your post.

    You can make a try of Tarun's method.

    Related issues for you to refer:

    http://social.msdn.microsoft.com/Forums/en-US/tfsversioncontrol/thread/d0b3a884-46a8-4a1a-b597-5a5e53b87923

    http://social.msdn.microsoft.com/Forums/en-US/tfsversioncontrol/thread/05d62bee-6b87-4369-a573-fd7ac783a166/

    If anything is unclear, please free feel to let me know.

    Best regards,


    Lily Wu [MSFT]
    MSDN Community Support | Feedback to us

  • 05 Nisan 2012 Perşembe 13:55
     
     Yanıt

    Hey Gastroman,

    You might have to drop down into the command line to pull this off. I also want to say to anyone else that these instructions work for TFS 2005 and 2008 only -- our item model has changed in TFS 2010 and TFS 11.

    1. First make a note of where on your local filesystem the file in question is. I'm going to call it C:\MyWorkspace\File.txt.
    2. Start up a Visual Studio Command Prompt and cd to C:\MyWorkspace.
    3. First we're going to delete your 'new' file -- the one you don't want. tf delete File.txt, and then tf checkin.
    4. Next run "tf history /noprompt /slotmode /format:detailed File.txt" -- this should show the entire history of every item that has ever been called File.txt. It should look something like:

    add (the original one, the one you want)
    edit
    ...
    edit
    delete (the original one, the one you want)
    add (the new one)
    delete (this is the change we just committed in step 3)

    We are going to undelete the first item that you deleted. But if we say "tf undelete File.txt" it is not clear whether we are talking about the first item or the new one. To disambiguate we are going to specify the Deletion ID of the first file.txt. The deletion ID is specified in the output from the tf history command we just ran. If you look at the first "delete" on the item in the history, then the file path is going to have a deletion ID on the end of it. It will look something like 

    C:\MyWorkspace\File.txt;X65
    or maybe
    $/MyProject/File.txt;X65

    Either way, the key part we are looking for is the X65. The newer item (the one you don't want) will have a deletion ID, too -- a larger one (higher number).

    5. Type "tf undelete File.txt;X65", replacing the 65 with the actual deletion ID from the changeset I put in bold above. This should bring back the File.txt you want. You can check this change in from the command line or from Visual Studio.

    Hope this helps
    P. Kelley
    Microsoft Corp.

    • Yanıt Olarak İşaretleyen Gastroman 13 Nisan 2012 Cuma 15:58
    •  
  • 13 Nisan 2012 Cuma 16:00
     
     
    This is exactly what I needed! There is information on how to undelete a file that has been deleted, but not how to undelete something that has then been re-added and deleted again. Thanks so much!