How to recover deleted Jupyter notebook cell?

If you need to undo something deleted inside a cell, press:
CTRL/CMD + Z

If you need to recover an entire deleted cell hit:
ESC + Z.
Especially this second tip might be useful if you delete a lot of cells by mistake.


If the notebook kernel is still running and you executed the cell, you can find the content of all cells, including the deleted ones in _ih. For example, the last five cells:

_ih[-5:]

If you go to "Edit", there's an option for "Undo Delete Cells".

In MacOS

If you are familiar with shortcuts, you can do cmd + shift + p and then type in undo to recover as well. No need to moving your mouse around.

In Windows

First, switch to command mode by pressing ESC, then you can press Z to recover the deleted cells. (Thanks to @nik7 who proposed this answer)


First, switch to command mode by pressing ESC, then you can press Z to recover the deleted cells. It works even in Jupyter Lab which doesn't have "Undo Delete Cells" option under "Edit" tab.