Git fork
1git-restore(1)
2==============
3
4NAME
5----
6git-restore - Restore working tree files
7
8SYNOPSIS
9--------
10[synopsis]
11git restore [<options>] [--source=<tree>] [--staged] [--worktree] [--] <pathspec>...
12git restore [<options>] [--source=<tree>] [--staged] [--worktree] --pathspec-from-file=<file> [--pathspec-file-nul]
13git restore (-p|--patch) [<options>] [--source=<tree>] [--staged] [--worktree] [--] [<pathspec>...]
14
15DESCRIPTION
16-----------
17Restore specified paths in the working tree with some contents from a
18restore source. If a path is tracked but does not exist in the restore
19source, it will be removed to match the source.
20
21The command can also be used to restore the content in the index with
22`--staged`, or restore both the working tree and the index with
23`--staged --worktree`.
24
25By default, if `--staged` is given, the contents are restored from `HEAD`,
26otherwise from the index. Use `--source` to restore from a different commit.
27
28See "Reset, restore and revert" in linkgit:git[1] for the differences
29between the three commands.
30
31OPTIONS
32-------
33`-s <tree>`::
34`--source=<tree>`::
35 Restore the working tree files with the content from the given
36 tree. It is common to specify the source tree by naming a
37 commit, branch or tag associated with it.
38+
39If not specified, the contents are restored from `HEAD` if `--staged` is
40given, otherwise from the index.
41+
42As a special case, you may use `"<rev-A>...<rev-B>"` as a shortcut for the
43merge base of _<rev-A>_ and _<rev-B>_ if there is exactly one merge base. You can
44leave out at most one of _<rev-A>__ and _<rev-B>_, in which case it defaults to `HEAD`.
45
46`-p`::
47`--patch`::
48 Interactively select hunks in the difference between the
49 restore source and the restore location. See the "Interactive
50 Mode" section of linkgit:git-add[1] to learn how to operate
51 the `--patch` mode.
52
53include::diff-context-options.adoc[]
54
55`-W`::
56`--worktree`::
57`-S`::
58`--staged`::
59 Specify the restore location. If neither option is specified,
60 by default the working tree is restored. Specifying `--staged`
61 will only restore the index. Specifying both restores both.
62
63`-q`::
64`--quiet`::
65 Quiet, suppress feedback messages. Implies `--no-progress`.
66
67`--progress`::
68`--no-progress`::
69 Progress status is reported on the standard error stream
70 by default when it is attached to a terminal, unless `--quiet`
71 is specified. This flag enables progress reporting even if not
72 attached to a terminal, regardless of `--quiet`.
73
74`--ours`::
75`--theirs`::
76 When restoring files in the working tree from the index, use
77 stage #2 (`ours`) or #3 (`theirs`) for unmerged paths.
78 This option cannot be used when checking out paths from a
79 tree-ish (i.e. with the `--source` option).
80+
81Note that during `git rebase` and `git pull --rebase`, `ours` and
82`theirs` may appear swapped. See the explanation of the same options
83in linkgit:git-checkout[1] for details.
84
85`-m`::
86`--merge`::
87 When restoring files on the working tree from the index,
88 recreate the conflicted merge in the unmerged paths.
89 This option cannot be used when checking out paths from a
90 tree-ish (i.e. with the `--source` option).
91
92`--conflict=<style>`::
93 The same as `--merge` option above, but changes the way the
94 conflicting hunks are presented, overriding the
95 `merge.conflictStyle` configuration variable. Possible values
96 are `merge` (default), `diff3`, and `zdiff3`.
97
98`--ignore-unmerged`::
99 When restoring files on the working tree from the index, do
100 not abort the operation if there are unmerged entries and
101 neither `--ours`, `--theirs`, `--merge` or `--conflict` is
102 specified. Unmerged paths on the working tree are left alone.
103
104`--ignore-skip-worktree-bits`::
105 In sparse checkout mode, the default is to only update entries
106 matched by _<pathspec>_ and sparse patterns in
107 `$GIT_DIR/info/sparse-checkout`. This option ignores the sparse
108 patterns and unconditionally restores any files in
109 _<pathspec>_.
110
111`--recurse-submodules`::
112`--no-recurse-submodules`::
113 If _<pathspec>_ names an active submodule and the restore location
114 includes the working tree, the submodule will only be updated if
115 this option is given, in which case its working tree will be
116 restored to the commit recorded in the superproject, and any local
117 modifications overwritten. If nothing (or
118 `--no-recurse-submodules`) is used, submodules working trees will
119 not be updated. Just like linkgit:git-checkout[1], this will detach
120 `HEAD` of the submodule.
121
122`--overlay`::
123`--no-overlay`::
124 In overlay mode, never remove files when restoring. In no-overlay mode,
125 remove tracked files that do not appear in the _<tree>_ of
126 `--source=<tree>`, to make them match _<tree>_ exactly. The default
127 is no-overlay mode.
128
129`--pathspec-from-file=<file>`::
130 Pathspec is passed in _<file>_ instead of commandline args. If
131 _<file>_ is exactly `-` then standard input is used. Pathspec
132 elements are separated by _LF_ or _CR_/_LF_. Pathspec elements can be
133 quoted as explained for the configuration variable `core.quotePath`
134 (see linkgit:git-config[1]). See also `--pathspec-file-nul` and
135 global `--literal-pathspecs`.
136
137`--pathspec-file-nul`::
138 Only meaningful with `--pathspec-from-file`. Pathspec elements are
139 separated with _NUL_ character and all other characters are taken
140 literally (including newlines and quotes).
141
142`--`::
143 Do not interpret any more arguments as options.
144
145`<pathspec>...`::
146 Limits the paths affected by the operation.
147+
148For more details, see the 'pathspec' entry in linkgit:gitglossary[7].
149
150EXAMPLES
151--------
152
153The following sequence switches to the `master` branch, reverts the
154`Makefile` to two revisions back, deletes `hello.c` by mistake, and gets
155it back from the index.
156
157------------
158$ git switch master
159$ git restore --source master~2 Makefile <1>
160$ rm -f hello.c
161$ git restore hello.c <2>
162------------
163
164<1> take a file out of another commit
165<2> restore `hello.c` from the index
166
167If you want to restore _all_ C source files to match the version in
168the index, you can say
169
170------------
171$ git restore '*.c'
172------------
173
174Note the quotes around `*.c`. The file `hello.c` will also be
175restored, even though it is no longer in the working tree, because the
176file globbing is used to match entries in the index (not in the
177working tree by the shell).
178
179To restore all files in the current directory
180
181------------
182$ git restore .
183------------
184
185or to restore all working tree files with 'top' pathspec magic (see
186linkgit:gitglossary[7])
187
188------------
189$ git restore :/
190------------
191
192To restore a file in the index to match the version in `HEAD` (this is
193the same as using linkgit:git-reset[1])
194
195------------
196$ git restore --staged hello.c
197------------
198
199or you can restore both the index and the working tree (this is the same
200as using linkgit:git-checkout[1])
201
202------------
203$ git restore --source=HEAD --staged --worktree hello.c
204------------
205
206or the short form which is more practical but less readable:
207
208------------
209$ git restore -s@ -SW hello.c
210------------
211
212SEE ALSO
213--------
214linkgit:git-checkout[1],
215linkgit:git-reset[1]
216
217GIT
218---
219Part of the linkgit:git[1] suite