Rider overwriting changes when switching branches
This was just annoying at first but I'm realizing it's actually VERY bad since Rider will erase uncommitted changes in some cases and you will lose code.
I also thought it was git at first, but I'm realizing that it is Rider. (2024.2.6).
I'm not sure exactly when, but during branch switching, definitely after rebasing but maybe other times, Rider will still have contents from the previous branch cached somewhere. It will report errors as if this code still existed even though it does not exist. If you switch to the cached file, Rider will open the cached contents instead of the real file contents, and will overwrite the file with the cached contents from the other branch. Any changes made between the branch switch and Rider overwriting the file will be lost (eg: if you did a git stash pop after switching).
Thanks
Please sign in to leave a comment.
Hi Dave!
Could you please check if restarting Rider fixes the issue? In this case, it could be a known problem: RIDER-103721 Code analysis errors after switching branches that could be fixed with Rider restart. Please follow the Investigation strategy and add your details to the YT issue.
Please let me know if your case is different.
Thanks!
It's usually (if not always) after resolving a bunch of rebase conflicts. Just happened again. Rider reporting 8000 errors after rebase, and I'm confused how certain files have changed on master that should only have changed on the branch and not in these ways, but it's because every file I open in Rider, Rider restores some cached version of the file instead of the real file. And it overwrites the real file. I can tell because the changes accumulate in git as I open the files in Rider. Again, this can result in lost work if you edited the file outside of Rider and then opened it in Rider. Without external changes you can just revert from git, and then restart Rider to make it see the real files again. This is 2024.3.2.
To replicate this you would have to do a rebase with a bunch of conflicts that you resolve with Rider. I tried with a single source file but didn't get it to happen.
For the linked issue… it does not involve ambiguous references. Basically the Rider engine “sees” the wrong branch for many files and if you open those files it overwrites the real file with the other branch contents. So at first the errors are all phony, and if you do dotnet build you won't really have errors. But the more files you open the more files are overwritten and then you do really have those errors now. And yes it is resolved just by restarting Rider.
Lately this presents as Rider showing visible analysis corruption. After/during a rebase (well resolving conflicts, specifically) there will be many errors left over. Doing a `dotnet build` shows no errors. But in Rider there are many, and if you investigate them you find files with scrambled syntax highlighting. Making a quick edit and undoing it results in a proper analysis of the file, the syntax highlighting corrects, and the related errors go away. Sometimes have to do this for dozens of files. Starting to be that you just have to restart Rider everytime you resolve rebase conflicts.