5

I am using Visual Studio 2019 Community and accidentally clicked in undo changes in the Team Explorer tab for all the files staged and lost all my last days work. Is it possible revert the situation and get back the changed files?

I hope to have explained my problem well. Thanks in advance.

Fernando
  • 81
  • 1
  • 1
  • 4

1 Answers1

4

I am using Visual Studio 2019 Community and accidentally clicked in undo changes in the Team Explorer tab for all the files staged and lost all my last days work.

If you are sure that you have staged your files, the recovery of files content is possible, even if painful! For the file names, the data is lost, due to how git works (i.e. when you stage files, only blob objects are created and stored in git data store but not filetree objects).

If you didn't staged your files, all is lost.

Download and install Git Extensions.

Then, once your repository is opened in GitExtensions, go to the menu item: "Repository" -> "Git Maintenance" -> "Recover lost objects"...

There, uncheck "Show commits and tags" (that will check "Show other objects")

enter image description here

Now, when you double-click on a line, you should be able to get the content of the files created from the more recent to the oldest.

Good luck!!

lost all my last days work.

PS: for the future, you just learned the hard way that with git you must commit often (you will always be able to recover once your work is committed). And after that, learn how to rewrite your history or to amend the last commit. Learn how to use the reflog also

Other ways to recover staged files in another Stackoverflow question: https://stackoverflow.com/a/58853981/717372

Philippe
  • 24,487
  • 5
  • 44
  • 70
  • **Be carefull with GitExtensions it will "destroy" your .gitconfig and [developers are not concerned at all](https://github.com/gitextensions/gitextensions/issues/4389).** – Luizgrs Nov 05 '20 at 01:58
  • @Luizgrs do you have a (handcrafted) .gitconfig that you could share that keeps getting messed up? I'm currently trying to fix that issue how GitExtensions handles gitconfigs and would greatly appreciate it if you could provide a sample, especially with non-obvious issues (like comments getting removed) - Thank you – wischi Nov 09 '20 at 20:31
  • @wischi, it got rid of my proxy entries, is there another issue in githup where I can send you an example? – Luizgrs Nov 11 '20 at 12:20
  • @Luizgrs I guess the simplest way would be directly on the issue you mentioned or on pastbin and comment it here. – wischi Nov 11 '20 at 19:24
  • "Recover selected objects" - to which location will they be recovered? – Gerard Jan 20 '22 at 10:17
  • @Gerard That will create tags (named `LOST_FOUND_n`) directly on the blob recovered and you will be able to see the content with the command `git cat-file -p LOST_FOUND_1` – Philippe Jan 20 '22 at 11:00
  • After 'recover selected objects' they disappear from the obejct list. The git cat-fil command you mention is perhaps advanced, allthough after git cat-file -p LOST_FOUNDx > myfile.cs one has the file on disk. Easier is to first select save files to lost-found! Luckily I saved my lost content manually before 'recover selected objects'. – Gerard Jan 20 '22 at 12:24