Recovering command history in Jupyter Notebook?

Something similar happened to me where I could not save what I did, refreshed the page, and lost all my commands.

You can get your entire notebook history and redirect the output to any given file by running

%history -g -f filename

In my case, I redirected it to a (.py) file. You can find more documentation here https://ipython.readthedocs.io/en/stable/interactive/magics.html under "%history".


You can get the IPython history, which Jupyter Notebook uses as its kernel. In one of the cells run:

%history

This will dump a history (good, bad, and ugly) of every command you have run in the current IPython session. It is probably more than you want, but it is better than losing all your work.