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) and
82           "diff3" (in addition to what is shown by "merge" style, shows the
83           original contents).
84
85       --ignore-unmerged
86           When restoring files on the working tree from the index, do not
87           abort the operation if there are unmerged entries and neither
88           --ours, --theirs, --merge or --conflict is specified. Unmerged
89           paths on the working tree are left alone.
90
91       --ignore-skip-worktree-bits
92           In sparse checkout mode, by default is to only update entries
93           matched by <pathspec> and sparse patterns in
94           $GIT_DIR/info/sparse-checkout. This option ignores the sparse
95           patterns and unconditionally restores any files in <pathspec>.
96
97       --recurse-submodules, --no-recurse-submodules
98           If <pathspec> names an active submodule and the restore location
99           includes the working tree, the submodule will only be updated if
100           this option is given, in which case its working tree will be
101           restored to the commit recorded in the superproject, and any local
102           modifications overwritten. If nothing (or --no-recurse-submodules)
103           is used, submodules working trees will not be updated. Just like
104           git-checkout(1), this will detach HEAD of the submodule.
105
106       --overlay, --no-overlay
107           In overlay mode, the command never removes files when restoring. In
108           no-overlay mode, tracked files that do not appear in the --source
109           tree are removed, to make them match <tree> exactly. The default is
110           no-overlay mode.
111
112       --pathspec-from-file=<file>
113           Pathspec is passed in <file> instead of commandline args. If <file>
114           is exactly - then standard input is used. Pathspec elements are
115           separated by LF or CR/LF. Pathspec elements can be quoted as
116           explained for the configuration variable core.quotePath (see git-
117           config(1)). See also --pathspec-file-nul and global
118           --literal-pathspecs.
119
120       --pathspec-file-nul
121           Only meaningful with --pathspec-from-file. Pathspec elements are
122           separated with NUL character and all other characters are taken
123           literally (including newlines and quotes).
124
125       --
126           Do not interpret any more arguments as options.
127
128       <pathspec>...
129           Limits the paths affected by the operation.
130
131           For more details, see the pathspec entry in gitglossary(7).
132

EXAMPLES

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

SEE ALSO

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

GIT

184       Part of the git(1) suite
185
186
187
188Git 2.30.2                        2021-03-08                    GIT-RESTORE(1)
Impressum