webberpuma
webberpuma

Reputation: 733

How can I use git revert to restore all mistakenly deleted files?

I was at the initial commit (c0), and I used the command

find . -name \*.min.js -type f -delete

to delete all minimized JS files in my project, added the change to the staging area and made a commit (c1), then pushed it to remote repository. I did some work and made another commit (c2) and pushed it to remote repository.

However, I now regret I deleted the files and want to get back all the files. I've searched on the Internet and found the revert command; so I ran

git revert c0

to go back to the commit (c0), where I have not deleted the files. I thought that would allow me to see the deleted files again, but no luck. I thought I was doing the right thing...

I am new to Git. Is my basic understanding of revert wrong?

Upvotes: 2

Views: 399

Answers (1)

Petr Skocik
Petr Skocik

Reputation: 60056

You should be reverting c1, not c0. You want to revert the commit that introduced those deletes. That's c1.

What you should do now as a good git citizen that doesn't alter history (if you already pushed the c0 revert commit) is

  • git revert c3 (the c0 revert commit)

and then

  • git revert c1.

Upvotes: 7

Related Questions