How to discard all unstaged changes?

git checkout .

To discard all your unstaged changes made to files tracked by git use git checkout .

Changes in untracked files won't be discarded.

Layer 1
Terminal Example
git status
On branch main
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
    modified:   README.md
    modified:   code.rb

Untracked files:
  (use "git add ..." to include in what will be committed)
    new_file.rb

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

git checkout .
Updated 2 paths from the index

git status
On branch main
Untracked files:
  (use "git add ..." to include in what will be committed)
    new_file.rb

nothing added to commit but untracked files present (use "git add" to track)

See git checkout to learn more about it.

Last modified on November 30, 2021.

You might also like