There's a few steps involved so let's go through them.
First and foremost, it's important that you understand that "lost commits" are not permanently lost immediately but may still reside on disk for a limited time. It is very important that you don't push or modify the repository in question further before attempting to fix your current problem
Additionally, depending on what you've done to the repository already, it may already be too late. But let's assume it isn't and see if we can retrieve your lost file.
First, navigate to your GitHub repository in question, let's say this is this (I'm using my own repository as an example, please edit the pertinent bits as indicated below):
https://github.com/lassevk/LVK
^--edit---^
Then let's edit the URL somewhat to grab the event log of your repository:
https://api.github.com/repos/lassevk/LVK/events
^--edit---^
This should give you a json file. In this json file you need to search for the file in question, or its contents, using Ctrl-F in your browser. Let's say you find it and it looks like this:
"commits": [
{
"sha": "a52da7697640b77f0b2e16de8d6e8ad8c29924e2",
"author": {
"email": "lasse@vkarlsen.no",
"name": "Lasse Vågsæther Karlsen"
},
"message": "Rewrite HttpClient related code.",
"distinct": false,
"url": "https://api.github.com/repos/lassevk/LVK/commits/a52da7697640b77f0b2e16de8d6e8ad8c29924e2"
See that SHA there? Copy it and paste it into the following type of link:
https://github.com/lassevk/LVK/commit/a52da7697640b77f0b2e16de8d6e8ad8c29924e2
^-------------------------edit----------------------------^
If this gives you a "404 not found" then you're out of luck as far as I know.
However, if it opens up the commit page then you can open the files modified one by one and download their raw content directly to your local disk as files, these you can then integrate into your repository as you see fit.
If you want to create a branch for the commit and deal with it later, you can by using this URL instead:
https://github.com/lassevk/LVK/tree/a52da7697640b77f0b2e16de8d6e8ad8c29924e2
^--edit---^ ^------------------edit----------------^
This should open up the repository browser for that commit, and you can then use the dropdown for branches to create a new branch that points to the commit. Once a branch points to a commit, it is no longer lost.
For instance, you can then locally do the following:
git fetch
git checkout master # or whichever branch this is on
git merge NAME-OF-TEMP-BRANCH
This should merge that file into your branch.