Restore (modified)

Restore (modified)

What if you realize that you don’t want to keep your changes to the file? How can you easily unmodify it — revert it back to what it looked like when you last committed (or initially cloned, or however you got it into your working directory)

The below steps shows how a file was modified and then unmodified using the git restore command:

git status

On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   hello.txt

no changes added to commit (use "git add" and/or "git commit -a")
git restore .
git status

On branch master
nothing to commit, working tree clean

Note: instead of unmodifying all files, we can select a specific file by giving its name in the above restore command in place of .

A reload might be required in the text editor to reflect the changes which Git is doing, but tools like VS Code and IDEs usually refresh it automatically!

Last updated