snippetbashTip
git restore — Restore working tree files. Requires Git version 2.23+. See also: `git checkout`, `git reset`. More
Viewed 0 times
commandtreefilescliworkingrestorerequiresgit restore
Problem
How to use the
git restore command: Restore working tree files. Requires Git version 2.23+. See also: git checkout, git reset. More information: <https://git-scm.com/docs/git-restore>.Solution
git restore — Restore working tree files. Requires Git version 2.23+. See also: git checkout, git reset. More information: <https://git-scm.com/docs/git-restore>.Restore an unstaged file to the staged version:
git restore {{path/to/file}}Restore an unstaged file to the version of a specific commit:
git restore {{[-s|--source]}} {{commit}} {{path/to/file}}Discard all unstaged changes to tracked files:
git restore :/Unstage a file:
git restore {{[-S|--staged]}} {{path/to/file}}Unstage all files:
git restore {{[-S|--staged]}} :/Discard all changes to files, both staged and unstaged:
git restore {{[-W|--worktree]}} {{[-S|--staged]}} :/Interactively select sections of files to restore:
git restore {{[-p|--patch]}}Code Snippets
Restore an unstaged file to the staged version
git restore {{path/to/file}}Restore an unstaged file to the version of a specific commit
git restore {{[-s|--source]}} {{commit}} {{path/to/file}}Discard all unstaged changes to tracked files
git restore :/Unstage a file
git restore {{[-S|--staged]}} {{path/to/file}}Unstage all files
git restore {{[-S|--staged]}} :/Context
tldr-pages: common/git restore
Revisions (0)
No revisions yet.