If a file was deleted from your GitHub repository, you can restore it by browsing the commit history to find the commit just before the deletion, viewing the file as it existed at that point, copying its contents, and creating the file again in your current repository. GitHub never truly deletes anything — every past version of every file is preserved in the commit history. This works for files deleted by humans and AI tools alike.
Why Deleted Files Are Never Truly Gone on GitHub
One of the biggest advantages of version control is that nothing is ever permanently lost. When a file is deleted from a GitHub repository — whether by a human, an automation, or an AI tool like Lovable or Cursor — the deletion is recorded as a commit, but all previous versions of the file still exist in the commit history. Think of it like a filing cabinet where removing a folder from the drawer just means it moves to the archive — it is always retrievable. The process for restoring a deleted file involves three steps: finding the commit where the file still existed, viewing or copying its contents, and recreating the file in your current project. You can do all of this through the GitHub website without any terminal commands. This skill is essential for non-technical founders because AI tools sometimes remove files during code restructuring, and you may need to bring them back.
Prerequisites
- A GitHub account (free plan works)
- A repository where a file was previously deleted
- Write access to the repository
Step-by-step guide
Find the commit that deleted the file
Find the commit that deleted the file
Navigate to your repository on github.com and click the commit count above the file list to open the commit history. Browse through the commits looking for one that mentions deleting or removing the file — check the commit messages for keywords like "delete," "remove," or the filename itself. Click on commits to see their diffs. A deleted file appears entirely in red in the diff view. Once you find the commit that deleted the file, note the commit message and the file path. You'll need the commit just before this one to find the file still intact.
Expected result: You identify the commit that deleted the file and can see the file contents in the red (removed) section of the diff.
Browse the repository before the deletion
Browse the repository before the deletion
From the commit history page, find the commit that existed just before the deletion commit. Click the commit hash (the short alphanumeric code on the right side like "b7e4a2c") for that earlier commit. GitHub loads the entire repository as it existed at that point in time. You'll see a banner at the top saying you are viewing the repository at a specific commit. Navigate through the file tree to find the file that was later deleted — it should still be present in this historical view.
Expected result: You see the repository files as they were before the deletion, with the deleted file still present in the file tree.
View and copy the deleted file's contents
View and copy the deleted file's contents
Click on the file you want to restore. GitHub displays its full contents as they were at that point in time. Click the "Raw" button in the toolbar above the file to see the plain text without any GitHub formatting. Select all the content on the page (press Ctrl+A on Windows or Cmd+A on Mac), then copy it (Ctrl+C or Cmd+C). You now have the complete file contents in your clipboard, ready to recreate the file in your current repository.
Expected result: You have the complete contents of the deleted file copied to your clipboard.
Recreate the file in your current repository
Recreate the file in your current repository
Navigate back to your repository's current state by clicking the repository name in the breadcrumb navigation at the top. Go to the folder where the file originally lived. Click the "Add file" dropdown button above the file list and select "Create new file." In the filename field at the top, type the exact original filename (including the extension, like "utils.ts" or "config.json"). Paste the copied contents into the editor area (Ctrl+V or Cmd+V). Scroll down, write a commit message like "Restore deleted file [filename]," and click the green "Commit changes" button.
Expected result: The file is recreated in your repository with its original contents, saved as a new commit.
Verify the restored file matches the original
Verify the restored file matches the original
After committing, click on the newly restored file to open it. Compare its contents with what you saw in the historical view. Check that the filename, file extension, and folder location are correct. If the file is code that your application depends on (like a component file from a Lovable or V0 project), make sure the imports and references in other files still point to the correct path. If the file was moved or renamed before deletion, you may need to check that other files reference the new location.
Expected result: The restored file matches the original and is in the correct location within your repository.
Complete working example
1# File Restoration Checklist23## Before You Start4- [ ] Confirm the file is actually deleted (not just moved)5- [ ] Note the original filename and folder path6- [ ] Check if other files reference/import the deleted file78## Restoration Steps91. [ ] Open commit history (click commit count)102. [ ] Find the commit before the deletion113. [ ] Click the commit hash to browse old state124. [ ] Navigate to the deleted file135. [ ] Click Raw → Select All → Copy146. [ ] Go back to current repository157. [ ] Add file → Create new file168. [ ] Paste contents and name the file correctly179. [ ] Write a descriptive commit message1810. [ ] Click Commit changes1920## After Restoration21- [ ] Verify file contents match the original22- [ ] Check that imports/references still work23- [ ] Test the application if it depends on this fileCommon mistakes when restoring a Deleted File in GitHub
Why it's a problem: Creating the file with a different name or in the wrong folder
How to avoid: Double-check the original filename and path from the historical commit view. The file must be at the exact same path for imports and references to work. Use the breadcrumb navigation to recreate the correct folder structure.
Why it's a problem: Copying contents from the wrong commit
How to avoid: Make sure you are browsing the commit before the deletion, not the deletion commit itself. The deletion commit shows the file in red (removed) — you need the commit before that one where the file still exists normally.
Why it's a problem: Not checking if the file was moved rather than deleted
How to avoid: Sometimes files are renamed or moved to a different folder, which looks like a deletion. Search the current repository for the filename before assuming it was deleted — it may just be in a different location.
Why it's a problem: Restoring an outdated version of the file
How to avoid: If the file was edited multiple times before being deleted, make sure you copy from the most recent version before deletion, not an older version. Browse the commit just before the deletion commit.
Best practices
- Always check whether a file was moved or renamed before assuming it was deleted
- Browse the commit just before the deletion to get the most recent version of the file
- Use the Raw view when copying file contents to avoid copying GitHub's formatting artifacts
- Write a clear commit message when restoring, like 'Restore config.ts deleted in commit abc123'
- After restoring, verify that other files referencing the restored file still work correctly
- If AI tools like Lovable or V0 deleted the file during restructuring, check if the functionality moved to a different file before restoring the old one
- Consider reverting the deletion commit instead of manually copying if you want to undo the entire commit's changes
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
A file was accidentally deleted from my GitHub repository. Walk me through how to find the file in the commit history and restore it using only the GitHub website — no terminal commands.
Frequently asked questions
Is a deleted file permanently gone from GitHub?
No. GitHub preserves every version of every file in the commit history. Even if a file was deleted months or years ago, you can find it by browsing the commit history to a point before the deletion.
Can I restore a file that was deleted in a force-push?
Force-pushes can rewrite history, but GitHub usually keeps 'dangling commits' for 90 days. If you know the commit hash, you may be able to view it directly by URL. For complex recovery, ask a developer or contact GitHub support.
What if I do not know when the file was deleted?
Browse through the commit history looking for commit messages that mention deleting or removing files. You can also search for the filename in the commit search bar. Another approach is to browse progressively older commits until you find one where the file still exists.
Can I restore a file that an AI tool like Lovable deleted?
Yes. AI tools commit changes through GitHub just like humans. Find the Lovable bot's commit that removed the file, browse the commit before it, and copy the file contents to restore it.
Can RapidDev help me restore deleted files and fix broken references?
Yes. RapidDev's engineering team can locate deleted files in your commit history, restore them, and ensure all imports and references throughout your codebase still work correctly after restoration.
Is it better to restore manually or revert the deletion commit?
If the commit only deleted the file, reverting it is faster. If the commit made other changes you want to keep, manual restoration is better because it only brings back the file without undoing other work.
Can I restore an entire deleted folder?
Yes, but you need to restore each file individually. Browse the commit before the folder was deleted, then recreate each file one by one. For large folders with many files, using GitHub Desktop or asking a developer to help is more efficient.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation