Read Anthropic’s case study about Graphite Reviewer

How to git restore all

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


The git restore command, introduced in Git version 2.23, offers users the ability to revert changes in their working directory and staging area. This guide explores how to use the git restore command to manage different types of restoration scenarios, such as restoring all files, staged changes, and deleted files.

The git restore command is used to undo changes made to the working directory and staging area. It's a safer alternative to git reset for discarding changes because it's more explicit about what it affects and doesn't alter the commit history.

To start using git restore, you need to understand its basic syntax and options:

Terminal
git restore [options] <paths>
  • <paths>: Specifies the files or directories to restore.
  • [options]: Includes various flags like --source, --staged, and --worktree to control the restore behavior.

To restore all changes in your working directory, run:

Terminal
git restore .

This command reverts all modified and deleted files in the working directory to their last committed state, but does not affect the staging area (the holding zone for changes that are prepared to be committed to the repository).

To unstage all files (i.e., restore the staging area to match the HEAD commit), use:

Terminal
git restore --staged .

This command removes all changes from the staging area but leaves the working directory files as they were.

To restore all files in both the working directory and staging area, you can combine the commands:

Terminal
git restore --source=HEAD --staged --worktree .

This will reset both the staging area and working directory for all files to their state in the last commit.

If you have deleted files that you want to restore:

Terminal
git restore --source=HEAD <path_to_deleted_files>

You can specify individual files or use a pattern to include multiple files.

To revert all modifications (but not deletions):

Terminal
git restore --source=HEAD -- <path_to_modified_files>

This command only affects modified files, ignoring any files that have been added or deleted.

  • Check status first: Always use git status to review the changes you're about to restore, ensuring you do not unintentionally lose work.
  • Selective restoration: Instead of restoring everything, consider restoring changes file by file or section by section, especially in complex projects.

The git restore command is a powerful tool for managing the current changes in your repository. It provides a flexible way to undo changes in your working directory and staging area, helping maintain a clean and organized code base.

For further reading see the official Git documentation.

On this page
Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2