tl;dr git restore -- .

I can't believe I didn't know this! Maybe, at one point, I did, but, since forgotten.

You're in a Git repo and you have edited 4 files and run git status and see this:


❯ git status
On branch main
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:   four.txt
    modified:   one.txt
    modified:   three.txt
    modified:   two.txt

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

Suppose you realize; "Oh no! I didn't mean to make those changes in three.txt" You can restore that file by mentioning it by name:


❯ git restore three.txt

❯ git status
On branch main
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:   four.txt
    modified:   one.txt
    modified:   two.txt

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

Now, suppose you realize you want to all of those modified files. How do you restore them all without mentioning each and every one by name. Simple:


❯ git status
On branch main
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:   four.txt
    modified:   one.txt
    modified:   two.txt

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

❯ git restore -- .

❯ git status
On branch main
nothing to commit, working tree clean

The "trick" is: git restore -- .

As far as I understand restore is the new word for checkout. You can equally run git checkout -- . too.

Comments

Alena Sajdlová

SECRET_TOKEN_NEEDED: ${{ secrets.SPECIAL_SECRET }}
        run: ./scripts/analyze.py --repo-root=./pr-code

Your email will never ever be published.

Previous:
How slow is Node to Brotli decompress a file compared to not having to decompress? January 19, 2024 Linux, Node, macOS
Next:
How to avoid a count query in Django if you can February 14, 2024 Python, Django
Related by category:
xbar-my-prs Info about your GitHub PRs in the macOS menu bar January 29, 2026 macOS
Find GitHub Pull Request by commit SHA August 21, 2025 GitHub
Set up iTerm to delete whole words on Option-Backspace May 13, 2025 macOS
How to run a GitHub Action workflow step if a file exists April 24, 2023 GitHub