###### Table of Contents
- [[#Important Options]]
- [[#Usage Examples]]
# git restore
**The "restore" command helps to unstage or even discard uncommitted local changes.**
On the one hand, the command can be used to undo the effects of `git add` and unstage changes you have previously added to the Staging Area.
On the other hand, the `restore` command can also be used to discard local changes in a file, thereby restoring its last committed state.
## Important Options
#### `<filename>`
**The name of a file (or multiple files) you want to restore.** Naming the file you want to restore can be as simple as providing the filename / path to a single file. But you can also provide multiple filenames (delimited by spaces) or even a wildcard pattern (e.g. `*.html`). Another option is to provide the `.` character, thereby restoring all files in the current directory.
#### `--staged`
**Removes the file from the Staging Area, but leaves its actual modifications untouched.** By default, the `git restore` command will discard any local, uncommitted changes in the corresponding files and thereby restore their last committed state. With the `--staged` option, however, the file will only be removed from the Staging Area - but its actual modifications will remain untouched.
#### `--source <ref>`
**Restores a specific revision of the file.** By default, the file will be restored to its last committed state (or simply be unstaged). The `--source` option, however, allows you to restore the file at a _specific revision_.
#### `--patch`
## Usage Examples
To only _unstage_ a certain file and thereby undo a previous `git add`, you need to provide the `--staged` flag:
```shell
$ git restore --staged index.html
```
If, additionally, you have untracked (i.e., new) files in your Working Copy and want to get rid of those, too, then the `git clean` command is your friend:
```shell
$ git clean -f
```
You can of course also remove multiple files at once from the Staging Area:
```shell
$ git restore --staged *.css
```
If you want to discard uncommitted local changes in a file, simply omit the `--staged` flag. Keep in mind, however, that you cannot undo this!
```shell
$ git restore index.html
```
If you want to undo _all_ of your current changes, you can use the "." parameter (instead of specifying a file path):
```shell
$ git restore .
```
Another interesting use case is to restore a specific historic revision of a file:
```shell
$ git restore --source 7173808e index.html
$ git restore --source master~2 index.html
```
The first example will restore the file as it was in commit #7173808e, while the second one will restore it as it was "two commits before the current tip of the master branch".
___
**Tags**: #git #restore