Skip to main content

How to Discard Changes in Git (with git restore)

Short answer

To discard all uncommitted changes in your working directory and return every tracked file to its last committed state, run git restore . (Git 2.23+) or the older git checkout -- .. For a single file, use git restore path/to/file or git checkout -- path/to/file. If you also have staged changes, first unstage them with git restore --staged . and then discard the unstaged changes with git restore .. Untracked files — new files not yet added to Git — are not affected by git restore; remove those separately with git clean -fd. These operations are permanent: the discarded edits cannot be recovered through Git, so review git status carefully and consider git stash instead if there is any chance you might want the changes later.

No matter how experienced you are as a programmer, not all of your code will always work at the first try. Luckily, Git allows you to discard and undo any of your changes, providing a safety net for your work.

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!

Free. We email you a ZIP with our cheat sheets.


Discarding Local Changes in a File

Changes that haven't been committed are called "local" changes — they exist in your working copy but haven't been wrapped in a commit yet.

To discard all uncommitted local changes in a specific file:

Careful: this command can discard work.

git restore index.html

Be careful: you cannot get these changes back once you've discarded them.

To discard all local changes across the entire project at once:

Careful: this command can discard work.

git restore .

If you also have untracked (new) files you want to remove:

Careful: this command can discard work.

git clean -fd


No Command Line Needed

Discarding Changes in Tower

In case you are using the Tower Git client, you can discard local changes in a file simply from its contextual menu — or even discard only _parts_ of your changes while keeping the rest:

Although it's not possible in Git, Tower allows you to undo any wrongfully discarded changes with a simple shortcut: CMD+Z (or CTRL+Z on Windows)!

Unstaging Changes

If you've run git add but haven't committed yet and want to remove files from the staging area (without touching the actual file contents), use the --staged flag:

git restore --staged index.html

To unstage everything at once:

git restore --staged .

For fine-grained control, the --patch flag lets you step through each changed chunk interactively and choose whether to unstage or discard it:

Careful: this command can discard work.

git restore --patch index.html


No Command Line Needed

Discarding / Unstaging Chunks or Lines in Tower

Using the Tower Git client, you can easily select the exact chunks & lines you want to stage, unstage, or discard:

Restoring a Specific Revision of a File

You can restore a file to how it looked at any point in history using the --source flag:

Careful: this command can discard work.

git restore --source 7173808e index.html
git restore --source master~2 index.html

The first example restores the file as it was in commit 7173808e. The second restores it as it was two commits before the current tip of master.

Saving Changes to the Stash

If you're not sure whether you'll need your changes later, save them temporarily on the stash instead of discarding them:

git stash --include-untracked

This leaves you with a clean working copy while preserving the changes. To restore them later:

git stash pop


No Command Line Needed

Stashing in Tower

In case you are using the Tower Git client, saving to and restoring from the Stash can be performed right from the toolbar:

Free download

Download the Cheat Sheet

Get 18 of our most popular Cheat Sheets in one handy ZIP!