3

I want to undo the git restore . command.

I wanted to pull changes from the origin, and WebStorm notified me that I need to commit all changes before the pull. I restored all changes. And now I remembered that there are changes that need to be committed. So I want to undo the git restore . command.

How can I do it?

1

1 Answer 1

6

You can't undo a git restore with git. The documentation tells you in the Important section that it's a dangerous command.

It’s important to understand that git restore is a dangerous command. Any local changes you made to that file are gone — Git just replaced that file with the last staged or committed version. Don’t ever use this command unless you absolutely know that you don’t want those unsaved local changes.

Git recommends to either stash / branch your changes if you are unsure what to do with them currently, but still need to move to another branch or pull or etc.

Edit: this applies for the git checkout -- <...> approach as well. Same warning and dangers.


Possible solution: If you text editor is still opened with the file you have restored, then you can undo (through whatever undo command your editor supports, maybe Ctrl+Z) to get back your changes. That is - if you are lucky to have your important changes saved into memory by your editor.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.