Wsl2 sometime corrupt .zsh_history and git
Wsl2 often corrupt .zsh_history file. Other times corrupt git rep ( i use git in wsl, not win version ).
wsl distro: Ubuntu 18.04 wsl version: 2 windows ver: 10.0.19041.172
I also had file corruption problems with Windows 10 but not only on WSL.
In my case it was the Fast Startup feature. I was dual booting with another Windows 10 Insider build and it was a mess every time I tried to boot the other Windows. Since I disabled that feature I had no problems with file corruption.
Same here. Corrupt .zsh_history and .git
WSL DIstro: Ubuntu 20.04 WSL Version: 2 Windows Version: 10.0.19041
Same here, corruption appears randomly after reboots or sleep wake-ups.
WSL Distro: Ubuntu 20.04 WSL Version: 2 Windows Version: 10.0.19041.330 Insider's preview (Slow Ring)
I have a dual boot setup so fast startup is already disabled on my system.
Edit: eventually I've started to wsl --shutdown manually after each session to minimize corruption
i just got this corrupt git repo issue, happened twice in a span of a week. i dual boot win 10 and manjaro, wsl2 distro is ubuntu 20.04, and files are in wsl file system
This happens to me about once per month in WSL2. Corrupts ~/.zsh_history (adds some garbage characters to the file) as well as corrupting files in my the .git directory of the project I'm working on.
Fast Startup feature is disabled.
I have the "blessing" of getting this history file corruption on each and every reboot, possibly because I run a wsl job on startup and a window is kept open. Based on @anaisbetts's comment re the VM power being turned off impolitely, I tried to add a task when windows shuts down based on this page, with the action being wsl.exe --shutdown, and trying a few reboots I didn't get the corruption.
Not enough data to make this more than a personal anecdote, but maybe others will try it too...
I sometimes get this on reboots. when i open .zsh_history i visually search for garbage and delete the particular line which tends to be located near the end.
This can also happen when force restarting WSL2, in case networking stops working with:
Restart-Service -Force -Name hns
Restart-Service LxssManager
@elibarzilay I did create this script to run wsl.exe --shutdown too and seems the problems have ceased.
For anyone who wants to try it too to stop corrupting history and git:
- Create a Basic Task in Task Scheduler
- Name it
WSL Shutdown - Set the options when a specific event is triggered:
Type : On Event (Basic)
Log : System
Source : User32
EventID : 1074
- Set action as initiate a program/script
- Set
wsl.exe --shutdownand confirm
I'm using WSL Distro: Ubuntu 20.04 WSL Version: 2 Windows Version: 10 20H2
One warning though: at least in one case I had lost a file that was open in a windows app (via wsl$) which tried to save it after shutdown started, and it ended up with a corrupt (all NULs) file. (I think that it happened because I canceled the reboot, then saved the file, then rebooted -- and I'm guessing that the shutdown happened on the first reboot starting.)
I've added a task in the scheduler like @marceloavf suggested, however I just got another repository corrupted on the last shutdown.
Manually shutting down with wsl.exe --shutdown before shutting down seems to be still the more reliable method
I'm also encountering this issue. Both .zsh_history and project git files are being corrupted. It appears to happen somewhat randomly to me...
- WSL Distro:
Ubuntu 20.04 - WSL Version:
2 - Windows OS Build:
19042.630 - Fastboot is disabled.
- Primarily using the Windows Terminal app and sometimes using the integrated terminal in VSCode.
WSL corrupts my git repo every week.
- Distro:
Ubuntu 20.04 - WSL2
- Windows 20H2 (Build -
10.0.19042.630) - Using Windows Terminal by Microsoft.
Same here. Need to start testing the shutdown method. What are your methods to revert .git? right now I just clone the repo again and move all my changes there, so I don't lose my changes at least.
I use this:
rm -rf .git && # delete old corrupted repo
git init && # initialise new repo
git remote add origin "${url}" && # link to old repo
git fetch && # get old history
git reset origin/master --mixed # force update to old history
@therealkenc, not sure if you are the best person to ping, but I've seen you add the "bug" tag to other issues in this repo. It would nice if this issue could be triaged and acknowledged as a bug, since it seems to affect a bunch of people (25 likes in this issue, plues other open related issues like https://github.com/microsoft/WSL2-Linux-Kernel/issues/168 or https://github.com/microsoft/WSL/issues/5895). Right now I have the feeling nobody is looking at this, and I can confirm not only that it happens quite often, but also that it is a very annoying bug from a user perspective. From what I gather in the different issues, it seems to be related to how the WSL subsystem gets shut down.
Is there anything I can do to get this issue triaged?
This happened to me today. My local git repo got corrupted. Thankfully I had no pending commits.
I use this:
rm -rf .git && # delete old corrupted repo git init && # initialise new repo git remote add origin "${url}" && # link to old repo git fetch && # get old history git reset origin/master --mixed # force update to old history
I have two active branches: master and dev. What would the approach be then?
This happened to me today on a Windows 10 Pro, version 20H2, build 19042.685. I have a different laptop with Windows 10 Home Single Language, version 2004, build 19041.685 and this issue does not occur.
I use this:
rm -rf .git && # delete old corrupted repo git init && # initialise new repo git remote add origin "${url}" && # link to old repo git fetch && # get old history git reset origin/master --mixed # force update to old historyI have two active branches: master and dev. What would the approach be then?
I have found the following to be effective
find .git/objects/ -size 0 -exec rm -f {} \;
No need to resync the whole repo
Seems like MSFT is finally looking into this issue! ♥ https://github.com/microsoft/WSL2-Linux-Kernel/issues/168#issuecomment-754106399