How to Restore Deleted Files from Git Staging Area

In the last blog, we saw how files can be removed from the staging area or working directory using git rm. But what if you delete a file from your working directory by mistake and realize it’s still in the staging area?

👉 Can we bring it back? Yes, with the help of the git restore command.


Scenario: File Deleted from Working Directory but Still in Staging

Let’s say we have a file called wrong.txt. We delete it using Linux rm:

rm wrong.txt

Now check:

ls

Output:

# nothing — wrong.txt is gone locally

But when you check Git status:

git status -s

Output:

D  wrong.txt

Git still knows about the file because it is staged as deleted.


Restoring the File with git restore

If you want to bring the file back from the staging area into your working directory:

git restore wrong.txt

Check again:

ls

Output:

wrong.txt

✅ The file is restored back to your working directory.

This is especially helpful when you accidentally delete a file locally but haven’t committed the deletion yet.


When to Use git restore

At this stage, we are mainly using git restore to recover files from the staging area back into the working directory.

Later, when we move into the commit process, we’ll revisit this command and see its more advanced use cases (like restoring files from previous commits). Click Here to See Full tutorials on Git Resotre


🚀 Don’t Miss Out!

Now you know how to safely remove files from Git’s staging area and working directory. In the next blog, we’ll learn how to recover files from Git after accidental removal.

👉 Subscribe to Learning Ocean – Subscribers get coupon codes, early access to blogs/courses, and exclusive YouTube videos.

👉 My YouTube Channel

👉 Watch this video explanation

Stay curious, keep coding, and let’s master Git together! 🎉