Information

Author(s) Mathieu Jadin
Deadline No deadline
Submission limit No limitation

Sign in

Git Disaster Scenario 3 - Back up some code after erasing the local and remote histories

You have been careless when using git reset --hard and you then erase the remote history with git push --force.

The modifications you made are no longer in the staging zone, neither locally nor remotely. However, you can fetch your modifications back as long as you did not delete the folder .git of your project!

To do this, you need to modify the reference logs, accessible using git reflog. These logs contain all the changes made on all branches in your history. You may thus get back all the commits that you erased. Once you identified the reference you want to get back to, you may use git merge to back up the modifications in your repository (and use git push to push these changes to the remote repository).


Download the archive which already contains a cloned repository in the subfolder clone. Your repository have local and remote histories one commit apart due to a wrong manipulation. Use reflog to find all deleted commits and push them again on the remote repository.

Afterwards, zip the whole folder and upload it.

Note that the remote repository in this exercise is not on GitHub or Bitbucket but inside the folder bare.git of the archive.

git-reflog/
├── bare.git/
|   └── [...]
└── clone/
    └── [...]

Max file size: 1.0 MiB
Allowed extensions: .zip