Restoring A Deleted File On GitHub

Goal: In this exercise you will familiarize yourself with the process of finding a file that you previously deleted and then restoring it (un-deleting it), all on GitHub.com

WARNING: You must do this exericse BEFORE doing the exercise about working with a git repo locally.
In this exercise you make a change to your copy of a project online.  In the next exercises you will download your copy and continue to modify it.

You must do this exercise first so that the changes you make at the end of this exercise will be downloaded in the next exercise.
 Your project on the GitLab server
Roadmap for these tutorials

Restoring a Deleted A File On GitHub

You may remove a file and then later on want to look at that file again, and/or you may want to put that file back into the repository.  Let's look at one way of doing this in GitHub.com

The first step is to log into GitHub and find the repo that you wish to work with.  Since this was covered in a prior tutorial we're not going to cover it again here.

Once you've open the repository you should click on the 'Commits' tab at the top of the list of files, as pictured here:

Restore: commits tab

Once you've opened clicked on that you'll be shown a list of all the commits (changes) that have been made to the repo.

Restoring a file: list of commits

Because we want to find a file that's been deleted we'll need to go to the most recent commit that happened BEFORE we deleted the file. In the above example we're going to open the commit with the message "Experimenting with a Word file" because in the next commit the file has already been removed.

If you want to see a description of the commit itself you can click on either link that the '1' points to in the above image.  To be clear: clicking on the message "Experimenting with a Word file" or clicking on the "b6dd169" in the above image takes you to the same page.  It's good for you to look at that page both to see what's there, and in case you accidentally end up there when trying to restore a file later.

However, we want to browse the files that were present in the repo after that commit was made, so you should instead click on button pointed to by the '2' (which looks like two brackets: "< >" ).

At this point you'll see something that looks just like the normal list of files except that it's from a point in time in the past.  Specifically, you'll notice that the file named logo_bluegrey_4in_jpg.jpg is present again:

Restore: list of previous files

At this point you can click on that file to see the page that describes that one file, then click on the 'Download' button and download that copy of the file back to your computer.

Restore: Download previously deleted file

Once you've done that you can then go back to the main page for your repo and Upload that file again.  (Since this was covered in a previous tutorial we won't talk about it here)

Please note that there are other ways of accomplishing this.  For example, if the file was deleted in the most recent commit you may be able to amend that most recent commit.