26

Using Visual Studio 2013 and TFS I did a lot of work before checking in. Then I accidentally clicked undo pending changes... thinking it would only apply to one of the projects in my solution. Unfortunately it was applied to all projects. How can I get my changes back?

This question has been asked before link. One person suggested using Reflector to copy the dll. I downloaded Reflector, but I'm unsure how to use it. How would I use Reflector to get my changes back.

Community
  • 1
  • 1
navig8tr
  • 1,724
  • 8
  • 31
  • 69
  • possible duplicate of [Team Foundation Server deleted local files after I undid pending changes](http://stackoverflow.com/questions/24637535/team-foundation-server-deleted-local-files-after-i-undid-pending-changes) – Daniel Mann Jul 21 '14 at 16:36
  • I already mentioned it was a duplicate, but I needed further information. – navig8tr Jul 21 '14 at 16:49
  • It's a duplicate *and* a "recommend a tool to me" question, neither of which are generally accepted on Stack Overflow. – Daniel Mann Jul 21 '14 at 22:05
  • 1
    I wasn't really asking for a recommended tool, I was asking how I can get the changes back--regardless of any tool. – navig8tr Jul 24 '14 at 22:59
  • Also none of the duplicates that I found provided a satisfactory answer. – navig8tr Jul 24 '14 at 23:00

5 Answers5

34

Just for your help. As per stackoverflow's questions link shared. He is trying to say that if you have not build your project. You can open last built dll in Reflector and see the code of the files and recover the code.

You can use any took like Reflector or dotpeek from JetBrains.

Visit this link to know more about dotpeek

But if you have build your project after performing Undo Pending changes then as per my knowledge it is impossible to get the code.

Dnyanesh
  • 2,265
  • 3
  • 20
  • 17
  • 1
    There are so many dlls I didn't know which one to open. Suggestions? – navig8tr Jul 21 '14 at 16:56
  • 2
    What type of project you are working on Windows/Web? More important did you Build your application after Undo Pending Changes? – Dnyanesh Jul 21 '14 at 16:58
  • 1
    Sorry I didn't mention this before, but I didn't build after Undo Pending Changes. Also I'm working on a Web project. – navig8tr Jul 21 '14 at 17:11
  • 1
    Ok. So now go to Bin folder and open dll into dotpeek or Reflector as shown in youtube video. And you will have all C# code. Do not go mad but this process is going to recover only C# changes. – Dnyanesh Jul 21 '14 at 17:17
  • 1
    That's too bad, but don't worry I'm not mad. – navig8tr Jul 21 '14 at 17:19
  • 1
    Dotpeek has been moved to this link: [Dotpeek](https://www.jetbrains.com/help/decompiler/10.0/dotPeek_Getting_Started.html) https://www.jetbrains.com/help/decompiler/10.0/dotPeek_Getting_Started.html Here is the direct download link: [Download dotPeek](https://www.jetbrains.com/decompiler/download/) – sandiejat Jul 21 '16 at 23:13
  • 1
    This worked for me. Keep in mind your variable names may be mangled a bit, some of your non-class specified properties may be specified as 'base', and some base implementations might show up (such as types for generic method calls or vice versa). Still vastly better than rebuilding the lot from (my own) memory. – ouflak Oct 25 '16 at 13:10
  • 2
    For mine, I had to use the right-click `Decompiled Sources` after clicking on my function took me nowhere. – interesting-name-here Mar 05 '19 at 20:36
13

Unbelievable! After giving up and rewriting all of the code I lost, I was able to recover the files. After pressing "Undo pending changes" I never built the solution again. Then, I closed the solution, copied the entire workspace and saved it under a different name. Next, I reopened the original solution. I then used "Add existing item" from the original locations of the files I lost. Then, (and here's the cool part) I navigated to the copied workspace and found the lost files in-tact and in their original locations. Great! I only wish I did this before I rewrote my code!

For me, this solution was found purely by happenstance, but I hope someone else can use this information in the future. Please note that I never built the solution after I undid the changes so that may be the reason why the files were still in their original locations but not visible in the solution itself.

navig8tr
  • 1,724
  • 8
  • 31
  • 69
  • 3
    There's no magic with copying an entire directory - the files you added from your copied workspace must've also still existed in the original directory. It sounds like you created new files and were trying to add them to TFVC - in which case this makes sense, as "Undo pending changes" doesn't delete new files you've created, it just removes them from the list of staged changes to be committed. – Eric Mar 01 '16 at 20:31
  • This didn't work for me unfortunately as TFS went ahead and undid the changes on the file I lost. Nice find though. – ouflak Oct 25 '16 at 13:08
  • Undo changes can be disastrous! Did anyone test this solution with modified files? – Shimmy Weitzhandler Jul 27 '17 at 08:13
  • I think this solution will only apply if you add files to your project. if you undo changes from existing files on the tfs you may use dotpeek or reflector if the project is not rebuild. – Drew Aguirre Sep 07 '17 at 00:59
12

This happened to me today, but it was after I overwrote local changes with an unshelved version. I tried decompiling the dll, but it was too old and didn't have the changes. I finally found the changes in the TFS temporary diff files in "AppData\Local\Temp\TFSTemp". The files all had names like "vctmp4316_370233.cs", but they were all there and thankfully I was able to recover my changes.

Another thing you might try if you have MSTest unit tests is looking for dlls in the solution "TestResults" folder.

The last step is to setup some sort of backup system so this doesn't happen again.

Dave A
  • 484
  • 3
  • 10
  • 1
    I can't find this folder? Are you talking about the local source control folder for the project? For instance: Source/Workspaces/Project/App_Data? – SomeRandomDeveloper Jun 07 '17 at 20:58
  • 2
    No, I'm talking about the hidden AppData folder in your windows user folder, for example C:\Users\SomeRandomDeveloper\AppData\Local\Temp\TFSTemp – Dave A Jun 08 '17 at 21:15
3

I did something similar where I hit undo and it removed files I didn't intend it too. I just hit the show all files icon in the Solution explorer. It made the files visible and then all I had to do was right click and then select Include In Project.

1

This happened to me today. In my case, I was working on an existing typescript file. Luckily the site was loaded in my browser tab and I didn't refresh the page. So I was able to copy the code from the chrome's dev tool - source.

I got this idea after reaching out to this question, Sharing in case somebody found it useful.

Nitinkumar
  • 19
  • 8