1GIT-RESTORE(1)                    Git Manual                    GIT-RESTORE(1)
2
3
4

NAME

6       git-restore - Restore working tree files
7

SYNOPSIS

9       git restore [<options>] [--source=<tree>] [--staged] [--worktree] [--] <pathspec>...
10       git restore [<options>] [--source=<tree>] [--staged] [--worktree] --pathspec-from-file=<file> [--pathspec-file-nul]
11       git restore (-p|--patch) [<options>] [--source=<tree>] [--staged] [--worktree] [--] [<pathspec>...]
12

DESCRIPTION

14       Restore specified paths in the working tree with some contents from a
15       restore source. If a path is tracked but does not exist in the restore
16       source, it will be removed to match the source.
17
18       The command can also be used to restore the content in the index with
19       --staged, or restore both the working tree and the index with --staged
20       --worktree.
21
22       By default, if --staged is given, the contents are restored from HEAD,
23       otherwise from the index. Use --source to restore from a different
24       commit.
25
26       See "Reset, restore and revert" in git(1) for the differences between
27       the three commands.
28
29       THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
30

OPTIONS

32       -s <tree>, --source=<tree>
33           Restore the working tree files with the content from the given
34           tree. It is common to specify the source tree by naming a commit,
35           branch or tag associated with it.
36
37           If not specified, the contents are restored from HEAD if --staged
38           is given, otherwise from the index.
39
40           As a special case, you may use "A...B" as a shortcut for the merge
41           base of A and B if there is exactly one merge base. You can leave
42           out at most one of A and B, in which case it defaults to HEAD.
43
44       -p, --patch
45           Interactively select hunks in the difference between the restore
46           source and the restore location. See the “Interactive Mode” section
47           of git-add(1) to learn how to operate the --patch mode.
48
49           Note that --patch can accept no pathspec and will prompt to restore
50           all modified paths.
51
52       -W, --worktree, -S, --staged
53           Specify the restore location. If neither option is specified, by
54           default the working tree is restored. Specifying --staged will only
55           restore the index. Specifying both restores both.
56
57       -q, --quiet
58           Quiet, suppress feedback messages. Implies --no-progress.
59
60       --progress, --no-progress
61           Progress status is reported on the standard error stream by default
62           when it is attached to a terminal, unless --quiet is specified.
63           This flag enables progress reporting even if not attached to a
64           terminal, regardless of --quiet.
65
66       --ours, --theirs
67           When restoring files in the working tree from the index, use stage
68           #2 (ours) or #3 (theirs) for unmerged paths.
69
70           Note that during git rebase and git pull --rebase, ours and theirs
71           may appear swapped. See the explanation of the same options in git-
72           checkout(1) for details.
73
74       -m, --merge
75           When restoring files on the working tree from the index, recreate
76           the conflicted merge in the unmerged paths.
77
78       --conflict=<style>
79           The same as --merge option above, but changes the way the
80           conflicting hunks are presented, overriding the merge.conflictStyle
81           configuration variable. Possible values are "merge" (default),
82           "diff3", and "zdiff3".
83
84       --ignore-unmerged
85           When restoring files on the working tree from the index, do not
86           abort the operation if there are unmerged entries and neither
87           --ours, --theirs, --merge or --conflict is specified. Unmerged
88           paths on the working tree are left alone.
89
90       --ignore-skip-worktree-bits
91           In sparse checkout mode, by default is to only update entries
92           matched by <pathspec> and sparse patterns in
93           $GIT_DIR/info/sparse-checkout. This option ignores the sparse
94           patterns and unconditionally restores any files in <pathspec>.
95
96       --recurse-submodules, --no-recurse-submodules
97           If <pathspec> names an active submodule and the restore location
98           includes the working tree, the submodule will only be updated if
99           this option is given, in which case its working tree will be
100           restored to the commit recorded in the superproject, and any local
101           modifications overwritten. If nothing (or --no-recurse-submodules)
102           is used, submodules working trees will not be updated. Just like
103           git-checkout(1), this will detach HEAD of the submodule.
104
105       --overlay, --no-overlay
106           In overlay mode, the command never removes files when restoring. In
107           no-overlay mode, tracked files that do not appear in the --source
108           tree are removed, to make them match <tree> exactly. The default is
109           no-overlay mode.
110
111       --pathspec-from-file=<file>
112           Pathspec is passed in <file> instead of commandline args. If <file>
113           is exactly - then standard input is used. Pathspec elements are
114           separated by LF or CR/LF. Pathspec elements can be quoted as
115           explained for the configuration variable core.quotePath (see git-
116           config(1)). See also --pathspec-file-nul and global
117           --literal-pathspecs.
118
119       --pathspec-file-nul
120           Only meaningful with --pathspec-from-file. Pathspec elements are
121           separated with NUL character and all other characters are taken
122           literally (including newlines and quotes).
123
124       --
125           Do not interpret any more arguments as options.
126
127       <pathspec>...
128           Limits the paths affected by the operation.
129
130           For more details, see the pathspec entry in gitglossary(7).
131

EXAMPLES

133       The following sequence switches to the master branch, reverts the
134       Makefile to two revisions back, deletes hello.c by mistake, and gets it
135       back from the index.
136
137           $ git switch master
138           $ git restore --source master~2 Makefile  (1)
139           $ rm -f hello.c
140           $ git restore hello.c                     (2)
141
142
143        1. take a file out of another commit
144        2. restore hello.c from the index
145
146       If you want to restore all C source files to match the version in the
147       index, you can say
148
149           $ git restore '*.c'
150
151       Note the quotes around *.c. The file hello.c will also be restored,
152       even though it is no longer in the working tree, because the file
153       globbing is used to match entries in the index (not in the working tree
154       by the shell).
155
156       To restore all files in the current directory
157
158           $ git restore .
159
160       or to restore all working tree files with top pathspec magic (see
161       gitglossary(7))
162
163           $ git restore :/
164
165       To restore a file in the index to match the version in HEAD (this is
166       the same as using git-reset(1))
167
168           $ git restore --staged hello.c
169
170       or you can restore both the index and the working tree (this the same
171       as using git-checkout(1))
172
173           $ git restore --source=HEAD --staged --worktree hello.c
174
175       or the short form which is more practical but less readable:
176
177           $ git restore -s@ -SW hello.c
178

SEE ALSO

180       git-checkout(1), git-reset(1)
181

GIT

183       Part of the git(1) suite
184
185
186
187Git 2.39.1                        2023-01-13                    GIT-RESTORE(1)
Impressum