Press Ctrl+Z to undo when you accidentally remove or overwrite anything. If you in the meantime move to another note you can still go back to the note in question and undo as long as you don’t restart Obsidian.
See also:
Edit: Changed redo to undo in title.