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, the restore sources for working tree and the index are the
23       index and HEAD respectively. --source could be used to specify a commit
24       as the restore source.
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 default restore source for the working tree
38           is the index, and the default restore source for the index is HEAD.
39           When both --staged and --worktree are specified, --source must also
40           be specified.
41
42       -p, --patch
43           Interactively select hunks in the difference between the restore
44           source and the restore location. See the “Interactive Mode” section
45           of git-add(1) to learn how to operate the --patch mode.
46
47           Note that --patch can accept no pathspec and will prompt to restore
48           all modified paths.
49
50       -W, --worktree, -S, --staged
51           Specify the restore location. If neither option is specified, by
52           default the working tree is restored. Specifying --staged will only
53           restore the index. Specifying both restores both.
54
55       -q, --quiet
56           Quiet, suppress feedback messages. Implies --no-progress.
57
58       --progress, --no-progress
59           Progress status is reported on the standard error stream by default
60           when it is attached to a terminal, unless --quiet is specified.
61           This flag enables progress reporting even if not attached to a
62           terminal, regardless of --quiet.
63
64       --ours, --theirs
65           When restoring files in the working tree from the index, use stage
66           #2 (ours) or #3 (theirs) for unmerged paths.
67
68           Note that during git rebase and git pull --rebase, ours and theirs
69           may appear swapped. See the explanation of the same options in git-
70           checkout(1) for details.
71
72       -m, --merge
73           When restoring files on the working tree from the index, recreate
74           the conflicted merge in the unmerged paths.
75
76       --conflict=<style>
77           The same as --merge option above, but changes the way the
78           conflicting hunks are presented, overriding the merge.conflictStyle
79           configuration variable. Possible values are "merge" (default) and
80           "diff3" (in addition to what is shown by "merge" style, shows the
81           original contents).
82
83       --ignore-unmerged
84           When restoring files on the working tree from the index, do not
85           abort the operation if there are unmerged entries and neither
86           --ours, --theirs, --merge or --conflict is specified. Unmerged
87           paths on the working tree are left alone.
88
89       --ignore-skip-worktree-bits
90           In sparse checkout mode, by default is to only update entries
91           matched by <pathspec> and sparse patterns in
92           $GIT_DIR/info/sparse-checkout. This option ignores the sparse
93           patterns and unconditionally restores any files in <pathspec>.
94
95       --overlay, --no-overlay
96           In overlay mode, the command never removes files when restoring. In
97           no-overlay mode, tracked files that do not appear in the --source
98           tree are removed, to make them match <tree> exactly. The default is
99           no-overlay mode.
100
101       --pathspec-from-file=<file>
102           Pathspec is passed in <file> instead of commandline args. If <file>
103           is exactly - then standard input is used. Pathspec elements are
104           separated by LF or CR/LF. Pathspec elements can be quoted as
105           explained for the configuration variable core.quotePath (see git-
106           config(1)). See also --pathspec-file-nul and global
107           --literal-pathspecs.
108
109       --pathspec-file-nul
110           Only meaningful with --pathspec-from-file. Pathspec elements are
111           separated with NUL character and all other characters are taken
112           literally (including newlines and quotes).
113
114       --
115           Do not interpret any more arguments as options.
116
117       <pathspec>...
118           Limits the paths affected by the operation.
119
120           For more details, see the pathspec entry in gitglossary(7).
121

EXAMPLES

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

SEE ALSO

170       git-checkout(1), git-reset(1)
171

GIT

173       Part of the git(1) suite
174
175
176
177Git 2.26.2                        2020-04-20                    GIT-RESTORE(1)
Impressum