Version Control
Git: Getting started
Git: Getting started
  • Introduction
    • What is version control
      • Distributed VCS
      • Summary
    • What is Git?
      • A Short History of Git
      • Under the hood
      • The Three States
    • What is GitHub?
  • Setting up Git
    • Installation
    • First time setup
    • Creating a repo
  • Basic operations
    • Recording Changes
      • Add another file
      • Modify-stage-commit
      • Modify-direct commit
      • View log
    • Undo changes
      • Restore (modified)
      • Restore (staged)
      • Amend (rare)
    • Clone repos
  • Remote Repos
    • Configure remote
    • Push to remote
      • Push branches
  • Reference
    • My Git Tutorials
    • Git Official
    • Others
Powered by GitBook
On this page
  1. Basic operations
  2. Undo changes

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!

PreviousUndo changesNextRestore (staged)

Last updated 2 years ago