mbbill / undotree

The undo history visualizer for VIM
http://www.vim.org/scripts/script.php?script_id=4177
BSD 3-Clause "New" or "Revised" License
3.97k stars 101 forks source link

restore deleted file #116

Open MyMyrtle opened 4 years ago

MyMyrtle commented 4 years ago

Hi,

I have deleted a file which I would like to restore. I can see the undo file is still there, for example:

ls ~/.vim/tmp/undo/%etc%sysctl.conf

Of course when I try to open /etc/sysctl.conf it is empty and no undo tree is visible in vim. Even trying rundo ls .vim/tmp/undo/%etc%sysctl.conf says "File contents changed, cannot use undo info". Is there any option to recover it with the undo info?

I love undotree!!

Best

mbbill commented 4 years ago

AFAIK VIM's undo file (in this case the one under you .vim/tmp/undo/ folder) doesn't store all the file contents for each undo version, instead it saves the diff, which means you need the original file as the base version in order to go back to any of the history versions. So I'm sorry you lost your file, but it seems like there isn't much you can do for it. However, if you happen to have a swap file, you might be able to restore it.

VimWei commented 8 months ago

However, if you happen to have a swap file, you might be able to restore it.

I creat a wiki page with vimwiki, and there is a : in the name such as 20240322foo10:00bar.md. Vimwiki can create, edit and save this page. And this page can be reopened with the same name after closing Vim. However, I found that the page file is actually saved as short name 20240322foo10 on the disk and the file size is 0.

image

And undotree work fine with the full name 20240322foo10%00bar.md.

image

Because I discovered the problem later, I deleted those zero-size files. Fortunately, I have backups of these files. However, when I put the backup files back and Vimwiki opens them with the original full names, the content is blank, and I can't use undotree either.

Is there any way to restore the files in this situation?

mbbill commented 8 months ago

tbh I'm not exactly sure what's happening here. I guess you might have hit some weird rare edge case bugs or something.