← 返回命令列表

Linux command

git-restore 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Restore working tree file

git restore [file]

Restore from specific commit

git restore --source=[commit] [file]

Unstage file

git restore --staged [file]

Restore all files

git restore .

Restore both staged and working tree

git restore --staged --worktree [file]

Interactive restore

git restore -p [file]

说明

git restore restores working tree files or unstages changes from the index. Introduced in Git 2.23 to provide a clearer alternative to the file-restoration aspects of `git checkout`. Use `--staged` to unstage files, `--worktree` (the default) to discard working tree changes, or both together to restore a file completely to a previous state.

参数

--source _tree_
Restore from tree.
-s _tree_
Short for --source.
--staged
Restore index (unstage).
--worktree
Restore working tree.
-S
Short for --staged.
-W
Short for --worktree.
-p, --patch
Interactive mode.

FAQ

What is the git-restore command used for?

git restore restores working tree files or unstages changes from the index. Introduced in Git 2.23 to provide a clearer alternative to the file-restoration aspects of `git checkout`. Use `--staged` to unstage files, `--worktree` (the default) to discard working tree changes, or both together to restore a file completely to a previous state.

How do I run a basic git-restore example?

Run `git restore [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --source _tree_ do in git-restore?

Restore from tree.