How to restore deleted commits on pythonanywhere

166 Views Asked by At

I have accidentally deleted my commits on pythonanywhere.com and now I see very old state of my files. My Django website isn't working at all.

What I did:

$ git reset --hard HEAD~1

And then:

$ git push --force

That was big mistake. I deleted commits from remote as well. What I wanted to do to fix it:

git reflog

And then use:

git reset --hard <sha value>

Unfortunately, bash console returned following error:

fatal: unable to write new index file

and then I have discovered that I am run out of space on my pythonanywhere account. It is strange, because before commits I had about 80% of used space, and now I have 100%. Is this the reason why I cannot use git reset command? I deleted single file to free up the space, but still it is telling me that space is 100% used. Now I see old version of my Django project, it never took up so much space.

What can I do to restore previous state of my files?

2

There are 2 best solutions below

6
VonC On

First, as documented in pythonanywhere Disk Quota, check what is using up all your space:

du -hs /tmp ~/.[!.]* ~/* | sort -h

Try and clean up as many files as possible, before attempting your git reset --hard <sha value>.
For instance, try also, to gain space, to "clear my local working directory" (assuming your current files are not the ones you want):

git clean -ndf # remove the n to actually remove files

Please advise, if I can remove folder called local. I think this is something auto-generated but I don't have knowledge about it and why it is so heavy

The .local folder is not generated by Django itself.
It is a folder created by the pip package manager when installing packages with the --user flag.
It is used to store user-specific packages and configurations.

You can safely delete it if you don’t need the packages installed in it anymore.
However, if you are still using the packages installed in it, you should not delete it.

In your case: delete it in order to get some free space and make your commit, then re-create it with your project build process, which will trigger the re-installation of the missing dependencies.

1
Percival On

I managed to reset to the previous commit and restored proper state of files, but still pythonanywhere is saying that I am using 100% of storage.

I did:

du -hs /tmp ~/.[!.]* ~/* | sort -h

And I found that the folder .local/ takes the most of space. Inside it, I see bin and lib folders with python3.6 folder and other Python-related stuff, but I don't know if I need this - I don't remember if that was present before reset.

Please advise, if I can remove folder called local. I think this is something auto-generated but I don't have knowledge about it and why it is so heavy. Is it commonly used in Django and needed?

I am unable to make new commit because when I am doing git add *, I see an error: fatal: error when closing sha1 file: Disk quota exceeded