Search code examples
gitgithubrestore

I accidentally clicked a button that deleted all commits made for a website, but I have a backup on my computer - how to restore?


On the github website, it said something like "you are xx commits ahead and user2 is xx commits behind". I saw that for a long time and thought I had to do something to solve that. So I clicked it and it took my website back to where it was 8 months ago.

The place I clicked says "This branch is up to date with user/repository:main." when there are no commits. I don't remember exactly what it said before I clicked anymore.

I have a whole backup of the repository on my computer, and I use rstudio for it. However, when I try to "commit" or force push, there is nothing to click to commit and it also asks for my password and username, but then it says that this type of authentification is not supported anymore.

Not sure what to do.


Solution

    1. You have to open the shell.
    2. Go into the backup folder (a real clone of the repository).
    3. Issue the command git push origin.

    Edit: if you want to replace the remote repository with your backup copy (NO CLONE, NO COMMITS HISTORY!).

                                                        ▒██         ███          
     █████░                                             █░            █      █   
     █   ▒█                                             █             █      █   
     █    █  ███           ▓██▒  ░███░   █▒██▒  ███   █████  █   █    █      █   
     █   ▒█ ▓▓ ▒█         ▓█  ▓  █▒ ▒█   ██  █ ▓▓ ▒█    █    █   █    █      █   
     █████░ █   █         █░         █   █     █   █    █    █   █    █      █   
     █   ▒█ █████         █      ▒████   █     █████    █    █   █    █      █   
     █    █ █             █░     █▒  █   █     █        █    █   █    █          
     █   ▒█ ▓▓  █         ▓█  ▓  █░ ▓█   █     ▓▓  █    █    █▒ ▓█    █░     █   
     █████░  ███▒          ▓██▒  ▒██▒█   █      ███▒    █    ▒██▒█    ▒██    █  
    
    1. Open the shell.
    2. Go into the backup folder
    3. git init.
    4. git remote add origin <REMOTE_REPOSITORY_URL>.
    5. git add --all.
    6. git commit -m "Whole replacement commit.".
    7. Replace remote repository by: git push --force.

    Good luck!