2019-08-23 18:22:38 +01:00
|
|
|
# git restore
|
|
|
|
|
2021-01-07 14:06:38 +00:00
|
|
|
> Restore working tree files. Requires Git version 2.23+.
|
2021-01-07 12:58:00 +00:00
|
|
|
> See also `git checkout` and `git reset`.
|
2021-01-08 15:24:00 +00:00
|
|
|
> More information: <https://git-scm.com/docs/git-restore>.
|
2019-08-23 18:22:38 +01:00
|
|
|
|
2021-01-07 12:58:00 +00:00
|
|
|
- Restore an unstaged file to the version of the current commit (HEAD):
|
2019-08-23 18:22:38 +01:00
|
|
|
|
|
|
|
`git restore {{path/to/file}}`
|
|
|
|
|
2021-01-07 12:58:00 +00:00
|
|
|
- Restore an unstaged file to the version of a specific commit:
|
2019-08-23 18:22:38 +01:00
|
|
|
|
|
|
|
`git restore --source {{commit}} {{path/to/file}}`
|
|
|
|
|
2021-01-07 12:58:00 +00:00
|
|
|
- Discard all unstaged changes to tracked files:
|
2019-08-23 18:22:38 +01:00
|
|
|
|
2021-01-07 12:58:00 +00:00
|
|
|
`git restore :/`
|
|
|
|
|
|
|
|
- Unstage a file:
|
|
|
|
|
|
|
|
`git restore --staged {{path/to/file}}`
|
|
|
|
|
|
|
|
- Unstage all files:
|
|
|
|
|
|
|
|
`git restore --staged :/`
|
|
|
|
|
|
|
|
- Discard all changes to files, both staged and unstaged:
|
|
|
|
|
|
|
|
`git restore --worktree --staged :/`
|
|
|
|
|
|
|
|
- Interactively select sections of files to restore:
|
|
|
|
|
|
|
|
`git restore --patch`
|