Just found out that Sonic Pi Work Space Is Saved with git!

Today I lost a fun grove I made. I kept making little changes and was using control + z a lot. Apparently this can result in the buffer disappearing and leaving you with a commented message telling you that the buffer is loading and to restart sonic pi. I did and the buffer didn’t come back. I got kind of sad that I lost it forever.

I found a comment here from samaaron telling you that if you lose a buffer it may be saved in ~/.sonic-pi/store/default since works spaces are backed up with git.

For windows that’s

cd ..sonic-pi\store\default\

and sure enough git is sitting there! And I was able to checkout from earlier commit copy it and revert back to the master branch no problem.

So freaking cool!

Thank you for that Sam!!! Seriously cool.

6 Likes

Oh wow, I lived with many of those accidentally erased ideas. Never knew there was a solution for that. Thanks for posting this !

2 Likes

I’m glad it helps someone else. I figure not many are aware of this. It’s not exactly stated in the docs.

I think there should be a advanced documentation that has more details and useful tips.

Hi,

Well would you give us more details with git commands to illustrate your words. The steps you used to get back.
Cheers

Uh sure,

It’s rather simple but I imagine it be confusing to someone that has never used git before. I’m NOT going to explain how git works or every command. It’s really easy to look up.

I will detail a very simple use case to recover a old buffer for someone that doesn’t know terminal or git well.

Open power shell then type (for linux I’m pretty sure it would just ~ your home dir)

cd .\.sonic-pi\store\default\

Also in that folder you will notice a bunch of files. Just type pwd and copy and paste the path into file explorer. You will see the current files in your store. Those .spi files are just the .rb files currently in sonic pi. You can copy them out and see it just contains the text from your buffers. I use vs code to open the folder and quickly view the code. You can copy the text into a new .rb file to save it so you can load it back into sonic pi. You can probably just open them with notepad or vim if you know how to use it.

image

Check your log (think of it like backups)

git log 

You will see a bunch of commits with date, time and maybe a note on the buffer saved. You can keep pressing enter to view more and q to quit.
You can also use these commands below to more easily filter (just search for them on the internet).

# show the last 3
git log -3
# show x starting at some date 
git log -3 --until="2021-07-20" 

Once you find one with a date you think you last had the buffer saved. Copy the commit hash. Highlight text right click to copy, right click to paste.

git checkout 1755e91fe335ae5dd30212f3af0d6cc10fa7fbd7

If it gives you some message about worked unsaved or can’t do it. I recommend you manually save your buffers. Then enter

git checkout 1755e91fe335ae5dd30212f3af0d6cc10fa7fbd7 -f

the -f will FORCE git to checkout (but I think unsaved work will be lost so don’t be mad at me). You could also commit the buffers your currently have it’s easy to look up how to do it. But if you are lazy and have nothing to lose don’t worry about it.

Now you have loaded the buffers into that folder from that commit. Look at the files and you can see the previous code that’s in them. Copy and paste out or save the file somewhere as a .rb file.

Oh and last thing don’t forget to return the head back.

git checkout master
#or 
git checkout -  

This way sonic pi will continue storing it’s saves in the master branch correctly.

Disclaimer: This worked for me easy peasy but I kind of know what I’m doing. So please don’t be mad at me if something weird happens. If anyone can think of a easier way to write it out step by step go for it. Hope this helps someone.

4 Likes

hi,

thanks for your explanations.
Off topic for sonic pi, i dig into the git log options :slight_smile: (Git - pretty-formats Documentation)

$ git log -9 --pretty=format:"%n %cn committed %C(bold red) %h%Creset -- %C(bold blue)%cd%Creset %n %f %n"

Cheers

1 Like

I’ve been playing in my windows sandbox today, and thing I’ve got some unique undocumented behaviour - stuff like notepad not loading, like not for a second, nothing in procmon even… it’s a win/me thing.

Also whilst sonic-pi plays from in the sandbox, I have no .git - even when showing hidden and protected system files & folders… I installed my sonic-pi using winget (so v4.3 currently) but I suspect my missing .git is unique to me…

If anyone would care to test and confirm :+1: (but no biggy:)

Installed via the msi (4.3) and this issue fixed :+1: