Search code examples
jupyter-notebookjupyterjupyter-labundorecovery

How to un-delete cells in Jupyter Lab?


Can it be done?

"Undo" only seems to work for blocks/lines of code within a cell

Cheers


Solution

  • Option 1

    Edit > Undo Cell Operation (or using the shortcut Z in the command mode - to access the command mode press ESC)

    or

    Edit > Undo (or using the shortcut CTRL+Z)

    enter image description here


    Option 2

    Alternatively, if one didn't restart the kernel, one can export the IPython history by running

    %history -g   # If one wants to give a name to the file add "-f NAME" 
    

    Or access the content of all cells (including deleted ones) with _ih such as

    _ih[-10:]
    

    Option 3

    If one already restarted the kernel, File > Revert Notebook to Checkpoint

    enter image description here

    Checkpoints will be stored in .ipynb_checkpoints so one can look inside the files and see if the deleted cell is there.