# git restore

> The `git restore` command restores files in the working tree or the staging area.

## How do I discard or unstage changes with git restore?

The command that discards uncommitted changes in files. With the `--staged` flag, it removes files from the staging area while keeping changes. It is a clearer alternative to the file-related part of `git checkout`.

- Topic: Git Commands - Undo Changes
- Type: command

## Example

```bash
git status
git restore --staged config.json
git restore config.json
```

`--staged` first removes 'config.json' from the staging area, then plain `git restore` discards its uncommitted edits in the working tree.

## Common mistakes

- Running `git restore .` to unstage and losing all uncommitted edits, which cannot be recovered.

## Key points

- Unstaging uses `git restore --staged <file>`, which keeps the changes in the working tree.
- `git restore <file>` without `--staged` is used only when losing local changes is intended.
- Restoring a file from another commit uses `--source`, e.g. `git restore --source=HEAD~1 <file>`.

## Interview questions

### What is the difference between git restore and git checkout?

`git restore` only restores files and `git switch` only changes branches. Both split up jobs that `git checkout` used to do alone.

### Can I undo git restore?

Usually not. Unstaged edits discarded by `git restore` were never stored by Git, so only an editor history or backup can bring them back.

## Related cards

- [git switch](https://wonderium.dev/processes/git-switch.md)
- [`git reset <commit>`](https://wonderium.dev/processes/git-reset.md)
- [`git checkout <branch>`](https://wonderium.dev/processes/git-checkout.md)
- [git status](https://wonderium.dev/processes/git-status.md)
- [git stash](https://wonderium.dev/processes/git-stash.md)

---

- Level: [Processes](https://wonderium.dev/processes.md)
- HTML version: https://wonderium.dev/processes/git-restore
- Last updated: 2026-11-25
