/github-for-non-tech

How to restore a deleted file in GitHub?

Restore a deleted GitHub file quickly with our step-by-step guide: locate the commit, checkout the file, stage, commit, and push your changes back to GitHub.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to restore a deleted file in GitHub?

 
Step 1: Identify the commit where the file was deleted
 

First, you need to find the SHA-1 hash (commit ID) of the commit just before the file deletion. Limiting the log to the file path shows you only relevant entries.

  • Open your terminal in the repository root.
  • Run this command, replacing path/to/your/file with the deleted file’s path:

git log -- path/to/your/file

 
Step 2: Check out the file from that commit
 

Once you have the commit hash (for example abc1234), you can retrieve the deleted file into your working directory without altering your current branch.

  • Use git checkout specifying the commit hash and file path:

git checkout abc1234 -- path/to/your/file

This restores the file state from commit abc1234 into your working directory.

 
Step 3: Stage the restored file
 

With the file back in your working directory, you need to add it to the staging area so it can be committed.

  • Stage the file using:

git add path/to/your/file

 
Step 4: Commit the restoration
 

Create a new commit that records the file restoration on your current branch.

  • Run:

git commit -m "Restore deleted file path/to/your/file"

 
Step 5: Push your changes to GitHub
 

Finally, upload your new commit to the remote repository so the file is restored on GitHub.

  • If you’re on main (or another branch), push with:

git push origin main

After the push completes, navigate to your GitHub repository to confirm that the deleted file has been restored.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022