Reverting back to a specific changes after saving in Visual Studio 2019 - visual-studio

In my project in Visual Studio 2019, I opened a file and made some changes. After running it, I decided to undo(ctrl + z) my changes and revert it back to the original point where I opened it and do some other code again to verify my changes. After saving and running my code, I decided to revert it back to the point where I made my first changes. And now, I cannot revert it back anymore. I tried to search it online but had no luck. Is there a way to revert my first changes back? Thanks in advance for your help.

Ctrl-Y is Redo, which is the opposite of Ctrl-Z Undo.
I would suggest creating a Git repository. You can commit versions of your code and revert to any of your previous versions.

Related

Visual Studio sometimes not saving files

I am getting an inconsistent error with Visual Studio 2015 that is severely hampering my productivity.
I am working on a very large application that I have pulled down from TFS. Sometimes when working I will try and save the file that I was working on, and have the asterix not go away and the file not save. This is despite running the application in Administrator.
Sometimes the solution is simply to rebuild the project and then try to save, however when this doesn't work I need close down visual studio and start up again, losing all my saves anyways.
This isn't too bad when I am working on .net files because the problem happens a lot less, and the solution is almost always to just rebuild, which is much better than having to re boot vs. However recently I have been working on javascript files within visual studio, and with them I get about one save, then the problems comes up, and rebuilding doesn't fix issue, causing me to have to reboot visual studio every save I make...
I have tried searching online for people who have faced a similar issue, or asked around my work, and no one seems to have ever had a similar problem. So hopefully, for my sanity's sake, someone knows what the heck is going on with my visual studio. Thanks!
I am currently running VS2019 16.7.2 and sometimes it just refuses to save no matter what I do. I try Ctrl + S, File -> "Save all", closing the window (which causes the changes to be lost) but nothing works.
Though for some reason when first I press the File -> "Save ... as" option in the menu and then cancel it, that releases the "save lock" and suddenly I am able to save again. Not really a satisfactory solution but at least all changes aren't lost. Maybe it will work on other versions as well?
I will give an answer to a problem which might not be exactly the same as the one reported by the author, but it is fairly close, and people searching for a solution to this problem are likely to arrive to this question.
In my case, in my entire solution containing thousands of files, there was only one particular file that Visual Studio was consistently failing to save when needed. As a result, after each commit, the "Git Changes" tab would not appear completely empty. All files would be committed, except this one file, which would appear as still uncommitted. So, I would have to manually save it and then amend the last commit in order to arrive at a completely empty "Git Changes" tab.
I thought that the problem might be due to some discrepancy between the letter case of the filename on disk (which is what the "Git Changes" view reports) and the letter case of the filename in the visual studio project file (which is what the "Solution Explorer" view reports) but it turns out that this was not it.
After much troubleshooting, I discovered that the following sequence of magical incantations solves the problem, I have no idea why:
In "Solution Explorer" locate the problematic file.
Rename the problematic file to something else.
Commit (with amend if you wish) the file.
Rename the file back to its original name.
Commit (with amend) the file again.
Restart Visual Studio.
The last step of restarting Visual studio is not strictly speaking necessary, but it is useful in case you have a letter case mismatch, because Visual Studio seems to be somehow caching filenames, (or at any rate not detecting that the capitalization of a filename has changed,) and restarting it makes it come to its senses.
I realize this is an old question but I had a similar problem with a solution file I had upgraded from Visual Studio 2015 to Visual Studio 2022. I was unable to save any changes to the solution, although the file was writable in notepad.
Deleting the section in the solution file as suggested by Richard Stanton's workaround fixed it for me!
developercommunity.visualstudio.com Workaround
Delete the following section from the solution file:
ProjectSection(FolderStartupServices) = postProject
{B4F97281-0DBD-4835-9ED8-7DFB966E87FF} = {B4F97281-0DBD-4835-9ED8-7DFB966E87FF}
EndProjectSection

Unshelve throws "No appropriate mapping exists" error then works when I try again

I am getting the aforementioned error most times I unshelve from Team Explorer > Shelveset Details, but unlike this question, I have my workspace set correctly under my Pending Changes window. The weird part is that I am always able to unshelve after trying a second time without changing anything.
It didn't always do this to me, and it seems to not affect anybody else on my team. I've not messed with any settings that I can think of as being relevant either.
And yes, I've restarted my computer since it started happening.
Another thing it does is deletes all ADD changes upon reconciling after passing a gated check-in build.
Thanks.
Using VS 2015 Update 3 (version 14.0.25431.01) connected to TFS 2015 (version 14.102.25423.0)
According to your description:" it seems to not affect anybody else on my team". The issue should be a client side issue.
First,you could use another TFS account to unshelve Shelvesets on your develop machine. This will narrow down if the issue related your account or not.
Suggest you try to clear TFS and VS cache:
For TFS cache:
close all instances of Visual Studio on the client machine,
manually delete the corresponding Tfs client cache folder, and then
start Visual Studio
The corresponding Tfs folders to manually delete are as follows:
Tfs 2015: "%localappdata%\Microsoft\Team Foundation\6.0\Cache\"
For VS cache:
Delete the contents from the following folders
C:\Users\<<Your Alias>>\AppData\Local\Microsoft\VisualStudio
C:\Users\<<Your Alias>>\AppData\Local\Microsoft\VSCommon
If above not work, you could also delete the old workspace(back up local changes first), and create a new one. Then test it again, which should do the trick.
It turns out that opening the shelfset before changing my workspace from pending changes causes the issue. The solution is the change the workspace in pending changes before opening the shelfset.
I'd definitely call this a bug in VS since the shelfset viewer does not indicate which workspace it is referencing before unshelving.

Is there any way to restore visual studio files of a project?

I am working on visual studio 2010.
I have done some changes in files and then I have closed the visual studio.
But now I want to restore the project, means I want to undo the previous changes.
lets say first version is version1 after changes this it becomes version2. I save these changes and close the visual studio. now I want version1 instead of version2.
So is there any way to restore the project in visual studio or on the basis of history I can get the the old project.
Please help me how can I solve this issue.
Unless your code in under version control: nope, there is not!
It's too late now, but setting up a git repository on your local machine is very easy (see this SO answer) and will save you that kind of problems in the future.

Visual Studio 2010 - automatic git commit, push when file is saved

Is there a way to have Visual Studio 2010 automatically commit a file and push it to a git repository when the file is saved?
I would like to be able to have a pop up box appear to allow me to write the commit message on save. I feel that this would force some good habits on me, because sadly I can miss a day or ten of commits on occasion and as I am the sole developer this isn't a job requirement here.
From a configuration manager point of view I completely disagree with your "always commit" policy.
Insted, I don't know if have you tried Visual Local History 2005. I've used it in the 2005 and 2008 versions, but I've never tried with the 2010 version. It simply create a subdirectory and save there a local copy every save you make. So you could watch the history per-file.
THEN you could commit at the right point (when it really makes sense).
Let me know if it works as you would.

TFS won't recognise need to perform merge

A colleague and I are working on the same area of code using Visual Studio 2008 and TFS 2005 on the server.
When we both edit the same file concurrently and I check it in first, TFS does not recognise this when he either gets latest version or checks in, meaning his or my changes get overwritten without a painstaking manual merge.
This only seems to be a problem for him.
Any ideas what the problem might be or how we can fix it?
We removed and recreated the workspace and that fixed it. Job done.

Resources