How to restore files entirely from a commit in Git?
dev.to·1d·
Discuss: DEV
Flag this post

I was working on my Spring Boot app when I accidentally moved the folder that contained the Git repository into another directory. When I tried to load it in Spring Tools Suite (STS), the IDE — due to its workspace cache — treated it as a new project. Not realizing this, I deleted the “new” project from the workspace, and all the changes I had made were gone.

I tried pulling it from the remote repository, but the local folder was missing.

So, I decided to restore the files from an earlier commit in my GitHub repository — before I made the mistake.

This is how I did it!

Step 1: Make sure you’re on the main branch

git checkout master
(or git checkout main depending on your branch name)

Step 2: Create a new branch to restore from old commit

This protects your cu…

Similar Posts

Loading similar posts...