Restoring deleted files based off initial commit?


Made a stupid mistake today and deleted a local repository before it had pushed to the web. Figured deleting it locally wouldn’t actually remove all the local files without sending them to some kind of recycle bin.

I’ve managed to restore the local repository and so have essentially the contents of all the files in the initial commit notes but none of these files exist on disk any more

Is there any way, bar going through and copy-pasting the contents of each file one file at a time to restore the files to disk?

Many thanks

In what form do you have the local repository now? If you have the .git folder that should be enough to check out the files again.

I have the .git folder so I have re-added the repository to the desktop client and can see the history with the initial commit.

The files which would have resided in the parent folder for the .git no longer exist. I have tried pulling the initial branch through the client, but it requires the files to be committed first which doesn’t work

This was enough to nudge me in the right direction.

The GitHub desktop client couldn’t do what I wanted but by opening the GIT GUI in the folder I could create a new branch from the initial commit and then check out that new branch restoring the files from the .git/objects


1 Like