git-restore
恢复工作树文件。
概要
bash
git restore [<options>] [--source=<tree>] [--staged] [--worktree] [--] <pathspec>...
git restore [<options>] [--source=<tree>] [--staged] [--worktree] --pathspec-from-file=<file> [--pathspec-file-nul]
git restore (-p|--patch) [<options>] [--source=<tree>] [--staged] [--worktree] [--] [<pathspec>...]描述
使用恢复源中的某些内容恢复工作树中的指定路径。如果路径被跟踪但在恢复源中不存在,它将被删除以匹配源。
该命令还可用于使用 --staged 恢复索引中的内容,或使用 --staged --worktree 同时恢复工作树和索引。
默认情况下,如果给出 --staged,则从 HEAD 恢复内容,否则从索引恢复。使用 --source 从不同的提交恢复。
选项
-s <tree>, --source=<tree>:使用给定树的内容恢复工作树文件。-p, --patch:交互式选择恢复源和恢复位置之间的差异块。-U<n>, --unified=<n>:生成具有 <n> 行上下文的差异。--inter-hunk-context=<n>:显示差异块之间的上下文。-W, --worktree:指定工作树为恢复位置。-S, --staged:指定暂存区为恢复位置。-q, --quiet:安静,抑制反馈消息。--progress, --no-progress:进度状态报告。--ours, --theirs:从索引恢复工作树中的文件时,使用阶段 #2(ours)或 #3(theirs)处理未合并的路径。-m, --merge:从索引恢复工作树中的文件时,在未合并的路径中重新创建冲突的合并。--conflict=<style>:与--merge选项相同,但更改冲突块的呈现方式。--ignore-unmerged:从索引恢复工作树中的文件时,如果有未合并的条目且未指定--ours、--theirs、--merge或--conflict,则不中止操作。--ignore-skip-worktree-bits:在稀疏检出模式下,忽略稀疏模式并无条件恢复 <pathspec> 中的任何文件。--recurse-submodules:如果 <pathspec> 命名了活动子模块且恢复位置包括工作树,则更新子模块。--no-recurse-submodules:不更新子模块工作树。--overlay, --no-overlay:在覆盖模式下,恢复时从不删除文件。在非覆盖模式下,删除不在 <tree> 中的跟踪文件。--pathspec-from-file=<file>:在 <file> 中传递路径规范。--pathspec-file-nul:仅与--pathspec-from-file一起使用。--:不再将任何更多参数解释为选项。<pathspec>...:限制受操作影响的路径。
示例
bash
$ git switch master
$ git restore --source master~2 Makefile
$ rm -f hello.c
$ git restore hello.c
$ git restore '*.c'
$ git restore .
$ git restore :/
$ git restore --staged hello.c
$ git restore --source=HEAD --staged --worktree hello.c另请参阅
Git
git 套件的一部分
